1 MODULE LinNet ["libc.so.90"];
3 (*
4 OpenBSD 6.2
5 i386
6 *)
8 CONST
9 NULL* = 0H;
11 SOCKET_ERROR* = -1;
12 INVALID_SOCKET* = -1;
14 INADDR_NONE* = -1;
15 INADDR_ANY* = 0;
17 (* socket domains *)
18 AF_UNSPEC* = 0; (* unspecified *)
19 AF_LOCAL* = 1; (* local to host (pipes, portals) *)
20 AF_UNIX* = AF_LOCAL; (* backward compatibility *)
21 AF_INET* = 2; (* internetwork: UDP, TCP, etc. *)
22 AF_IMPLINK* = 3; (* arpanet imp addresses *)
23 AF_PUP* = 4; (* pup protocols: e.g. BSP *)
24 AF_CHAOS* = 5; (* mit CHAOS protocols *)
25 AF_NS* = 6; (* XEROX NS protocols *)
26 AF_ISO* = 7; (* ISO protocols *)
27 AF_ECMA* = 8; (* european computer manufacturers *)
28 AF_DATAKIT* = 9; (* datakit protocols *)
29 AF_CCITT* = 10; (* CCITT protocols, X.25 etc *)
30 AF_SNA* = 11; (* IBM SNA *)
31 AF_DECnet* = 12; (* DECnet *)
32 AF_DLI* = 13; (* DEC Direct data link interface *)
33 AF_LAT* = 14; (* LAT *)
34 AF_HYLINK* = 15; (* NSC Hyperchannel *)
35 AF_APPLETALK* = 16; (* Apple Talk *)
36 AF_ROUTE* = 17; (* Internal Routing Protocol *)
37 AF_LINK* = 18; (* Link layer interface *)
38 AF_COIP* = 20; (* connection-oriented IP, aka ST II *)
39 AF_CNT* = 21; (* Computer Network Technology *)
40 AF_IPX* = 23; (* Novell Internet Protocol *)
41 AF_INET6* = 24; (* IPv6 *)
42 AF_ISDN* = 26; (* Integrated Services Digital Network *)
43 AF_E164* = AF_ISDN; (* CCITT E.164 recommendation *)
44 AF_NATM* = 27; (* native ATM access *)
45 AF_ENCAP* = 28;
46 AF_SIP* = 29; (* Simple Internet Protocol *)
47 AF_KEY* = 30;
48 AF_BLUETOOTH* = 32; (* Bluetooth *)
49 AF_MPLS* = 33; (* MPLS *)
50 AF_MAX* = 36;
52 (* socket types *)
53 SOCK_STREAM* = 1; (* stream socket *)
54 SOCK_DGRAM* = 2; (* datagram socket *)
55 SOCK_RAW* = 3; (* raw-protocol interface *)
56 SOCK_RDM* = 4; (* reliably-delivered message *)
57 SOCK_SEQPACKET* = 5; (* sequenced packet stream *)
59 (* socket protocols *)
60 IPPROTO_IP* = 0; (* dummy for IP *)
61 IPPROTO_HOPOPTS* = IPPROTO_IP; (* Hop-by-hop option header *)
62 IPPROTO_ICMP* = 1; (* control message protocol *)
63 IPPROTO_IGMP* = 2; (* group mgmt protocol *)
64 IPPROTO_GGP* = 3; (* gateway^2 (deprecated) *)
65 IPPROTO_IPIP* = 4; (* IP inside IP *)
66 IPPROTO_IPV4* = IPPROTO_IPIP; (* IP inside IP *)
67 IPPROTO_TCP* = 6; (* tcp *)
68 IPPROTO_EGP* = 8; (* exterior gateway protocol *)
69 IPPROTO_PUP* = 12; (* pup *)
70 IPPROTO_UDP* = 17; (* user datagram protocol *)
71 IPPROTO_IDP* = 22; (* xns idp *)
72 IPPROTO_TP* = 29; (* tp-4 w/ class negotiation *)
73 IPPROTO_IPV6* = 41; (* IPv6 in IPv6 *)
74 IPPROTO_ROUTING* = 43; (* Routing header *)
75 IPPROTO_FRAGMENT* = 44; (* Fragmentation/reassembly header *)
76 IPPROTO_RSVP* = 46; (* resource reservation *)
77 IPPROTO_GRE* = 47; (* GRE encap, RFCs 1701/1702 *)
78 IPPROTO_ESP* = 50; (* Encap. Security Payload *)
79 IPPROTO_AH* = 51; (* Authentication header *)
80 IPPROTO_MOBILE* = 55; (* IP Mobility, RFC 2004 *)
81 IPPROTO_ICMPV6* = 58; (* ICMP for IPv6 *)
82 IPPROTO_NONE* = 59; (* No next header *)
83 IPPROTO_DSTOPTS* = 60; (* Destination options header *)
84 IPPROTO_EON* = 80; (* ISO cnlp *)
85 IPPROTO_ETHERIP* = 97; (* Ethernet in IPv4 *)
86 IPPROTO_ENCAP* = 98; (* encapsulation header *)
87 IPPROTO_PIM* = 103; (* Protocol indep. multicast *)
88 IPPROTO_IPCOMP* = 108; (* IP Payload Comp. Protocol *)
89 IPPROTO_CARP* = 112; (* CARP *)
90 IPPROTO_MPLS* = 137; (* unicast MPLS packet *)
91 IPPROTO_PFSYNC* = 240; (* PFSYNC *)
92 IPPROTO_RAW* = 255; (* raw IP packet *)
93 IPPROTO_MAX* = 256;
94 IPPROTO_DIVERT* = 258; (* Divert sockets *)
95 IPPROTO_DONE* = 257;
96 IPPROTO_DIVERT_RESP* = 01H; (* {0} *) (* divert response packets *)
97 IPPROTO_DIVERT_INIT* = 02H; (* {1} *) (* divert packets initial direction *)
99 (* socket options *)
100 SO_DEBUG* = {0}; (* turn on debugging info recording *)
101 SO_ACCEPTCONN* = {1}; (* socket has had listen() *)
102 SO_REUSEADDR* = {2}; (* allow local address reuse *)
103 SO_KEEPALIVE* = {3}; (* keep connections alive *)
104 SO_DONTROUTE* = {4}; (* just use interface addresses *)
105 SO_BROADCAST* = {5}; (* permit sending of broadcast msgs *)
106 SO_USELOOPBACK* = {6}; (* bypass hardware when possible *)
107 SO_LINGER* = {7}; (* linger on close if data present *)
108 SO_OOBINLINE* = {8}; (* leave received OOB data in line *)
109 SO_REUSEPORT* = {9}; (* allow local address & port reuse *)
110 SO_TIMESTAMP* = {11}; (* timestamp received dgram traffic *)
111 SO_BINDANY* = {12}; (* allow bind to any address *)
112 SO_ZEROIZE* = {13}; (* zero out all mbufs sent over socket *)
113 SO_SNDBUF* = {0,12}; (* send buffer size *)
114 SO_RCVBUF* = {1,12}; (* receive buffer size *)
115 SO_SNDLOWAT* = {0,1,12}; (* send low-water mark *)
116 SO_RCVLOWAT* = {2,12}; (* receive low-water mark *)
117 SO_SNDTIMEO* = {0,2,12}; (* send timeout *)
118 SO_RCVTIMEO* = {1,2,12}; (* receive timeout *)
119 SO_ERROR* = {0..2,12}; (* get error status and clear *)
120 SO_TYPE* = {3,12}; (* get socket type *)
121 SO_NETPROC* = {5,12}; (* multiplex; network processing *)
122 SO_RTABLE* = {0,5,12}; (* routing table to be used *)
123 SO_PEERCRED* = {1,5,12}; (* get connect-time credentials *)
124 SO_SPLICE* = {0,1,5,12}; (* splice data to other socket *)
126 SHUT_RD* = 0;
127 SHUT_WR* = 1;
128 SHUT_RDWR* = 2;
130 SOL_SOCKET* = 0FFFFH; (* {0..15} *) (* options for socket level *)
132 MSG_OOB* = {0}; (* process out-of-band data *)
133 MSG_PEEK* = {1}; (* peek at incoming message *)
134 MSG_DONTROUTE* = {2}; (* send without using routing tables *)
135 MSG_EOR* = {3}; (* data completes record *)
136 MSG_TRUNC* = {4}; (* data discarded before delivery *)
137 MSG_CTRUNC* = {5}; (* control data lost before delivery *)
138 MSG_WAITALL* = {6}; (* wait for full request or error *)
139 MSG_DONTWAIT* = {7}; (* this message should be nonblocking *)
140 MSG_BCAST* = {8}; (* this message rec'd as broadcast *)
141 MSG_MCAST* = {9}; (* this message rec'd as multicast *)
142 MSG_NOSIGNAL* = {10}; (* do not send SIGPIPE *)
143 MSG_CMSG_CLOEXEC* = {11}; (* set FD_CLOEXEC on received fds *)
145 SOMAXCONN* = 128;
147 (* addrinfo.ai_flags *)
148 AI_PASSIVE* = {0}; (* socket address is intended for bind() *)
149 AI_CANONNAME* = {1}; (* request for canonical name *)
150 AI_NUMERICHOST* = {2}; (* don't ever try hostname lookup *)
151 AI_EXT* = {3}; (* enable non-portable extensions *)
152 AI_NUMERICSERV* = {4}; (* don't ever try servname lookup *)
153 AI_FQDN* = {5}; (* return the FQDN that was resolved *)
154 AI_ADDRCONFIG* = {6}; (* return configured address families only *)
156 (* getaddrinfo/getnameinfo/gai_strerror error codes *)
157 EAI_BADFLAGS* = -1; (* invalid value for ai_flags *)
158 EAI_NONAME* = -2; (* name or service is not known *)
159 EAI_AGAIN* = -3; (* temporary failure in name resolution *)
160 EAI_FAIL* = -4; (* non-recoverable failure in name resolution *)
161 EAI_NODATA* = -5; (* no address associated with name *)
162 EAI_FAMILY* = -6; (* ai_family not supported *)
163 EAI_SOCKTYPE* = -7; (* ai_socktype not supported *)
164 EAI_SERVICE* = -8; (* service not supported for ai_socktype *)
165 EAI_ADDRFAMILY* = -9; (* address family for name not supported *)
166 EAI_MEMORY* = -10; (* memory allocation failure *)
167 EAI_SYSTEM* = -11; (* system error (code indicated in errno) *)
168 EAI_BADHINTS* = -12; (* invalid value for hints *)
169 EAI_PROTOCOL* = -13; (* resolved protocol is unknown *)
170 EAI_OVERFLOW* = -14; (* argument buffer overflow *)
172 (* OpenBSD 6.0 /usr/include/sys/select.h *)
173 FD_SETSIZE = 1024;
174 __NBBY = 8;
176 TYPE
177 u_int8_t = SHORTCHAR;
178 int8_t = SHORTCHAR;
179 uint16_t = SHORTINT;
180 (* PtrVoid, int, intFlags, short, socklen_t, size_t, ssize_t, in_addr_t, in_port_t, time_t, suseconds_t, nfds_t, sa_family_t *)
181 PtrVoid* = INTEGER;
182 short* = SHORTINT;
183 int* = INTEGER;
184 intFlags* = SET;
185 size_t* = INTEGER;
186 ssize_t* = INTEGER;
187 time_t* = LONGINT;
188 suseconds_t* = INTEGER;
189 socklen_t* = INTEGER;
190 in_addr_t* = INTEGER;
191 in_port_t* = SHORTINT;
192 nfds_t* = INTEGER;
193 sa_family_t* = SHORTCHAR;
195 PtrSTR* = POINTER [untagged] TO ARRAY [untagged] OF SHORTCHAR;
197 SOCKET* = int;
199 (*
200 in_addr* = RECORD [untagged]
201 s_addr*: in_addr_t;
202 END;
203 *)
204 in_addr* = RECORD [untagged]
205 S_un*: RECORD [union]
206 S_un_b*: RECORD [untagged]
207 s_b1*: SHORTCHAR;
208 s_b2*: SHORTCHAR;
209 s_b3*: SHORTCHAR;
210 s_b4*: SHORTCHAR;
211 END;
212 S_un_w*: RECORD [untagged]
213 s_w1*: SHORTINT;
214 s_w2*: SHORTINT;
215 END;
216 S_addr*: in_addr_t;
217 END;
218 END;
220 Ptrsockaddr* = POINTER [untagged] TO sockaddr;
221 sockaddr* = RECORD [untagged]
222 (* OpenBSD /usr/include/sys/socket.h *)
223 sa_len*: SHORTCHAR; (* total length *)
224 sa_family*: sa_family_t; (* address family *)
225 sa_data*: ARRAY [untagged] 14 OF SHORTCHAR; (* actually longer; address value *)
226 END;
228 Ptrsockaddr_storage = POINTER [untagged] TO sockaddr_storage;
229 sockaddr_storage* = RECORD [untagged]
230 (* OpenBSD 6.0 /usr/include/sys/socket.h *)
231 ss_len*: SHORTCHAR; (* total length *)
232 ss_family*: sa_family_t; (* address family *)
233 __ss_pad1: ARRAY [untagged] 6 OF SHORTCHAR; (* align to quad *)
234 __ss_pad2: LONGINT; (* force alignment for stupid compilers *)
235 __ss_pad3: ARRAY [untagged] 240 OF SHORTCHAR; (* pad to a total of 256 bytes *)
236 END;
238 Ptrsockaddr_in* = POINTER [untagged] TO sockaddr_in;
239 sockaddr_in* = RECORD [untagged]
240 (* OpenBSD /usr/include/netinet/in.h *)
241 sin_len*: u_int8_t;
242 sin_family*: sa_family_t;
243 sin_port*: in_port_t;
244 sin_addr*: in_addr;
245 sin_zero*: ARRAY [untagged] 8 OF int8_t;
246 END;
248 Ptraddrinfo* = POINTER [untagged] TO addrinfo;
249 addrinfo* = RECORD [untagged]
250 (* OpenBSD 6.0 /usr/include/netdb.h *)
251 ai_flags*: intFlags; (* input flags *)
252 ai_family*: int; (* protocol family for socket *)
253 ai_socktype*: int; (* socket type *)
254 ai_protocol*: int; (* protocol for socket *)
255 ai_addrlen*: socklen_t; (* length of socket-address *)
256 ai_addr*: Ptrsockaddr; (* socket-address for socket *)
257 ai_canonname*: PtrSTR; (* canonical name for service location (iff req) *)
258 ai_next*: Ptraddrinfo; (* pointer to next in list *)
259 END;
261 timeval* = RECORD [untagged]
262 (* Linux, FreeBSD, OpenBSD *)
263 tv_sec*: time_t; (* seconds *)
264 tv_usec*: suseconds_t; (* and microseconds *)
265 END;
267 pollfd* = RECORD [untagged]
268 (* Linux, FreeBSD, OpenBSD *)
269 fd*: int;
270 events*: short;
271 revents*: short;
272 END;
274 (* OpenBSD 6.0 /usr/include/sys/select.h *)
275 __fd_mask = SET;
276 fd_set* = ARRAY [untagged] (FD_SETSIZE + (SIZE(__fd_mask) * __NBBY - 1)) DIV (SIZE(__fd_mask) * __NBBY) OF __fd_mask;
278 (* POSIX.1 *)
279 PROCEDURE [ccall] socket* (domain: int; type: int; protocol: int): SOCKET;
280 PROCEDURE [ccall] accept* (s: SOCKET; VAR addr: sockaddr; VAR addrlen: socklen_t): SOCKET;
281 PROCEDURE [ccall] bind* (s: SOCKET; VAR name: sockaddr; namelen: socklen_t): int;
282 PROCEDURE [ccall] connect* (s: SOCKET; VAR name: sockaddr; namelen: socklen_t): int;
283 PROCEDURE [ccall] getsockname* (s: SOCKET; VAR name: sockaddr; VAR namelen: socklen_t): int;
284 PROCEDURE [ccall] listen* (s: SOCKET; backlog: int): int;
285 PROCEDURE [ccall] recv* (s: SOCKET; buf: PtrVoid; len: size_t; flags: intFlags): ssize_t;
286 PROCEDURE [ccall] recvfrom* (s: SOCKET; buf: PtrVoid; len: size_t; flags: intFlags; VAR from: sockaddr; VAR fromlen: socklen_t): ssize_t;
287 PROCEDURE [ccall] send* (s: SOCKET; msg: PtrVoid; len: size_t; flags: intFlags): ssize_t;
288 PROCEDURE [ccall] sendto* (s: SOCKET; msg: PtrVoid; len: size_t; flags: intFlags; VAR to: sockaddr; tolen: socklen_t): ssize_t;
289 PROCEDURE [ccall] shutdown* (s: SOCKET; how: int): int;
290 PROCEDURE [ccall] getsockopt* (s: SOCKET; level: int; optname: intFlags; optval: PtrVoid; VAR [nil] optlen: socklen_t): int;
291 PROCEDURE [ccall] setsockopt* (s: SOCKET; level: int; optname: intFlags; optval: PtrVoid; optlen: socklen_t): int;
293 PROCEDURE [ccall] inet_addr* (cp: PtrSTR): in_addr_t;
294 PROCEDURE [ccall] htons* (host16: uint16_t): uint16_t;
296 PROCEDURE [ccall] select* (nfds: INTEGER; VAR [nil] readfds: fd_set; VAR [nil] writefds: fd_set; VAR [nil] exceptfds: fd_set; VAR timeout: timeval): int;
298 PROCEDURE [ccall] poll* (VAR fds: ARRAY [untagged] OF pollfd; nfds: nfds_t; timeout: int): int;
300 (*
301 PROCEDURE FD_ZERO (VAR set: Net.fd_set);
302 VAR i: INTEGER;
303 BEGIN
304 i := LEN(set); REPEAT DEC(i); set[i] := {} UNTIL i = 0
305 END FD_ZERO;
307 PROCEDURE FD_SET (fd: Net.SOCKET; VAR set: Net.fd_set);
308 BEGIN
309 INCL(set[fd DIV 32], fd MOD 32)
310 END FD_SET;
311 *)
313 (* POSIX.1g *)
314 PROCEDURE [ccall] getaddrinfo* (hostname: PtrSTR; servname: PtrSTR; VAR [nil] hints: addrinfo; VAR res: Ptraddrinfo): int;
315 PROCEDURE [ccall] freeaddrinfo* (ai: Ptraddrinfo);
317 PROCEDURE [ccall] gai_strerror* (ecode: int): PtrSTR;
319 END LinNet.