sys_socket.odin 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. #+build linux, darwin, netbsd, openbsd, freebsd, haiku
  2. package posix
  3. import "core:c"
  4. when ODIN_OS == .Darwin {
  5. foreign import libc "system:System"
  6. } else {
  7. foreign import libc "system:c"
  8. }
  9. // sys/socket.h - main sockets header
  10. #assert(Protocol.IP == Protocol(0), "socket() assumes this")
  11. foreign libc {
  12. /*
  13. Creates a socket.
  14. Returns: -1 (setting errno) on failure, file descriptor of socket otherwise
  15. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html ]]
  16. */
  17. @(link_name=LSOCKET)
  18. socket :: proc(domain: AF, type: Sock, protocol: Protocol = .IP) -> FD ---
  19. /*
  20. Extracts the first connection on the queue of pending connections.
  21. Blocks (if not O_NONBLOCK) if there is no pending connection.
  22. Returns: -1 (setting errno) on failure, file descriptor of accepted socket otherwise
  23. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/accept.html ]]
  24. */
  25. accept :: proc(socket: FD, address: ^sockaddr, address_len: ^socklen_t) -> FD ---
  26. /*
  27. Assigns a local socket address to the socket.
  28. Example:
  29. sfd := posix.socket(.UNIX, .STREAM)
  30. if sfd == -1 {
  31. /* Handle error */
  32. }
  33. addr: posix.sockaddr_un
  34. addr.sun_family = .UNIX
  35. copy(addr.sun_path[:], "/somepath\x00")
  36. /*
  37. unlink the socket before binding in case
  38. of previous runs not cleaning up the socket
  39. */
  40. posix.unlink("/somepath")
  41. if posix.bind(sfd, (^posix.sockaddr)(&addr), size_of(addr)) != .OK {
  42. /* Handle error */
  43. }
  44. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html ]]
  45. */
  46. bind :: proc(socket: FD, address: ^sockaddr, address_len: socklen_t) -> result ---
  47. /*
  48. Attempt to make a connection.
  49. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html ]]
  50. */
  51. connect :: proc(socket: FD, address: ^sockaddr, address_len: socklen_t) -> result ---
  52. /*
  53. Get the peer address of the specified socket.
  54. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpeername.html ]]
  55. */
  56. getpeername :: proc(socket: FD, address: ^sockaddr, address_len: ^socklen_t) -> result ---
  57. /*
  58. Get the socket name.
  59. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html ]]
  60. */
  61. getsockname :: proc(socket: FD, address: ^sockaddr, address_len: ^socklen_t) -> result ---
  62. /*
  63. Retrieves the value for the option specified by option_name.
  64. level: either `c.int(posix.Protocol(...))` to specify a protocol level or `posix.SOL_SOCKET`
  65. to specify the socket local level.
  66. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html ]]
  67. */
  68. getsockopt :: proc(
  69. socket: FD,
  70. level: c.int,
  71. option_name: Sock_Option,
  72. option_value: rawptr,
  73. option_len: ^socklen_t,
  74. ) -> result ---
  75. /*
  76. Sets the specified option.
  77. level: either `c.int(posix.Protocol(...))` to specify a protocol level or `posix.SOL_SOCKET`
  78. to specify the socket local level.
  79. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html ]]
  80. */
  81. setsockopt :: proc(
  82. socket: FD,
  83. level: c.int,
  84. option_name: Sock_Option,
  85. option_value: rawptr,
  86. option_len: socklen_t,
  87. ) -> result ---
  88. /*
  89. Mark the socket as a socket accepting connections.
  90. backlog provides a hint to limit the number of connections on the listen queue.
  91. Implementation may silently reduce the backlog, additionally `SOMAXCONN` specifies the maximum
  92. an implementation has to support.
  93. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html ]]
  94. */
  95. listen :: proc(socket: FD, backlog: c.int) -> result ---
  96. /*
  97. Receives a message from a socket.
  98. Blocks (besides with O_NONBLOCK) if there is nothing to receive.
  99. Returns: 0 when the peer shutdown with no more messages, -1 (setting errno) on failure, the amount of bytes received on success
  100. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/recv.html ]]
  101. */
  102. recv :: proc(socket: FD, buffer: rawptr, length: c.size_t, flags: Msg_Flags) -> c.ssize_t ---
  103. /*
  104. Receives a message from a socket.
  105. Equivalent to recv() but retrieves the source address too.
  106. Returns: 0 when the peer shutdown with no more messages, -1 (setting errno) on failure, the amount of bytes received on success
  107. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvfrom.html ]]
  108. */
  109. recvfrom :: proc(
  110. socket: FD,
  111. buffer: rawptr,
  112. length: c.size_t,
  113. flags: Msg_Flags,
  114. address: ^sockaddr,
  115. address_len: ^socklen_t,
  116. ) -> c.ssize_t ---
  117. /*
  118. Receives a message from a socket.
  119. Returns: 0 when the peer shutdown with no more messages, -1 (setting errno) on failure, the amount of bytes received on success
  120. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvmsg.html ]]
  121. */
  122. recvmsg :: proc(socket: FD, message: ^msghdr, flags: Msg_Flags) -> c.ssize_t ---
  123. /*
  124. Sends a message on a socket.
  125. Returns: -1 (setting errno) on failure, the amount of bytes received on success
  126. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/send.html ]]
  127. */
  128. send :: proc(socket: FD, buffer: rawptr, length: c.size_t, flags: Msg_Flags) -> c.ssize_t ---
  129. /*
  130. Sends a message on a socket.
  131. Returns: -1 (setting errno) on failure, the amount of bytes received on success
  132. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendmsg.html ]]
  133. */
  134. sendmsg :: proc(socket: FD, message: ^msghdr, flags: Msg_Flags) -> c.ssize_t ---
  135. /*
  136. Sends a message on a socket.
  137. If the socket is connectionless, the dest_addr is used to send to.
  138. Returns: -1 (setting errno) on failure, the amount of bytes received on success
  139. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendto.html ]]
  140. */
  141. sendto :: proc(
  142. socket: FD,
  143. message: rawptr,
  144. length: c.size_t,
  145. flags: Msg_Flags,
  146. dest_addr: ^sockaddr,
  147. dest_len: socklen_t,
  148. ) -> c.ssize_t ---
  149. /*
  150. Shuts down a socket end or both.
  151. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/shutdown.html ]]
  152. */
  153. shutdown :: proc(socket: FD, how: Shut) -> result ---
  154. /*
  155. Determine wheter a socket is at the out-of-band mark.
  156. Returns: -1 (setting errno) on failure, 0 if not at the mark, 1 if it is
  157. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/sockatmark.html ]]
  158. */
  159. sockatmark :: proc(socket: FD) -> c.int ---
  160. /*
  161. Create a pair of connected sockets.
  162. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/socketpair.html ]]
  163. */
  164. socketpair :: proc(domain: AF, type: Sock, protocol: Protocol, socket_vector: ^[2]FD) -> result ---
  165. }
  166. AF_UNSPEC :: 0
  167. AF :: enum c.int {
  168. // Unspecified.
  169. UNSPEC = AF_UNSPEC,
  170. // Internet domain sockets for use with IPv4 addresses.
  171. INET = AF_INET,
  172. // Internet domain sockets for use with IPv6 addresses.
  173. INET6 = AF_INET6,
  174. // UNIX domain sockets.
  175. UNIX = AF_UNIX,
  176. }
  177. sa_family_t :: enum _sa_family_t {
  178. // Unspecified.
  179. UNSPEC = AF_UNSPEC,
  180. // Internet domain sockets for use with IPv4 addresses.
  181. INET = AF_INET,
  182. // Internet domain sockets for use with IPv6 addresses.
  183. INET6 = AF_INET6,
  184. // UNIX domain sockets.
  185. UNIX = AF_UNIX,
  186. }
  187. Sock :: enum c.int {
  188. // Datagram socket.
  189. DGRAM = SOCK_DGRAM,
  190. // Raw Protocol Interface.
  191. RAW = SOCK_RAW,
  192. // Sequenced-packet socket.
  193. SEQPACKET = SOCK_SEQPACKET,
  194. // Byte-stream socket.
  195. STREAM = SOCK_STREAM,
  196. }
  197. Shut :: enum c.int {
  198. // Disables further receive operations.
  199. RD = SHUT_RD,
  200. // Disables further send and receive operations.
  201. RDWR = SHUT_RDWR,
  202. // Disables further send operations.
  203. WR = SHUT_WR,
  204. }
  205. Msg_Flag_Bits :: enum c.int {
  206. // Control data truncated.
  207. CTRUNC = log2(MSG_CTRUNC),
  208. // Send without using routing table.
  209. DONTROUTE = log2(MSG_DONTROUTE),
  210. // Terminates a record (if supported by protocol).
  211. EOR = log2(MSG_EOR),
  212. // Out-of-band data.
  213. OOB = log2(MSG_OOB),
  214. // No SIGPIPE is generated when an attempt to send is made on a stream-oriented socket that is
  215. // no longer connected.
  216. NOSIGNAL = log2(MSG_NOSIGNAL),
  217. // Leave received data in queue.
  218. PEEK = log2(MSG_PEEK),
  219. // Normal data truncated.
  220. TRUNC = log2(MSG_TRUNC),
  221. // Attempt to fill the read buffer.
  222. WAITALL = log2(MSG_WAITALL),
  223. }
  224. Msg_Flags :: bit_set[Msg_Flag_Bits; c.int]
  225. Sock_Option :: enum c.int {
  226. // Transmission of broadcast message is supported.
  227. BROADCAST = SO_BROADCAST,
  228. // Debugging information is being recorded.
  229. DEBUG = SO_DEBUG,
  230. // Bypass normal routing.
  231. DONTROUTE = SO_DONTROUTE,
  232. // Socket error status.
  233. ERROR = SO_ERROR,
  234. // Connections are kept alive with periodic messages.
  235. KEEPALIVE = SO_KEEPALIVE,
  236. // Socket lingers on close.
  237. LINGER = SO_LINGER,
  238. // Out-of-band data is transmitted in line.
  239. OOBINLINE = SO_OOBINLINE,
  240. // Receive buffer size.
  241. RCVBUF = SO_RCVBUF,
  242. // Receive low water mark.
  243. RCVLOWAT = SO_RCVLOWAT,
  244. // Receive timeout.
  245. RCVTIMEO = SO_RCVTIMEO,
  246. // Reuse of local addresses is supported.
  247. REUSEADDR = SO_REUSEADDR,
  248. // Send buffer size.
  249. SNDBUF = SO_SNDBUF,
  250. // Send low water mark.
  251. SNDLOWAT = SO_SNDLOWAT,
  252. // Send timeout.
  253. SNDTIMEO = SO_SNDTIMEO,
  254. // Socket type.
  255. TYPE = SO_TYPE,
  256. }
  257. when ODIN_OS == .NetBSD {
  258. @(private) LSOCKET :: "__socket30"
  259. } else {
  260. @(private) LSOCKET :: "socket"
  261. }
  262. when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD || ODIN_OS == .Linux || ODIN_OS == .Haiku {
  263. socklen_t :: distinct c.uint
  264. when ODIN_OS == .Haiku {
  265. @(private)
  266. _SA_DATASIZE :: 30
  267. } else {
  268. @(private)
  269. _SA_DATASIZE :: 14
  270. }
  271. when ODIN_OS == .Linux {
  272. _sa_family_t :: distinct c.ushort
  273. sockaddr :: struct {
  274. sa_family: sa_family_t, /* [PSX] address family */
  275. sa_data: [_SA_DATASIZE]c.char, /* [PSX] socket address */
  276. }
  277. } else {
  278. _sa_family_t :: distinct c.uint8_t
  279. sockaddr :: struct {
  280. sa_len: c.uint8_t, /* total length */
  281. sa_family: sa_family_t, /* [PSX] address family */
  282. sa_data: [_SA_DATASIZE]c.char, /* [PSX] socket address */
  283. }
  284. }
  285. when ODIN_OS == .OpenBSD {
  286. @(private)
  287. _SS_PAD1SIZE :: 6
  288. @(private)
  289. _SS_PAD2SIZE :: 240
  290. } else when ODIN_OS == .Haiku {
  291. @(private)
  292. _SS_PAD1SIZE :: 6
  293. @(private)
  294. _SS_PAD2SIZE :: 112
  295. } else when ODIN_OS == .Linux {
  296. @(private)
  297. _SS_SIZE :: 128
  298. @(private)
  299. _SS_PADSIZE :: _SS_SIZE - size_of(c.uint16_t) - size_of(c.uint64_t)
  300. } else {
  301. @(private)
  302. _SS_MAXSIZE :: 128
  303. @(private)
  304. _SS_ALIGNSIZE :: size_of(c.int64_t)
  305. @(private)
  306. _SS_PAD1SIZE :: _SS_ALIGNSIZE - size_of(c.uint8_t) - size_of(sa_family_t)
  307. @(private)
  308. _SS_PAD2SIZE :: _SS_MAXSIZE - size_of(c.uint8_t) - size_of(sa_family_t) - _SS_PAD1SIZE - _SS_ALIGNSIZE
  309. }
  310. when ODIN_OS == .Linux {
  311. sockaddr_storage :: struct {
  312. ss_family: sa_family_t, /* [PSX] address family */
  313. __ss_padding: [_SS_PADSIZE]c.char,
  314. __ss_align: c.uint64_t, /* force structure storage alignment */
  315. }
  316. msghdr :: struct {
  317. msg_name: rawptr, /* [PSX] optional address */
  318. msg_namelen: socklen_t, /* [PSX] size of address */
  319. msg_iov: [^]iovec, /* [PSX] scatter/gather array */
  320. msg_iovlen: c.size_t, /* [PSX] members in msg_iov */
  321. msg_control: rawptr, /* [PSX] ancillary data */
  322. msg_controllen: c.size_t, /* [PSX] ancillary data buffer length */
  323. msg_flags: Msg_Flags, /* [PSX] flags on received message */
  324. }
  325. cmsghdr :: struct {
  326. cmsg_len: c.size_t, /* [PSX] data byte count, including cmsghdr */
  327. cmsg_level: c.int, /* [PSX] originating protocol */
  328. cmsg_type: c.int, /* [PSX] protocol-specific type */
  329. }
  330. } else {
  331. sockaddr_storage :: struct {
  332. ss_len: c.uint8_t, /* address length */
  333. ss_family: sa_family_t, /* [PSX] address family */
  334. __ss_pad1: [_SS_PAD1SIZE]c.char,
  335. __ss_align: c.int64_t, /* force structure storage alignment */
  336. __ss_pad2: [_SS_PAD2SIZE]c.char,
  337. }
  338. msghdr :: struct {
  339. msg_name: rawptr, /* [PSX] optional address */
  340. msg_namelen: socklen_t, /* [PSX] size of address */
  341. msg_iov: [^]iovec, /* [PSX] scatter/gather array */
  342. msg_iovlen: c.int, /* [PSX] members in msg_iov */
  343. msg_control: rawptr, /* [PSX] ancillary data */
  344. msg_controllen: socklen_t, /* [PSX] ancillary data buffer length */
  345. msg_flags: Msg_Flags, /* [PSX] flags on received message */
  346. }
  347. cmsghdr :: struct {
  348. cmsg_len: socklen_t, /* [PSX] data byte count, including cmsghdr */
  349. cmsg_level: c.int, /* [PSX] originating protocol */
  350. cmsg_type: c.int, /* [PSX] protocol-specific type */
  351. }
  352. }
  353. SCM_RIGHTS :: 0x01
  354. @(private)
  355. __ALIGN32 :: #force_inline proc "contextless" (p: uintptr) -> uintptr {
  356. __ALIGNBYTES32 :: size_of(c.uint32_t) - 1
  357. return (p + __ALIGNBYTES32) &~ __ALIGNBYTES32
  358. }
  359. // Returns a pointer to the data array.
  360. CMSG_DATA :: #force_inline proc "contextless" (cmsg: ^cmsghdr) -> [^]c.uchar {
  361. return ([^]c.uchar)(uintptr(cmsg) + __ALIGN32(size_of(cmsghdr)))
  362. }
  363. // Returns a pointer to the next cmsghdr or nil.
  364. CMSG_NXTHDR :: #force_inline proc "contextless" (mhdr: ^msghdr, cmsg: ^cmsghdr) -> ^cmsghdr {
  365. if cmsg == nil {
  366. return CMSG_FIRSTHDR(mhdr)
  367. }
  368. ptr := uintptr(cmsg) + __ALIGN32(uintptr(cmsg.cmsg_len))
  369. if ptr + __ALIGN32(size_of(cmsghdr)) > uintptr(mhdr.msg_control) + uintptr(mhdr.msg_controllen) {
  370. return nil
  371. }
  372. return (^cmsghdr)(ptr)
  373. }
  374. // Returns a pointer to the first cmsghdr or nil.
  375. CMSG_FIRSTHDR :: #force_inline proc "contextless" (mhdr: ^msghdr) -> ^cmsghdr {
  376. if mhdr.msg_controllen >= size_of(cmsghdr) {
  377. return (^cmsghdr)(mhdr.msg_control)
  378. }
  379. return nil
  380. }
  381. linger :: struct {
  382. l_onoff: c.int, /* [PSX] indicates whether linger option is enabled */
  383. l_linger: c.int, /* [PSX] linger time in seconds */
  384. }
  385. SOCK_DGRAM :: 2
  386. SOCK_RAW :: 3
  387. SOCK_SEQPACKET :: 5
  388. SOCK_STREAM :: 1
  389. // Options to be accessed at socket level, not protocol level.
  390. when ODIN_OS == .Linux {
  391. SOL_SOCKET :: 1
  392. SO_ACCEPTCONN :: 30
  393. SO_BROADCAST :: 6
  394. SO_DEBUG :: 1
  395. SO_DONTROUTE :: 5
  396. SO_ERROR :: 4
  397. SO_KEEPALIVE :: 9
  398. SO_OOBINLINE :: 10
  399. SO_RCVBUF :: 8
  400. SO_RCVLOWAT :: 18
  401. SO_REUSEADDR :: 2
  402. SO_SNDBUF :: 7
  403. SO_SNDLOWAT :: 19
  404. SO_TYPE :: 3
  405. SO_LINGER :: 13
  406. SO_RCVTIMEO :: 66
  407. SO_SNDTIMEO :: 67
  408. } else when ODIN_OS == .Haiku {
  409. SOL_SOCKET :: -1
  410. SO_ACCEPTCONN :: 0x00000001
  411. SO_BROADCAST :: 0x00000002
  412. SO_DEBUG :: 0x00000004
  413. SO_DONTROUTE :: 0x00000008
  414. SO_ERROR :: 0x40000007
  415. SO_KEEPALIVE :: 0x00000010
  416. SO_OOBINLINE :: 0x00000020
  417. SO_RCVBUF :: 0x40000004
  418. SO_RCVLOWAT :: 0x40000005
  419. SO_REUSEADDR :: 0x00000040
  420. SO_SNDBUF :: 0x40000001
  421. SO_SNDLOWAT :: 0x40000002
  422. SO_TYPE :: 0x40000008
  423. SO_LINGER :: 0x00000200
  424. SO_RCVTIMEO :: 0x40000006
  425. SO_SNDTIMEO :: 0x40000003
  426. } else {
  427. SOL_SOCKET :: 0xffff
  428. SO_ACCEPTCONN :: 0x0002
  429. SO_BROADCAST :: 0x0020
  430. SO_DEBUG :: 0x0001
  431. SO_DONTROUTE :: 0x0010
  432. SO_ERROR :: 0x1007
  433. SO_KEEPALIVE :: 0x0008
  434. SO_OOBINLINE :: 0x0100
  435. SO_RCVBUF :: 0x1002
  436. SO_RCVLOWAT :: 0x1004
  437. SO_REUSEADDR :: 0x0004
  438. SO_SNDBUF :: 0x1001
  439. SO_SNDLOWAT :: 0x1003
  440. SO_TYPE :: 0x1008
  441. when ODIN_OS == .Darwin {
  442. SO_LINGER :: 0x1080
  443. SO_RCVTIMEO :: 0x1006
  444. SO_SNDTIMEO :: 0x1005
  445. } else when ODIN_OS == .FreeBSD {
  446. SO_LINGER :: 0x0080
  447. SO_RCVTIMEO :: 0x1006
  448. SO_SNDTIMEO :: 0x1005
  449. } else when ODIN_OS == .NetBSD {
  450. SO_LINGER :: 0x0080
  451. SO_RCVTIMEO :: 0x100c
  452. SO_SNDTIMEO :: 0x100b
  453. } else when ODIN_OS == .OpenBSD {
  454. SO_LINGER :: 0x0080
  455. SO_RCVTIMEO :: 0x1006
  456. SO_SNDTIMEO :: 0x1005
  457. }
  458. }
  459. // The maximum backlog queue length for listen().
  460. when ODIN_OS == .Haiku {
  461. SOMAXCONN :: 32
  462. } else {
  463. SOMAXCONN :: 128
  464. }
  465. when ODIN_OS == .Linux {
  466. MSG_CTRUNC :: 0x008
  467. MSG_DONTROUTE :: 0x004
  468. MSG_EOR :: 0x080
  469. MSG_OOB :: 0x001
  470. MSG_PEEK :: 0x002
  471. MSG_TRUNC :: 0x020
  472. MSG_WAITALL :: 0x100
  473. MSG_NOSIGNAL :: 0x4000
  474. } else {
  475. MSG_CTRUNC :: 0x20
  476. MSG_DONTROUTE :: 0x4
  477. MSG_EOR :: 0x8
  478. MSG_OOB :: 0x1
  479. MSG_PEEK :: 0x2
  480. MSG_TRUNC :: 0x10
  481. MSG_WAITALL :: 0x40
  482. when ODIN_OS == .Darwin {
  483. MSG_NOSIGNAL :: 0x80000
  484. } else when ODIN_OS == .FreeBSD {
  485. MSG_NOSIGNAL :: 0x00020000
  486. } else when ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD {
  487. MSG_NOSIGNAL :: 0x0400
  488. } else when ODIN_OS == .Haiku {
  489. MSG_NOSIGNAL :: 0x800
  490. }
  491. }
  492. when ODIN_OS == .Haiku {
  493. AF_INET :: 1
  494. AF_UNIX :: 9
  495. } else {
  496. AF_INET :: 2
  497. AF_UNIX :: 1
  498. }
  499. when ODIN_OS == .Darwin {
  500. AF_INET6 :: 30
  501. } else when ODIN_OS == .FreeBSD {
  502. AF_INET6 :: 28
  503. } else when ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD {
  504. AF_INET6 :: 24
  505. } else when ODIN_OS == .Linux {
  506. AF_INET6 :: 10
  507. } else when ODIN_OS == .Haiku {
  508. AF_INET6 :: 5
  509. }
  510. SHUT_RD :: 0
  511. SHUT_RDWR :: 2
  512. SHUT_WR :: 1
  513. }