| 1 | const std = @import("../std.zig"); |
| 2 | |
| 3 | const SIG = std.c.SIG; |
| 4 | const caddr_t = std.c.caddr_t; |
| 5 | const gid_t = std.c.gid_t; |
| 6 | const iovec = std.c.iovec; |
| 7 | const pid_t = std.c.pid_t; |
| 8 | const socklen_t = std.c.socklen_t; |
| 9 | const uid_t = std.c.uid_t; |
| 10 | |
| 11 | pub extern "c" fn lwp_gettid() c_int; |
| 12 | pub extern "c" fn ptrace(request: c_int, pid: pid_t, addr: caddr_t, data: c_int) c_int; |
| 13 | pub extern "c" fn umtx_sleep(ptr: *const volatile c_int, value: c_int, timeout: c_int) c_int; |
| 14 | pub extern "c" fn umtx_wakeup(ptr: *const volatile c_int, count: c_int) c_int; |
| 15 | |
| 16 | pub const E = enum(u16) { |
| 17 | /// No error occurred. |
| 18 | SUCCESS = 0, |
| 19 | |
| 20 | PERM = 1, |
| 21 | NOENT = 2, |
| 22 | SRCH = 3, |
| 23 | INTR = 4, |
| 24 | IO = 5, |
| 25 | NXIO = 6, |
| 26 | @"2BIG" = 7, |
| 27 | NOEXEC = 8, |
| 28 | BADF = 9, |
| 29 | CHILD = 10, |
| 30 | DEADLK = 11, |
| 31 | NOMEM = 12, |
| 32 | ACCES = 13, |
| 33 | FAULT = 14, |
| 34 | NOTBLK = 15, |
| 35 | BUSY = 16, |
| 36 | EXIST = 17, |
| 37 | XDEV = 18, |
| 38 | NODEV = 19, |
| 39 | NOTDIR = 20, |
| 40 | ISDIR = 21, |
| 41 | INVAL = 22, |
| 42 | NFILE = 23, |
| 43 | MFILE = 24, |
| 44 | NOTTY = 25, |
| 45 | TXTBSY = 26, |
| 46 | FBIG = 27, |
| 47 | NOSPC = 28, |
| 48 | SPIPE = 29, |
| 49 | ROFS = 30, |
| 50 | MLINK = 31, |
| 51 | PIPE = 32, |
| 52 | DOM = 33, |
| 53 | RANGE = 34, |
| 54 | /// This code is also used for `WOULDBLOCK`. |
| 55 | AGAIN = 35, |
| 56 | INPROGRESS = 36, |
| 57 | ALREADY = 37, |
| 58 | NOTSOCK = 38, |
| 59 | DESTADDRREQ = 39, |
| 60 | MSGSIZE = 40, |
| 61 | PROTOTYPE = 41, |
| 62 | NOPROTOOPT = 42, |
| 63 | PROTONOSUPPORT = 43, |
| 64 | SOCKTNOSUPPORT = 44, |
| 65 | /// This code is also used for `NOTSUP`. |
| 66 | OPNOTSUPP = 45, |
| 67 | PFNOSUPPORT = 46, |
| 68 | AFNOSUPPORT = 47, |
| 69 | ADDRINUSE = 48, |
| 70 | ADDRNOTAVAIL = 49, |
| 71 | NETDOWN = 50, |
| 72 | NETUNREACH = 51, |
| 73 | NETRESET = 52, |
| 74 | CONNABORTED = 53, |
| 75 | CONNRESET = 54, |
| 76 | NOBUFS = 55, |
| 77 | ISCONN = 56, |
| 78 | NOTCONN = 57, |
| 79 | SHUTDOWN = 58, |
| 80 | TOOMANYREFS = 59, |
| 81 | TIMEDOUT = 60, |
| 82 | CONNREFUSED = 61, |
| 83 | LOOP = 62, |
| 84 | NAMETOOLONG = 63, |
| 85 | HOSTDOWN = 64, |
| 86 | HOSTUNREACH = 65, |
| 87 | NOTEMPTY = 66, |
| 88 | PROCLIM = 67, |
| 89 | USERS = 68, |
| 90 | DQUOT = 69, |
| 91 | STALE = 70, |
| 92 | REMOTE = 71, |
| 93 | BADRPC = 72, |
| 94 | RPCMISMATCH = 73, |
| 95 | PROGUNAVAIL = 74, |
| 96 | PROGMISMATCH = 75, |
| 97 | PROCUNAVAIL = 76, |
| 98 | NOLCK = 77, |
| 99 | NOSYS = 78, |
| 100 | FTYPE = 79, |
| 101 | AUTH = 80, |
| 102 | NEEDAUTH = 81, |
| 103 | IDRM = 82, |
| 104 | NOMSG = 83, |
| 105 | OVERFLOW = 84, |
| 106 | CANCELED = 85, |
| 107 | ILSEQ = 86, |
| 108 | NOATTR = 87, |
| 109 | DOOFUS = 88, |
| 110 | BADMSG = 89, |
| 111 | MULTIHOP = 90, |
| 112 | NOLINK = 91, |
| 113 | PROTO = 92, |
| 114 | NOMEDIUM = 93, |
| 115 | ASYNC = 99, |
| 116 | _, |
| 117 | }; |
| 118 | |
| 119 | pub const BADSIG = SIG.ERR; |
| 120 | |
| 121 | pub const sig_t = *const fn (i32) callconv(.c) void; |
| 122 | |
| 123 | pub const cmsgcred = extern struct { |
| 124 | pid: pid_t, |
| 125 | uid: uid_t, |
| 126 | euid: uid_t, |
| 127 | gid: gid_t, |
| 128 | ngroups: c_short, |
| 129 | groups: [16]gid_t, |
| 130 | }; |
| 131 | pub const sf_hdtr = extern struct { |
| 132 | headers: [*]iovec, |
| 133 | hdr_cnt: c_int, |
| 134 | trailers: [*]iovec, |
| 135 | trl_cnt: c_int, |
| 136 | }; |
| 137 | |
| 138 | pub const MS_SYNC = 0; |
| 139 | pub const MS_ASYNC = 1; |
| 140 | pub const MS_INVALIDATE = 2; |
| 141 | |
| 142 | pub const POSIX_MADV_SEQUENTIAL = 2; |
| 143 | pub const POSIX_MADV_RANDOM = 1; |
| 144 | pub const POSIX_MADV_DONTNEED = 4; |
| 145 | pub const POSIX_MADV_NORMAL = 0; |
| 146 | pub const POSIX_MADV_WILLNEED = 3; |
| 147 | |
| 148 | // https://github.com/DragonFlyBSD/DragonFlyBSD/blob/6098912863ed4c7b3f70d7483910ce2956cf4ed3/sys/netinet/ip.h#L94 |
| 149 | pub const IP = struct { |
| 150 | pub const OPTIONS = 1; |
| 151 | pub const HDRINCL = 2; |
| 152 | pub const TOS = 3; |
| 153 | pub const TTL = 4; |
| 154 | pub const RECVOPTS = 5; |
| 155 | pub const RECVRETOPTS = 6; |
| 156 | pub const RECVDSTADDR = 7; |
| 157 | pub const SENDSRCADDR = RECVDSTADDR; |
| 158 | pub const RETOPTS = 8; |
| 159 | pub const MULTICAST_IF = 9; |
| 160 | pub const MULTICAST_TTL = 10; |
| 161 | pub const MULTICAST_LOOP = 11; |
| 162 | pub const ADD_MEMBERSHIP = 12; |
| 163 | pub const DROP_MEMBERSHIP = 13; |
| 164 | pub const MULTICAST_VIF = 14; |
| 165 | pub const RSVP_ON = 15; |
| 166 | pub const RSVP_OFF = 16; |
| 167 | pub const RSVP_VIF_ON = 17; |
| 168 | pub const RSVP_VIF_OFF = 18; |
| 169 | pub const PORTRANGE = 19; |
| 170 | pub const RECVIF = 20; |
| 171 | pub const FW_TBL_CREATE = 40; |
| 172 | pub const FW_TBL_DESTROY = 41; |
| 173 | pub const FW_TBL_ADD = 42; |
| 174 | pub const FW_TBL_DEL = 43; |
| 175 | pub const FW_TBL_FLUSH = 44; |
| 176 | pub const FW_TBL_GET = 45; |
| 177 | pub const FW_TBL_ZERO = 46; |
| 178 | pub const FW_TBL_EXPIRE = 47; |
| 179 | pub const FW_X = 49; |
| 180 | pub const FW_ADD = 50; |
| 181 | pub const FW_DEL = 51; |
| 182 | pub const FW_FLUSH = 52; |
| 183 | pub const FW_ZERO = 53; |
| 184 | pub const FW_GET = 54; |
| 185 | pub const FW_RESETLOG = 55; |
| 186 | pub const DUMMYNET_CONFIGURE = 60; |
| 187 | pub const DUMMYNET_DEL = 61; |
| 188 | pub const DUMMYNET_FLUSH = 62; |
| 189 | pub const DUMMYNET_GET = 64; |
| 190 | pub const RECVTTL = 65; |
| 191 | pub const MINTTL = 66; |
| 192 | pub const RECVTOS = 68; |
| 193 | // Same namespace, but these are arguments rather than option names |
| 194 | pub const DEFAULT_MULTICAST_TTL = 1; |
| 195 | pub const DEFAULT_MULTICAST_LOOP = 1; |
| 196 | pub const MAX_MEMBERSHIPS = 20; |
| 197 | pub const PORTRANGE_DEFAULT = 0; |
| 198 | pub const PORTRANGE_HIGH = 1; |
| 199 | pub const PORTRANGE_LOW = 2; |
| 200 | }; |
| 201 | |
| 202 | // https://github.com/DragonFlyBSD/DragonFlyBSD/blob/6098912863ed4c7b3f70d7483910ce2956cf4ed3/sys/netinet6/in6.h#L448 |
| 203 | pub const IPV6 = struct { |
| 204 | pub const UNICAST_HOPS = 4; |
| 205 | pub const MULTICAST_IF = 9; |
| 206 | pub const MULTICAST_HOPS = 10; |
| 207 | pub const MULTICAST_LOOP = 11; |
| 208 | pub const JOIN_GROUP = 12; |
| 209 | pub const LEAVE_GROUP = 13; |
| 210 | pub const PORTRANGE = 14; |
| 211 | pub const @"2292PKTINFO" = 19; |
| 212 | pub const @"2292HOPLIMIT" = 20; |
| 213 | pub const @"2292NEXTHOP" = 21; |
| 214 | pub const @"2292HOPOPTS" = 22; |
| 215 | pub const @"2292DSTOPTS" = 23; |
| 216 | pub const @"2292RTHDR" = 24; |
| 217 | pub const @"2292PKTOPTIONS" = 25; |
| 218 | pub const CHECKSUM = 26; |
| 219 | pub const V6ONLY = 27; |
| 220 | pub const BINDV6ONLY = V6ONLY; |
| 221 | pub const FW_ADD = 30; |
| 222 | pub const FW_DEL = 31; |
| 223 | pub const FW_FLUSH = 32; |
| 224 | pub const FW_ZERO = 33; |
| 225 | pub const FW_GET = 34; |
| 226 | pub const RTHDRDSTOPTS = 35; |
| 227 | pub const RECVPKTINFO = 36; |
| 228 | pub const RECVHOPLIMIT = 37; |
| 229 | pub const RECVRTHDR = 38; |
| 230 | pub const RECVHOPOPTS = 39; |
| 231 | pub const RECVDSTOPTS = 40; |
| 232 | pub const RECVRTHDRDSTOPTS = 41; |
| 233 | pub const USE_MIN_MTU = 42; |
| 234 | pub const RECVPATHMTU = 43; |
| 235 | pub const PATHMTU = 44; |
| 236 | pub const REACHCONF = 45; |
| 237 | pub const PKTINFO = 46; |
| 238 | pub const HOPLIMIT = 47; |
| 239 | pub const NEXTHOP = 48; |
| 240 | pub const HOPOPTS = 49; |
| 241 | pub const DSTOPTS = 50; |
| 242 | pub const RTHDR = 51; |
| 243 | pub const PKTOPTIONS = 52; |
| 244 | pub const RECVTCLASS = 57; |
| 245 | pub const AUTOFLOWLABEL = 59; |
| 246 | pub const TCLASS = 61; |
| 247 | pub const DONTFRAG = 62; |
| 248 | pub const PREFER_TEMPADDR = 63; |
| 249 | pub const MSFILTER = 74; |
| 250 | // Same namespace, but these are arguments rather than option names |
| 251 | pub const RTHDR_LOOSE = 0; |
| 252 | pub const RTHDR_STRICT = 1; |
| 253 | pub const RTHDR_TYPE_0 = 0; |
| 254 | pub const DEFAULT_MULTICAST_HOPS = 1; |
| 255 | pub const DEFAULT_MULTICAST_LOOP = 1; |
| 256 | pub const PORTRANGE_DEFAULT = 0; |
| 257 | pub const PORTRANGE_HIGH = 1; |
| 258 | pub const PORTRANGE_LOW = 2; |
| 259 | }; |
| 260 | |
| 261 | // https://github.com/DragonFlyBSD/DragonFlyBSD/blob/6098912863ed4c7b3f70d7483910ce2956cf4ed3/sys/netinet/ip.h#L94 |
| 262 | pub const IPTOS = struct { |
| 263 | pub const LOWDELAY = 0x10; |
| 264 | pub const THROUGHPUT = 0x08; |
| 265 | pub const RELIABILITY = 0x04; |
| 266 | pub const MINCOST = 0x02; |
| 267 | pub const CE = 0x01; |
| 268 | pub const ECT = 0x02; |
| 269 | pub const PREC_ROUTINE = DSCP_CS0; |
| 270 | pub const PREC_PRIORITY = DSCP_CS1; |
| 271 | pub const PREC_IMMEDIATE = DSCP_CS2; |
| 272 | pub const PREC_FLASH = DSCP_CS3; |
| 273 | pub const PREC_FLASHOVERRIDE = DSCP_CS4; |
| 274 | pub const PREC_CRITIC_ECP = DSCP_CS5; |
| 275 | pub const PREC_INTERNETCONTROL = DSCP_CS6; |
| 276 | pub const PREC_NETCONTROL = DSCP_CS7; |
| 277 | pub const DSCP_CS0 = 0x00; |
| 278 | pub const DSCP_CS1 = 0x20; |
| 279 | pub const DSCP_AF11 = 0x28; |
| 280 | pub const DSCP_AF12 = 0x30; |
| 281 | pub const DSCP_AF13 = 0x38; |
| 282 | pub const DSCP_CS2 = 0x40; |
| 283 | pub const DSCP_AF21 = 0x48; |
| 284 | pub const DSCP_AF22 = 0x50; |
| 285 | pub const DSCP_AF23 = 0x58; |
| 286 | pub const DSCP_CS3 = 0x60; |
| 287 | pub const DSCP_AF31 = 0x68; |
| 288 | pub const DSCP_AF32 = 0x70; |
| 289 | pub const DSCP_AF33 = 0x78; |
| 290 | pub const DSCP_CS4 = 0x80; |
| 291 | pub const DSCP_AF41 = 0x88; |
| 292 | pub const DSCP_AF42 = 0x90; |
| 293 | pub const DSCP_AF43 = 0x98; |
| 294 | pub const DSCP_CS5 = 0xa0; |
| 295 | pub const DSCP_VA = 0xb0; |
| 296 | pub const DSCP_EF = 0xb8; |
| 297 | pub const DSCP_CS6 = 0xc0; |
| 298 | pub const DSCP_CS7 = 0xe0; |
| 299 | pub const ECN_NOTECT = 0x00; |
| 300 | pub const ECN_ECT1 = 0x01; |
| 301 | pub const ECN_ECT0 = 0x02; |
| 302 | pub const ECN_CE = 0x03; |
| 303 | pub const ECN_MASK = 0x03; |
| 304 | }; |
| 305 | |
| 306 | // https://github.com/DragonFlyBSD/DragonFlyBSD/blob/8410ea0817ce17438e0a10fc4ba6c9697281048a/sys/netinet/tcp.h#L156 |
| 307 | pub const TCP = struct { |
| 308 | pub const NODELAY = 0x01; |
| 309 | pub const MAXSEG = 0x02; |
| 310 | pub const NOPUSH = 0x04; |
| 311 | pub const NOOPT = 0x08; |
| 312 | pub const SIGNATURE_ENABLE = 0x10; |
| 313 | pub const KEEPINIT = 0x20; |
| 314 | pub const FASTKEEP = 0x80; |
| 315 | pub const KEEPIDLE = 0x100; |
| 316 | pub const KEEPINTVL = 0x200; |
| 317 | pub const KEEPCNT = 0x400; |
| 318 | }; |