socket.ha (3961B)
1 // SPDX-License-Identifier: MPL-2.0 2 // (c) Hare authors <https://harelang.org> 3 4 export type socklen_t = u32; 5 export type sa_family_t = u8; 6 7 export type in_addr = struct { 8 s_addr: u32 9 }; 10 11 export type sockaddr_in = struct { 12 sin_len: u8, 13 sin_family: sa_family_t, 14 sin_port: u16, 15 sin_addr: in_addr, 16 __pad: [8]u8, 17 }; 18 19 export type in6_addr = struct { 20 union { 21 s6_addr: [16]u8, 22 s6_addr16: [8]u16, 23 s6_addr32: [4]u32, 24 } 25 }; 26 27 export type sockaddr_in6 = struct { 28 sin6_len: u8, 29 sin6_family: sa_family_t, 30 sin6_port: u16, 31 sin6_flowinfo: u32, 32 sin6_addr: in6_addr, 33 sin6_scope_id: u32, 34 }; 35 36 export def UNIX_PATH_MAX: size = 104; 37 38 export type sockaddr_un = struct { 39 sun_len: u8, 40 sun_family: sa_family_t, 41 sun_path: [UNIX_PATH_MAX]u8, 42 }; 43 44 export type sockaddr = struct { 45 union { 46 in: sockaddr_in, 47 in6: sockaddr_in6, 48 un: sockaddr_un, 49 }, 50 }; 51 52 export def SCM_RIGHTS: int = 0x01; 53 export def SCM_TIMESTAMP: int = 0x04; 54 55 export type msghdr = struct { 56 msg_name: nullable *opaque, 57 msg_namelen: socklen_t, 58 msg_iov: nullable *[*]iovec, 59 msg_iovlen: uint, 60 msg_control: nullable *opaque, 61 msg_controllen: socklen_t, 62 msg_flags: int 63 }; 64 65 export type cmsghdr = struct { 66 cmsg_len: socklen_t, 67 cmsg_level: int, 68 cmsg_type: int, 69 }; 70 71 export type cmsg = struct { 72 hdr: cmsghdr, 73 cmsg_data: [*]u8, 74 }; 75 76 export def SOCK_STREAM: int = 1; 77 export def SOCK_DGRAM: int = 2; 78 export def SOCK_RAW: int = 3; 79 export def SOCK_RDM: int = 4; 80 export def SOCK_SEQPACKET: int = 5; 81 82 export def SOCK_CLOEXEC: int = 0x8000; 83 export def SOCK_NONBLOCK: int = 0x4000; 84 85 export def SOL_SOCKET: int = 0xffff; 86 87 export def AF_UNSPEC: sa_family_t = 0; 88 export def AF_UNIX: sa_family_t = 1; 89 export def AF_LOCAL: sa_family_t = AF_UNIX; 90 export def AF_INET: sa_family_t = 2; 91 export def AF_IMPLINK: sa_family_t = 3; 92 export def AF_PUP: sa_family_t = 4; 93 export def AF_CHAOS: sa_family_t = 5; 94 export def AF_NS: sa_family_t = 6; 95 export def AF_ISO: sa_family_t = 7; 96 export def AF_OSI: sa_family_t = AF_ISO; 97 export def AF_ECMA: sa_family_t = 8; 98 export def AF_DATAKIT: sa_family_t = 9; 99 export def AF_CCITT: sa_family_t = 10; 100 export def AF_SNA: sa_family_t = 11; 101 export def AF_DECnet: sa_family_t = 12; 102 export def AF_DLI: sa_family_t = 13; 103 export def AF_LAT: sa_family_t = 14; 104 export def AF_HYLINK: sa_family_t = 15; 105 export def AF_APPLETALK: sa_family_t = 16; 106 export def AF_ROUTE: sa_family_t = 17; 107 export def AF_LINK: sa_family_t = 18; 108 export def pseudo_AF_XTP: sa_family_t = 19; 109 export def AF_COIP: sa_family_t = 20; 110 export def AF_CNT: sa_family_t = 21; 111 export def pseudo_AF_RTIP: sa_family_t = 22; 112 export def AF_IPX: sa_family_t = 23; 113 export def AF_INET6: sa_family_t = 24; 114 export def pseudo_AF_PIP: sa_family_t = 25; 115 export def AF_ISDN: sa_family_t = 26; 116 export def AF_E164: sa_family_t = AF_ISDN; 117 export def AF_NATM: sa_family_t = 27; 118 export def AF_ENCAP: sa_family_t = 28; 119 export def AF_SIP: sa_family_t = 29; 120 export def AF_KEY: sa_family_t = 30; 121 export def pseudo_AF_HDRCMPLT: sa_family_t = 31; 122 123 export def SO_DEBUG: int = 0x0001; 124 export def SO_ACCEPTCONN: int = 0x0002; 125 export def SO_REUSEADDR: int = 0x0004; 126 export def SO_KEEPALIVE: int = 0x0008; 127 export def SO_DONTROUTE: int = 0x0010; 128 export def SO_BROADCAST: int = 0x0020; 129 export def SO_USELOOPBACK: int = 0x0040; 130 export def SO_LINGER: int = 0x0080; 131 export def SO_OOBINLINE: int = 0x0100; 132 export def SO_REUSEPORT: int = 0x0200; 133 export def SO_TIMESTAMP: int = 0x0800; 134 export def SO_BINDANY: int = 0x1000; 135 export def SO_ZEROIZE: int = 0x2000; 136 137 export def SO_SNDBUF: int = 0x1001; 138 export def SO_RCVBUF: int = 0x1002; 139 export def SO_SNDLOWAT: int = 0x1003; 140 export def SO_RCVLOWAT: int = 0x1004; 141 export def SO_SNDTIMEO: int = 0x1005; 142 export def SO_RCVTIMEO: int = 0x1006; 143 export def SO_ERROR: int = 0x1007; 144 export def SO_TYPE: int = 0x1008; 145 export def SO_NETPROC: int = 0x1020; 146 export def SO_RTABLE: int = 0x1021; 147 export def SO_PEERCRED: int = 0x1022; 148 export def SO_SPLICE: int = 0x1023; 149 export def SO_DOMAIN: int = 0x1024; 150 export def SO_PROTOCOL: int = 0x1025;