hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

socket.ha (13111B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 export type sa_family_t = u16;
      5 export type socklen_t = uint;
      6 
      7 export type in_addr = struct {
      8 	s_addr: u32
      9 };
     10 
     11 export type sockaddr_in = struct {
     12 	sin_family: sa_family_t,
     13 	sin_port: u16,
     14 	sin_addr: in_addr,
     15 	__pad: [16]u8,
     16 };
     17 
     18 export type in6_addr = struct {
     19 	union {
     20 		s6_addr: [16]u8,
     21 		s6_addr16: [8]u16,
     22 		s6_addr32: [4]u32,
     23 	}
     24 };
     25 
     26 export type sockaddr_in6 = struct {
     27 	sin6_family: sa_family_t,
     28 	sin6_port: u16,
     29 	sin6_flowinfo: u32,
     30 	sin6_addr: in6_addr,
     31 	sin6_scope_id: u32,
     32 };
     33 
     34 export def UNIX_PATH_MAX: size = 108;
     35 
     36 export type sockaddr_un = struct {
     37 	sun_family: sa_family_t,
     38 	sun_path: [UNIX_PATH_MAX]u8,
     39 };
     40 
     41 export type sockaddr_nl = struct {
     42 	nl_family: sa_family_t,
     43 	nl_pad: u16,
     44 	nl_pid: u32,
     45 	nl_groups: u32,
     46 };
     47 
     48 export type sockaddr_ll = struct {
     49 	sll_family: sa_family_t,
     50 	sll_protocol: u16,
     51 	sll_ifindex: int,
     52 	sll_hatype: u16,
     53 	sll_pkttype: u8,
     54 	sll_halen: u8,
     55 	sll_addr: [8]u8,
     56 };
     57 
     58 export type sockaddr = struct {
     59 	union {
     60 		in: sockaddr_in,
     61 		in6: sockaddr_in6,
     62 		un: sockaddr_un,
     63 		nl: sockaddr_nl,
     64 		ll: sockaddr_ll,
     65 	},
     66 };
     67 
     68 export def SCM_RIGHTS: int = 0x01;
     69 export def SCM_CREDENTIALS: int = 0x02;
     70 
     71 export type msghdr = struct {
     72 	msg_name: nullable *opaque,
     73 	msg_namelen: u32,
     74 
     75 	msg_iov: nullable *[*]iovec,
     76 	msg_iovlen: size,
     77 
     78 	msg_control: nullable *opaque,
     79 	msg_controllen: size,
     80 
     81 	msg_flags: int
     82 };
     83 
     84 export type cmsg = struct {
     85 	hdr: cmsghdr,
     86 	cmsg_data: [*]u8,
     87 };
     88 
     89 export type sock_filter = struct {
     90 	__code: u16,
     91 	__jt: u8,
     92 	__jf: u8,
     93 	__k: u32,
     94 };
     95 
     96 export type sock_fprog = struct {
     97 	__len: u16,
     98 	__filter: *[*]sock_filter,
     99 };
    100 
    101 // domain for socket(2)
    102 
    103 // Unspecified
    104 export def AF_UNSPEC: sa_family_t = 0;
    105 // Unix domain sockets
    106 export def AF_UNIX: sa_family_t = 1;
    107 // POSIX name for AF_UNIX
    108 export def AF_LOCAL: sa_family_t = 1;
    109 // Internet IP Protocol
    110 export def AF_INET: sa_family_t = 2;
    111 // Amateur Radio AX.25
    112 export def AF_AX25: sa_family_t = 3;
    113 // Novell IPX
    114 export def AF_IPX: sa_family_t = 4;
    115 // AppleTalk DDP
    116 export def AF_APPLETALK: sa_family_t = 5;
    117 // Amateur Radio NET/ROM
    118 export def AF_NETROM: sa_family_t = 6;
    119 // Multiprotocol bridge
    120 export def AF_BRIDGE: sa_family_t = 7;
    121 // ATM PVCs
    122 export def AF_ATMPVC: sa_family_t = 8;
    123 // Reserved for X.25 project
    124 export def AF_X25: sa_family_t = 9;
    125 // IP version 6
    126 export def AF_INET6: sa_family_t = 10;
    127 // Amateur Radio X.25 PLP
    128 export def AF_ROSE: sa_family_t = 11;
    129 // Reserved for DECnet project
    130 export def AF_DECnet: sa_family_t = 12;
    131 // Reserved for 802.2LLC project
    132 export def AF_NETBEUI: sa_family_t = 13;
    133 // Security callback pseudo AF
    134 export def AF_SECURITY: sa_family_t = 14;
    135 // PF_KEY key management API
    136 export def AF_KEY: sa_family_t = 15;
    137 // Linux netlink API
    138 export def AF_NETLINK: sa_family_t = 16;
    139 // Alias to emulate 4.4BSD
    140 export def AF_ROUTE: sa_family_t = AF_NETLINK;
    141 // Packet family
    142 export def AF_PACKET: sa_family_t = 17;
    143 // Ash
    144 export def AF_ASH: sa_family_t = 18;
    145 // Acorn Econet
    146 export def AF_ECONET: sa_family_t = 19;
    147 // ATM SVCs
    148 export def AF_ATMSVC: sa_family_t = 20;
    149 // RDS sockets
    150 export def AF_RDS: sa_family_t = 21;
    151 // Linux SNA Project (nutters!)
    152 export def AF_SNA: sa_family_t = 22;
    153 // IRDA sockets
    154 export def AF_IRDA: sa_family_t = 23;
    155 // PPPoX sockets
    156 export def AF_PPPOX: sa_family_t = 24;
    157 // Wanpipe API Sockets
    158 export def AF_WANPIPE: sa_family_t = 25;
    159 // Linux LLC
    160 export def AF_LLC: sa_family_t = 26;
    161 // Native InfiniBand address
    162 export def AF_IB: sa_family_t = 27;
    163 // MPLS
    164 export def AF_MPLS: sa_family_t = 28;
    165 // Controller Area Network
    166 export def AF_CAN: sa_family_t = 29;
    167 // TIPC sockets
    168 export def AF_TIPC: sa_family_t = 30;
    169 // Bluetooth sockets
    170 export def AF_BLUETOOTH: sa_family_t = 31;
    171 // IUCV sockets
    172 export def AF_IUCV: sa_family_t = 32;
    173 // RxRPC sockets
    174 export def AF_RXRPC: sa_family_t = 33;
    175 // mISDN sockets
    176 export def AF_ISDN: sa_family_t = 34;
    177 // Phonet sockets
    178 export def AF_PHONET: sa_family_t = 35;
    179 // IEEE802154 sockets
    180 export def AF_IEEE802154: sa_family_t = 36;
    181 // CAIF sockets
    182 export def AF_CAIF: sa_family_t = 37;
    183 // Algorithm sockets
    184 export def AF_ALG: sa_family_t = 38;
    185 // NFC sockets
    186 export def AF_NFC: sa_family_t = 39;
    187 // vSockets
    188 export def AF_VSOCK: sa_family_t = 40;
    189 // Kernel Connection Multiplexor
    190 export def AF_KCM: sa_family_t = 41;
    191 // Qualcomm IPC Router
    192 export def AF_QIPCRTR: sa_family_t = 42;
    193 // smc sockets
    194 export def AF_SMC: sa_family_t = 43;
    195 // XDP sockets
    196 export def AF_XDP: sa_family_t = 44;
    197 
    198 // type for socket(2)
    199 export def SOCK_STREAM: int = 1;
    200 export def SOCK_DGRAM: int = 2;
    201 export def SOCK_RAW: int = 3;
    202 export def SOCK_RDM: int = 4;
    203 export def SOCK_SEQPACKET: int = 5;
    204 export def SOCK_DCCP: int = 6;
    205 export def SOCK_PACKET: int = 10;
    206 export def SOCK_NONBLOCK: int = 0o4000;
    207 export def SOCK_CLOEXEC: int = 0o2000000;
    208 
    209 // protocol for socket(2)
    210 export def ETH_P_15: int = 0x88f7;
    211 export def ETH_P_8021AD: int = 0x88a8;
    212 export def ETH_P_8021AH: int = 0x88e7;
    213 export def ETH_P_8021Q: int = 0x8100;
    214 export def ETH_P_80221: int = 0x8917;
    215 export def ETH_P_802_2: int = 0x4;
    216 export def ETH_P_802_3: int = 0x1;
    217 export def ETH_P_802_3_MIN: int = 0x600;
    218 export def ETH_P_802_EX1: int = 0x88b5;
    219 export def ETH_P_AARP: int = 0x80f3;
    220 export def ETH_P_AF_IUCV: int = 0xfbfb;
    221 export def ETH_P_ALL: int = 0x3;
    222 export def ETH_P_AOE: int = 0x88a2;
    223 export def ETH_P_ARCNET: int = 0x1a;
    224 export def ETH_P_ARP: int = 0x806;
    225 export def ETH_P_ATALK: int = 0x809b;
    226 export def ETH_P_ATMFATE: int = 0x8884;
    227 export def ETH_P_ATMMPOA: int = 0x884c;
    228 export def ETH_P_AX25: int = 0x2;
    229 export def ETH_P_BATMAN: int = 0x4305;
    230 export def ETH_P_BPQ: int = 0x8ff;
    231 export def ETH_P_CAIF: int = 0xf7;
    232 export def ETH_P_CAN: int = 0xc;
    233 export def ETH_P_CANFD: int = 0xd;
    234 export def ETH_P_CANXL: int = 0xe;
    235 export def ETH_P_CFM: int = 0x8902;
    236 export def ETH_P_CONTROL: int = 0x16;
    237 export def ETH_P_CUST: int = 0x6006;
    238 export def ETH_P_DDCMP: int = 0x6;
    239 export def ETH_P_DEC: int = 0x6000;
    240 export def ETH_P_DIAG: int = 0x6005;
    241 export def ETH_P_DNA_DL: int = 0x6001;
    242 export def ETH_P_DNA_RC: int = 0x6002;
    243 export def ETH_P_DNA_RT: int = 0x6003;
    244 export def ETH_P_DSA: int = 0x1b;
    245 export def ETH_P_DSA_8021Q: int = 0xdadb;
    246 export def ETH_P_DSA_A5PSW: int = 0xe001;
    247 export def ETH_P_ECONET: int = 0x18;
    248 export def ETH_P_EDSA: int = 0xdada;
    249 export def ETH_P_ERSPAN: int = 0x88be;
    250 export def ETH_P_ERSPAN2: int = 0x22eb;
    251 export def ETH_P_ETHERCAT: int = 0x88a4;
    252 export def ETH_P_FCOE: int = 0x8906;
    253 export def ETH_P_FIP: int = 0x8914;
    254 export def ETH_P_HDLC: int = 0x19;
    255 export def ETH_P_HSR: int = 0x892f;
    256 export def ETH_P_IBOE: int = 0x8915;
    257 export def ETH_P_IEEE802154: int = 0xf6;
    258 export def ETH_P_IEEEPUP: int = 0xa00;
    259 export def ETH_P_IEEEPUPAT: int = 0xa01;
    260 export def ETH_P_IFE: int = 0xed3e;
    261 export def ETH_P_IP: int = 0x800;
    262 export def ETH_P_IPV6: int = 0x86dd;
    263 export def ETH_P_IPX: int = 0x8137;
    264 export def ETH_P_IRDA: int = 0x17;
    265 export def ETH_P_LAT: int = 0x6004;
    266 export def ETH_P_LINK_CTL: int = 0x886c;
    267 export def ETH_P_LLDP: int = 0x88cc;
    268 export def ETH_P_LOCALTALK: int = 0x9;
    269 export def ETH_P_LOOP: int = 0x60;
    270 export def ETH_P_LOOPBACK: int = 0x9000;
    271 export def ETH_P_MACSEC: int = 0x88e5;
    272 export def ETH_P_MAP: int = 0xf9;
    273 export def ETH_P_MCTP: int = 0xfa;
    274 export def ETH_P_MOBITEX: int = 0x15;
    275 export def ETH_P_MPLS_MC: int = 0x8848;
    276 export def ETH_P_MPLS_UC: int = 0x8847;
    277 export def ETH_P_MRP: int = 0x88e3;
    278 export def ETH_P_MVRP: int = 0x88f5;
    279 export def ETH_P_NCSI: int = 0x88f8;
    280 export def ETH_P_NSH: int = 0x894f;
    281 export def ETH_P_PAE: int = 0x888e;
    282 export def ETH_P_PAUSE: int = 0x8808;
    283 export def ETH_P_PHONET: int = 0xf5;
    284 export def ETH_P_PPPTALK: int = 0x10;
    285 export def ETH_P_PPP_DISC: int = 0x8863;
    286 export def ETH_P_PPP_MP: int = 0x8;
    287 export def ETH_P_PPP_SES: int = 0x8864;
    288 export def ETH_P_PREAUTH: int = 0x88c7;
    289 export def ETH_P_PROFINET: int = 0x8892;
    290 export def ETH_P_PRP: int = 0x88fb;
    291 export def ETH_P_PUP: int = 0x200;
    292 export def ETH_P_PUPAT: int = 0x201;
    293 export def ETH_P_QINQ1: int = 0x9100;
    294 export def ETH_P_QINQ2: int = 0x9200;
    295 export def ETH_P_QINQ3: int = 0x9300;
    296 export def ETH_P_RARP: int = 0x8035;
    297 export def ETH_P_REALTEK: int = 0x8899;
    298 export def ETH_P_SCA: int = 0x6007;
    299 export def ETH_P_SLOW: int = 0x8809;
    300 export def ETH_P_SNAP: int = 0x5;
    301 export def ETH_P_TDLS: int = 0x890d;
    302 export def ETH_P_TEB: int = 0x6558;
    303 export def ETH_P_TIPC: int = 0x88ca;
    304 export def ETH_P_TRAILER: int = 0x1c;
    305 export def ETH_P_TR_802_2: int = 0x11;
    306 export def ETH_P_TSN: int = 0x22f0;
    307 export def ETH_P_WAN_PPP: int = 0x7;
    308 export def ETH_P_WCCP: int = 0x883e;
    309 export def ETH_P_X25: int = 0x805;
    310 export def ETH_P_XDSA: int = 0xf8;
    311 
    312 // Dummy protocol for TCP
    313 export def IPPROTO_IP: int = 0;
    314 // Internet Control Message Protocol
    315 export def IPPROTO_ICMP: int = 1;
    316 // Internet Group Management Protocol
    317 export def IPPROTO_IGMP: int = 2;
    318 // IPIP tunnels (older KA9Q tunnels use 94)
    319 export def IPPROTO_IPIP: int = 4;
    320 // Transmission Control Protocol
    321 export def IPPROTO_TCP: int = 6;
    322 // Exterior Gateway Protocol
    323 export def IPPROTO_EGP: int = 8;
    324 // PUP protocol
    325 export def IPPROTO_PUP: int = 12;
    326 // User Datagram Protocol
    327 export def IPPROTO_UDP: int = 17;
    328 // XNS IDP protocol
    329 export def IPPROTO_IDP: int = 22;
    330 // SO Transport Protocol Class 4
    331 export def IPPROTO_TP: int = 29;
    332 // Datagram Congestion Control Protocol
    333 export def IPPROTO_DCCP: int = 33;
    334 // IPv6-in-IPv4 tunnelling
    335 export def IPPROTO_IPV6: int = 41;
    336 // RSVP Protocol
    337 export def IPPROTO_RSVP: int = 46;
    338 // Cisco GRE tunnels (rfc 1701,1702)
    339 export def IPPROTO_GRE: int = 47;
    340 // Encapsulation Security Payload protocol
    341 export def IPPROTO_ESP: int = 50;
    342 // Authentication Header protocol
    343 export def IPPROTO_AH: int = 51;
    344 // ICMPv6
    345 export def IPPROTO_ICMPV6: int = 58;
    346 // Multicast Transport Protocol
    347 export def IPPROTO_MTP: int = 92;
    348 // IP option pseudo header for BEET
    349 export def IPPROTO_BEETPH: int = 94;
    350 // Encapsulation Header
    351 export def IPPROTO_ENCAP: int = 98;
    352 // Protocol Independent Multicast
    353 export def IPPROTO_PIM: int = 103;
    354 // Compression Header Protocol
    355 export def IPPROTO_COMP: int = 108;
    356 // Stream Control Transport Protocol
    357 export def IPPROTO_SCTP: int = 132;
    358 // UDP-Lite (RFC 3828)
    359 export def IPPROTO_UDPLITE: int = 136;
    360 // MPLS in IP (RFC 4023)
    361 export def IPPROTO_MPLS: int = 137;
    362 // Ethernet-within-IPv6 Encapsulation
    363 export def IPPROTO_ETHERNET: int = 143;
    364 // Raw IP packets
    365 export def IPPROTO_RAW: int = 255;
    366 // Multipath TCP connection
    367 export def IPPROTO_MPTCP: int = 262;
    368 
    369 // send/rcv flags
    370 export def MSG_OOB: int = 1;
    371 export def MSG_PEEK: int = 2;
    372 export def MSG_DONTROUTE: int = 4;
    373 export def MSG_TRYHARD: int = 4; // Synonym for MSG_DONTROUTE for DECnet
    374 export def MSG_CTRUNC: int = 8;
    375 export def MSG_PROBE: int = 0x10; // Do not send. Only probe path f.e. for MTU
    376 export def MSG_TRUNC: int = 0x20;
    377 export def MSG_DONTWAIT: int = 0x40; // Nonblocking io
    378 export def MSG_EOR: int = 0x80; // End of record
    379 export def MSG_WAITALL: int = 0x100; // Wait for a full request
    380 export def MSG_FIN: int = 0x200;
    381 export def MSG_SYN: int = 0x400;
    382 export def MSG_CONFIRM: int = 0x800; // Confirm path validity
    383 export def MSG_RST: int = 0x1000;
    384 export def MSG_ERRQUEUE: int = 0x2000; // Fetch message from error queue
    385 export def MSG_NOSIGNAL: int = 0x4000; // Do not generate SIGPIPE
    386 export def MSG_MORE: int = 0x8000; // Sender will send more
    387 export def MSG_WAITFORONE: int = 0x10000; // recvmmsg(): block until 1+ packets avail
    388 export def MSG_SENDPAGE_NOPOLICY: int = 0x10000; // sendpage() internal : do no apply policy
    389 export def MSG_SENDPAGE_NOTLAST: int = 0x20000; // sendpage() internal : not the last page
    390 export def MSG_BATCH: int = 0x40000; // sendmmsg(): more messages coming
    391 export def MSG_EOF: int = MSG_FIN;
    392 export def MSG_NO_SHARED_FRAGS: int = 0x80000; // sendpage() internal : page frags are not shared
    393 export def MSG_SENDPAGE_DECRYPTED: int = 0x100000; // sendpage() internal : page may carry * plain text and require encryption
    394 export def MSG_ZEROCOPY: int = 0x4000000; // Use user data in kernel path
    395 export def MSG_FASTOPEN: int = 0x20000000; // Send data in TCP SYN
    396 export def MSG_CMSG_CLOEXEC: int = 0x40000000; // Set close_on_exec for file descriptor received through SCM_RIGHTS
    397 
    398 // setsockopt levels
    399 export def SOL_SOCKET: int = 1;
    400 
    401 // setsockopt options
    402 export def SO_DEBUG: int = 1;
    403 export def SO_REUSEADDR: int = 2;
    404 export def SO_TYPE: int = 3;
    405 export def SO_ERROR: int = 4;
    406 export def SO_DONTROUTE: int = 5;
    407 export def SO_BROADCAST: int = 6;
    408 export def SO_SNDBUF: int = 7;
    409 export def SO_RCVBUF: int = 8;
    410 export def SO_SNDBUFFORCE: int = 32;
    411 export def SO_RCVBUFFORCE: int = 33;
    412 export def SO_KEEPALIVE: int = 9;
    413 export def SO_OOBINLINE: int = 10;
    414 export def SO_NO_CHECK: int = 11;
    415 export def SO_PRIORITY: int = 12;
    416 export def SO_LINGER: int = 13;
    417 export def SO_BSDCOMPAT: int = 14;
    418 export def SO_REUSEPORT: int = 15;
    419 export def SO_ATTACH_FILTER: int = 26;
    420 export def SO_DETATCH_FILTER: int = 27;
    421 export def SO_LOCK_FILTER: int = 44;
    422 
    423 // the following differ on ppc
    424 export def SO_PASSCRED: int = 16;
    425 export def SO_PEERCRED: int = 17;
    426 export def SO_RCVLOWAT: int = 18;
    427 export def SO_SNDLOWAT: int = 19;
    428 export def SO_RCVTIMEO_OLD: int = 20;
    429 export def SO_SNDTIMEO_OLD: int = 21;