| ... | @@ -25,6 +25,65 @@ pub const dl_phdr_info = extern struct { | ... | @@ -25,6 +25,65 @@ pub const dl_phdr_info = extern struct { |
| 25 | dlpi_phnum: u16, | 25 | dlpi_phnum: u16, |
| 26 | }; | 26 | }; |
| 27 | | 27 | |
| | 28 | pub const addrinfo = extern struct { |
| | 29 | flags: i32, |
| | 30 | family: i32, |
| | 31 | socktype: i32, |
| | 32 | protocol: i32, |
| | 33 | addrlen: socklen_t, |
| | 34 | canonname: ?[*:0]u8, |
| | 35 | addr: ?*sockaddr, |
| | 36 | next: ?*addrinfo, |
| | 37 | }; |
| | 38 | |
| | 39 | pub const EAI = extern enum(c_int) { |
| | 40 | /// address family for hostname not supported |
| | 41 | ADDRFAMILY = 1, |
| | 42 | |
| | 43 | /// name could not be resolved at this time |
| | 44 | AGAIN = 2, |
| | 45 | |
| | 46 | /// flags parameter had an invalid value |
| | 47 | BADFLAGS = 3, |
| | 48 | |
| | 49 | /// non-recoverable failure in name resolution |
| | 50 | FAIL = 4, |
| | 51 | |
| | 52 | /// address family not recognized |
| | 53 | FAMILY = 5, |
| | 54 | |
| | 55 | /// memory allocation failure |
| | 56 | MEMORY = 6, |
| | 57 | |
| | 58 | /// no address associated with hostname |
| | 59 | NODATA = 7, |
| | 60 | |
| | 61 | /// name does not resolve |
| | 62 | NONAME = 8, |
| | 63 | |
| | 64 | /// service not recognized for socket type |
| | 65 | SERVICE = 9, |
| | 66 | |
| | 67 | /// intended socket type was not recognized |
| | 68 | SOCKTYPE = 10, |
| | 69 | |
| | 70 | /// system error returned in errno |
| | 71 | SYSTEM = 11, |
| | 72 | |
| | 73 | /// invalid value for hints |
| | 74 | BADHINTS = 12, |
| | 75 | |
| | 76 | /// resolved protocol is unknown |
| | 77 | PROTOCOL = 13, |
| | 78 | |
| | 79 | /// argument buffer overflow |
| | 80 | OVERFLOW = 14, |
| | 81 | |
| | 82 | _, |
| | 83 | }; |
| | 84 | |
| | 85 | pub const EAI_MAX = 15; |
| | 86 | |
| 28 | pub const msghdr = extern struct { | 87 | pub const msghdr = extern struct { |
| 29 | /// optional address | 88 | /// optional address |
| 30 | msg_name: ?*sockaddr, | 89 | msg_name: ?*sockaddr, |
| ... | @@ -122,7 +181,6 @@ pub const dirent = extern struct { | ... | @@ -122,7 +181,6 @@ pub const dirent = extern struct { |
| 122 | d_reclen: u16, | 181 | d_reclen: u16, |
| 123 | d_namlen: u16, | 182 | d_namlen: u16, |
| 124 | d_type: u8, | 183 | d_type: u8, |
| 125 | d_off: i64, | | |
| 126 | d_name: [512]u8, | 184 | d_name: [512]u8, |
| 127 | | 185 | |
| 128 | pub fn reclen(self: dirent) u16 { | 186 | pub fn reclen(self: dirent) u16 { |
| ... | @@ -146,7 +204,7 @@ pub const sockaddr = extern struct { | ... | @@ -146,7 +204,7 @@ pub const sockaddr = extern struct { |
| 146 | | 204 | |
| 147 | pub const sockaddr_in = extern struct { | 205 | pub const sockaddr_in = extern struct { |
| 148 | len: u8 = @sizeOf(sockaddr_in), | 206 | len: u8 = @sizeOf(sockaddr_in), |
| 149 | family: sa_family_t, | 207 | family: sa_family_t = AF_INET, |
| 150 | port: in_port_t, | 208 | port: in_port_t, |
| 151 | addr: u32, | 209 | addr: u32, |
| 152 | zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 }, | 210 | zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 }, |
| ... | @@ -154,7 +212,7 @@ pub const sockaddr_in = extern struct { | ... | @@ -154,7 +212,7 @@ pub const sockaddr_in = extern struct { |
| 154 | | 212 | |
| 155 | pub const sockaddr_in6 = extern struct { | 213 | pub const sockaddr_in6 = extern struct { |
| 156 | len: u8 = @sizeOf(sockaddr_in6), | 214 | len: u8 = @sizeOf(sockaddr_in6), |
| 157 | family: sa_family_t, | 215 | family: sa_family_t = AF_INET6, |
| 158 | port: in_port_t, | 216 | port: in_port_t, |
| 159 | flowinfo: u32, | 217 | flowinfo: u32, |
| 160 | addr: [16]u8, | 218 | addr: [16]u8, |
| ... | @@ -167,12 +225,27 @@ pub const sockaddr_un = extern struct { | ... | @@ -167,12 +225,27 @@ pub const sockaddr_un = extern struct { |
| 167 | len: u8 = @sizeOf(sockaddr_un), | 225 | len: u8 = @sizeOf(sockaddr_un), |
| 168 | | 226 | |
| 169 | /// AF_LOCAL | 227 | /// AF_LOCAL |
| 170 | family: sa_family_t, | 228 | family: sa_family_t = AF_LOCAL, |
| 171 | | 229 | |
| 172 | /// path name | 230 | /// path name |
| 173 | path: [104]u8, | 231 | path: [104]u8, |
| 174 | }; | 232 | }; |
| 175 | | 233 | |
| | 234 | /// get address to use bind() |
| | 235 | pub const AI_PASSIVE = 0x00000001; |
| | 236 | |
| | 237 | /// fill ai_canonname |
| | 238 | pub const AI_CANONNAME = 0x00000002; |
| | 239 | |
| | 240 | /// prevent host name resolution |
| | 241 | pub const AI_NUMERICHOST = 0x00000004; |
| | 242 | |
| | 243 | /// prevent service name resolution |
| | 244 | pub const AI_NUMERICSERV = 0x00000008; |
| | 245 | |
| | 246 | /// only if any address is assigned |
| | 247 | pub const AI_ADDRCONFIG = 0x00000400; |
| | 248 | |
| 176 | pub const CTL_KERN = 1; | 249 | pub const CTL_KERN = 1; |
| 177 | pub const CTL_DEBUG = 5; | 250 | pub const CTL_DEBUG = 5; |
| 178 | | 251 | |
| ... | @@ -274,30 +347,71 @@ pub const X_OK = 1; // test for execute or search permission | ... | @@ -274,30 +347,71 @@ pub const X_OK = 1; // test for execute or search permission |
| 274 | pub const W_OK = 2; // test for write permission | 347 | pub const W_OK = 2; // test for write permission |
| 275 | pub const R_OK = 4; // test for read permission | 348 | pub const R_OK = 4; // test for read permission |
| 276 | | 349 | |
| 277 | pub const O_RDONLY = 0x0000; | 350 | /// open for reading only |
| 278 | pub const O_WRONLY = 0x0001; | 351 | pub const O_RDONLY = 0x00000000; |
| 279 | pub const O_RDWR = 0x0002; | 352 | |
| 280 | pub const O_ACCMODE = 0x0003; | 353 | /// open for writing only |
| 281 | | 354 | pub const O_WRONLY = 0x00000001; |
| 282 | pub const O_CREAT = 0x0200; | 355 | |
| 283 | pub const O_EXCL = 0x0800; | 356 | /// open for reading and writing |
| 284 | pub const O_NOCTTY = 0x8000; | 357 | pub const O_RDWR = 0x00000002; |
| 285 | pub const O_TRUNC = 0x0400; | 358 | |
| 286 | pub const O_APPEND = 0x0008; | 359 | /// mask for above modes |
| 287 | pub const O_NONBLOCK = 0x0004; | 360 | pub const O_ACCMODE = 0x00000003; |
| | 361 | |
| | 362 | /// no delay |
| | 363 | pub const O_NONBLOCK = 0x00000004; |
| | 364 | |
| | 365 | /// set append mode |
| | 366 | pub const O_APPEND = 0x00000008; |
| | 367 | |
| | 368 | /// open with shared file lock |
| | 369 | pub const O_SHLOCK = 0x00000010; |
| | 370 | |
| | 371 | /// open with exclusive file lock |
| | 372 | pub const O_EXLOCK = 0x00000020; |
| | 373 | |
| | 374 | /// signal pgrp when data ready |
| | 375 | pub const O_ASYNC = 0x00000040; |
| | 376 | |
| | 377 | /// synchronous writes |
| | 378 | pub const O_SYNC = 0x00000080; |
| | 379 | |
| | 380 | /// don't follow symlinks on the last |
| | 381 | pub const O_NOFOLLOW = 0x00000100; |
| | 382 | |
| | 383 | /// create if nonexistent |
| | 384 | pub const O_CREAT = 0x00000200; |
| | 385 | |
| | 386 | /// truncate to zero length |
| | 387 | pub const O_TRUNC = 0x00000400; |
| | 388 | |
| | 389 | /// error if already exists |
| | 390 | pub const O_EXCL = 0x00000800; |
| | 391 | |
| | 392 | /// don't assign controlling terminal |
| | 393 | pub const O_NOCTTY = 0x00008000; |
| | 394 | |
| | 395 | /// write: I/O data completion |
| 288 | pub const O_DSYNC = 0x00010000; | 396 | pub const O_DSYNC = 0x00010000; |
| 289 | pub const O_SYNC = 0x0080; | 397 | |
| | 398 | /// read: I/O completion as for write |
| 290 | pub const O_RSYNC = 0x00020000; | 399 | pub const O_RSYNC = 0x00020000; |
| 291 | pub const O_DIRECTORY = 0x00080000; | | |
| 292 | pub const O_NOFOLLOW = 0x00000100; | | |
| 293 | pub const O_CLOEXEC = 0x00400000; | | |
| 294 | | 400 | |
| 295 | pub const O_ASYNC = 0x0040; | 401 | /// use alternate i/o semantics |
| | 402 | pub const O_ALT_IO = 0x00040000; |
| | 403 | |
| | 404 | /// direct I/O hint |
| 296 | pub const O_DIRECT = 0x00080000; | 405 | pub const O_DIRECT = 0x00080000; |
| 297 | pub const O_NOATIME = 0; | 406 | |
| 298 | pub const O_PATH = 0; | 407 | /// fail if not a directory |
| 299 | pub const O_TMPFILE = 0; | 408 | pub const O_DIRECTORY = 0x00200000; |
| 300 | pub const O_NDELAY = O_NONBLOCK; | 409 | |
| | 410 | /// set close on exec |
| | 411 | pub const O_CLOEXEC = 0x00400000; |
| | 412 | |
| | 413 | /// skip search permission checks |
| | 414 | pub const O_SEARCH = 0x00800000; |
| 301 | | 415 | |
| 302 | pub const F_DUPFD = 0; | 416 | pub const F_DUPFD = 0; |
| 303 | pub const F_GETFD = 1; | 417 | pub const F_GETFD = 1; |