1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
|
Fix many incorrect things in the Usocket interface for FreeBSD.
Also make provisions for using SOCKS.
--- m3/m3core/src/unix/freebsd-2/Usocket.i3.orig Sat Jan 7 14:22:22 1995
+++ m3/m3core/src/unix/freebsd-2/Usocket.i3 Thu Oct 24 16:04:43 1996
@@ -30,28 +30,30 @@
(*
* Option flags per-socket.
*)
- SO_DEBUG = 1; (* turn on debugging info recording *)
- SO_REUSEADDR = 2; (* allow local address reuse *)
- SO_TYPE = 3; (* get socket type *)
- SO_ERROR = 4; (* get error status and clear *)
- SO_DONTROUTE = 5; (* just use interface addresses *)
- SO_BROADCAST = 6; (* permit sending of broadcast msgs *)
- SO_SNDBUF = 7; (* send buffer size *)
- SO_RCVBUF = 8; (* receive buffer size *)
- SO_KEEPALIVE = 9; (* keep connections alive *)
- SO_OOBINLINE = 10; (* leave received OOB data in line *)
- SO_NO_CHECK = 11;
- SO_PRIORITY = 12;
- SO_LINGER = 13; (* linger on close if data present *)
+ SO_DEBUG = 16_0001; (* turn on debugging info recording *)
+ SO_ACCEPTCONN = 16_0002; (* socket has had listen() *)
+ SO_REUSEADDR = 16_0004; (* allow local address reuse *)
+ SO_KEEPALIVE = 16_0008; (* keep connections alive *)
+ SO_DONTROUTE = 16_0010; (* just use interface addresses *)
+ SO_BROADCAST = 16_0020; (* permit sending of broadcast msgs *)
+ SO_USELOOPBACK = 16_0040; (* bypass hardware when possible *)
+ SO_LINGER = 16_0080; (* linger on close if data present *)
+ SO_OOBINLINE = 16_0100; (* leave received OOB data in line *)
+ SO_REUSEPORT = 16_0200; (* allow local address & port reuse *)
+ SO_TIMESTAMP = 16_0400; (* timestamp received dgram traffic *)
(*
* Additional options, not kept in so_options.
*)
- (* these constants may not be implemented - be careful *)
- SO_SNDLOWAT = 16_1003; (* send low-water mark *)
- SO_RCVLOWAT = 16_1004; (* receive low-water mark *)
- SO_SNDTIMEO = 16_1005; (* send timeout *)
- SO_RCVTIMEO = 16_1006; (* receive timeout *)
+ SO_SNDBUF = 16_1001; (* send buffer size *)
+ SO_RCVBUF = 16_1002; (* receive buffer size *)
+ SO_SNDLOWAT = 16_1003; (* send low-water mark *)
+ SO_RCVLOWAT = 16_1004; (* receive low-water mark *)
+ SO_SNDTIMEO = 16_1005; (* send timeout *)
+ SO_RCVTIMEO = 16_1006; (* receive timeout *)
+ SO_ERROR = 16_1007; (* get error status and clear *)
+ SO_TYPE = 16_1008; (* get socket type *)
+ SO_PRIVSTATE = 16_1009; (* get/deny privileged state *)
(*
* Structure used for manipulating linger option.
@@ -67,38 +69,45 @@
* Level number for (get/set)sockopt() to apply to socket itself.
*)
CONST
- SOL_SOCKET = 1; (* options for socket level *)
+ SOL_SOCKET = 16_ffff; (* options for socket level *)
(*
* Address families.
*)
- AF_UNSPEC = 0; (* unspecified *)
- AF_UNIX = 1; (* local to host (pipes, portals) *)
- AF_INET = 2; (* internetwork: UDP, TCP, etc. *)
- AF_AX25 = 3;
- AF_IPX = 4;
-
- AF_MAX = 5;
-
-(*****
- AF_IMPLINK = 3; (* arpanet imp addresses *)
- AF_PUP = 4; (* pup protocols: e.g. BSP *)
- AF_CHAOS = 5; (* mit CHAOS protocols *)
- AF_NS = 6; (* XEROX NS protocols *)
- AF_NBS = 7; (* nbs protocols *)
- AF_ECMA = 8; (* european computer manufacturers *)
- AF_DATAKIT = 9; (* datakit protocols *)
- AF_CCITT = 10; (* CCITT protocols, X.25 etc *)
- AF_SNA = 11; (* IBM SNA *)
- AF_DECnet = 12; (* DECnet *)
- AF_DLI = 13; (* Direct data link interface *)
- AF_LAT = 14; (* LAT *)
- AF_HYLINK = 15; (* NSC Hyperchannel *)
- AF_APPLETALK = 16; (* Apple talk *)
- AF_BSC = 17; (* BISYNC 2780/3780 *)
- AF_DSS = 18; (* Distributed system services *)
-*******)
+ AF_UNSPEC = 0; (* unspecified *)
+ AF_LOCAL = 1; (* local to host (pipes, portals) *)
+ AF_UNIX = AF_LOCAL; (* backward compatibility *)
+ AF_INET = 2; (* internetwork: UDP, TCP, etc. *)
+ AF_IMPLINK = 3; (* arpanet imp addresses *)
+ AF_PUP = 4; (* pup protocols: e.g. BSP *)
+ AF_CHAOS = 5; (* mit CHAOS protocols *)
+ AF_NS = 6; (* XEROX NS protocols *)
+ AF_ISO = 7; (* ISO protocols *)
+ AF_OSI = AF_ISO;
+ AF_ECMA = 8; (* European computer manufacturers *)
+ AF_DATAKIT = 9; (* datakit protocols *)
+ AF_CCITT = 10; (* CCITT protocols, X.25 etc *)
+ AF_SNA = 11; (* IBM SNA *)
+ AF_DECnet = 12; (* DECnet *)
+ AF_DLI = 13; (* DEC Direct data link interface *)
+ AF_LAT = 14; (* LAT *)
+ AF_HYLINK = 15; (* NSC Hyperchannel *)
+ AF_APPLETALK = 16; (* Apple Talk *)
+ AF_ROUTE = 17; (* Internal Routing Protocol *)
+ AF_LINK = 18; (* Link layer interface *)
+ pseudo_AF_XTP = 19; (* eXpress Transfer Protocol (no AF) *)
+ AF_COIP = 20; (* connection-oriented IP, aka ST II *)
+ AF_CNT = 21; (* Computer Network Technology *)
+ pseudo_AF_RTIP = 22; (* Help Identify RTIP packets *)
+ AF_IPX = 23; (* Novell Internet Protocol *)
+ AF_SIP = 24; (* Simple Internet Protocol *)
+ pseudo_AF_PIP = 25; (* Help Identify PIP packets *)
+ AF_ISDN = 26; (* Integrated Services Digital Network*)
+ AF_E164 = AF_ISDN; (* CCITT E.164 recommendation *)
+ pseudo_AF_KEY = 27; (* Internal key-management function *)
+
+ AF_MAX = 28;
(*
* Structure used by kernel to store most
@@ -106,9 +115,9 @@
*)
TYPE
struct_sockaddr = RECORD
- sa_family: Ctypes.unsigned_short; (* address family *)
- sa_data: ARRAY [0..13] OF Ctypes.char;
- (* up to 14 bytes of direct address *)
+ sa_len: Ctypes.unsigned_char; (* total length *)
+ sa_family: Ctypes.unsigned_char; (* address family *)
+ sa_data: ARRAY [0..13] OF Ctypes.char; (* address; actually longer *)
END;
@@ -116,7 +125,6 @@
* Structure used by kernel to pass protocol
* information in raw sockets.
*)
- (* Can't find this one either .. be careful *)
struct_sockproto = RECORD
sp_family: Ctypes.unsigned_short; (* address family *)
sp_protocol: Ctypes.unsigned_short; (* protocol *)
@@ -126,75 +134,101 @@
* Protocol families, same as address families for now.
*)
CONST
+ PF_UNSPEC = AF_UNSPEC;
+ PF_LOCAL = AF_LOCAL;
+ PF_UNIX = PF_LOCAL; (* backward compatibility *)
+ PF_INET = AF_INET;
+ PF_IMPLINK = AF_IMPLINK;
+ PF_PUP = AF_PUP;
+ PF_CHAOS = AF_CHAOS;
+ PF_NS = AF_NS;
+ PF_ISO = AF_ISO;
+ PF_OSI = AF_ISO;
+ PF_ECMA = AF_ECMA;
+ PF_DATAKIT = AF_DATAKIT;
+ PF_CCITT = AF_CCITT;
+ PF_SNA = AF_SNA;
+ PF_DECnet = AF_DECnet;
+ PF_DLI = AF_DLI;
+ PF_LAT = AF_LAT;
+ PF_HYLINK = AF_HYLINK;
+ PF_APPLETALK = AF_APPLETALK;
+ PF_ROUTE = AF_ROUTE;
+ PF_LINK = AF_LINK;
+ PF_XTP = pseudo_AF_XTP; (* really just proto family, no AF *)
+ PF_COIP = AF_COIP;
+ PF_CNT = AF_CNT;
+ PF_SIP = AF_SIP;
+ PF_IPX = AF_IPX; (* same format as AF_NS *)
+ PF_RTIP = pseudo_AF_RTIP; (* same format as AF_INET *)
+ PF_PIP = pseudo_AF_PIP;
+ PF_ISDN = AF_ISDN;
+ PF_KEY = pseudo_AF_KEY;
- PF_UNSPEC = AF_UNSPEC;
- PF_UNIX = AF_UNIX;
- PF_INET = AF_INET;
- PF_AX25 = AF_AX25;
- PF_IPX = AF_IPX;
-
- (* NO supported on Linux:
- PF_IMPLINK = AF_IMPLINK;
- PF_PUP = AF_PUP;
- PF_CHAOS = AF_CHAOS;
- PF_NS = AF_NS;
- PF_NBS = AF_NBS;
- PF_ECMA = AF_ECMA;
- PF_DATAKIT = AF_DATAKIT;
- PF_CCITT = AF_CCITT;
- PF_SNA = AF_SNA;
- PF_DECnet = AF_DECnet;
- PF_DLI = AF_DLI;
- PF_LAT = AF_LAT;
- PF_HYLINK = AF_HYLINK;
- PF_APPLETALK = AF_APPLETALK;
- PF_BSC = AF_BSC;
- PF_DSS = AF_DSS;
- ************)
-
- PF_MAX = AF_MAX;
+ PF_MAX = AF_MAX;
(*
* Maximum queue length specifiable by listen.
*)
- (* Not defined under Linux - be careful *)
- SOMAXCONN = 5;
+ SOMAXCONN = 128;
(*
* Message header for recvmsg and sendmsg calls.
*)
TYPE
- (* Again, I haven't checked this structure *)
struct_msghdr = RECORD
- msg_name: Utypes.caddr_t; (* optional address *)
- msg_namelen: Ctypes.int; (* size of address *)
- msg_iov: Uuio.struct_iovec_star; (* scatter/gather array *)
- msg_iovlen: Ctypes.int; (* # elements in msg_iov *)
- msg_accrights: Utypes.caddr_t; (* access rights sent/received *)
- msg_accrightslen: Ctypes.int;
+ msg_name: Utypes.caddr_t; (* optional address *)
+ msg_namelen: Ctypes.unsigned_int; (* size of address *)
+ msg_iov: Uuio.struct_iovec_star; (* scatter/gather array *)
+ msg_iovlen: Ctypes.unsigned_int; (* # elements in msg_iov *)
+ msg_control: Utypes.caddr_t; (* ancillary data, see below *)
+ msg_controllen: Ctypes.unsigned_int; (* ancillary data buffer len *)
+ msg_flags: Ctypes.int; (* flags on received message *)
END;
CONST
- MSG_OOB = 16_1; (* process out-of-band data *)
- MSG_PEEK = 16_2; (* peek at incoming message *)
-(* The following aren't defined in /usr/include/linux/socket.h *)
-(**
- MSG_DONTROUTE = 16_4; (* send without using routing tables *)
+ MSG_OOB = 16_1; (* process out-of-band data *)
+ MSG_PEEK = 16_2; (* peek at incoming message *)
+ MSG_DONTROUTE = 16_4; (* send without using routing tables *)
+ MSG_EOR = 16_8; (* data completes record *)
+ MSG_TRUNC = 16_10; (* data discarded before delivery *)
+ MSG_CTRUNC = 16_20; (* control data lost before delivery *)
+ MSG_WAITALL = 16_40; (* wait for full request or error *)
+ MSG_DONTWAIT = 16_80; (* this message should be nonblocking *)
+ MSG_EOF = 16_100; (* data completes connection *)
+ MSG_COMPAT = 16_8000; (* used in sendit() *)
+
+(*
+ * Header for ancillary data objects in msg_control buffer.
+ * Used for additional information with/about a datagram
+ * not expressible by flags. The format is a sequence
+ * of message elements headed by cmsghdr structures.
+ *)
+TYPE
+ struct_cmsghdr = RECORD
+ cmsg_len: Ctypes.unsigned_int; (* data byte count, including hdr *)
+ cmsg_level: Ctypes.int; (* originating protocol *)
+ cmsg_type: Ctypes.int; (* protocol-specific type *)
+ (* followed by u_char cmsg_data[]; *)
+ END;
- MSG_MAXIOVLEN = 16;
-***)
+(* "Socket"-level control message types: *)
+CONST
+ SCM_RIGHTS = 16_01; (* access rights (array of int) *)
+ SCM_TIMESTAMP = 16_02; (* timestamp (struct timeval) *)
(*
* Definitions for UNIX IPC domain.
*)
TYPE
struct_sockaddr_un = RECORD
- sun_family: Ctypes.unsigned_short; (* AF_UNIX *)
- sun_path: ARRAY [0..107] OF Ctypes.char; (* path name (gag) *)
+ sun_len: Ctypes.unsigned_char; (* sockaddr len including null *)
+ sun_family: Ctypes.unsigned_char; (* AF_UNIX *)
+ sun_path: ARRAY [0..103] OF Ctypes.char; (* path name (gag) *)
END;
-<*EXTERNAL*>
+<*EXTERNAL "m3_accept"*>
PROCEDURE accept(
s: Ctypes.int;
addr: UNTRACED REF struct_sockaddr;
@@ -202,7 +236,7 @@
: Ctypes.int
RAISES {};
-<*EXTERNAL*>
+<*EXTERNAL "m3_bind"*>
PROCEDURE bind(
s: Ctypes.int;
name: UNTRACED REF struct_sockaddr;
@@ -210,7 +244,7 @@
: Ctypes.int
RAISES {};
-<*EXTERNAL*>
+<*EXTERNAL "m3_connect"*>
PROCEDURE connect(
s: Ctypes.int;
name: UNTRACED REF struct_sockaddr;
@@ -218,7 +252,7 @@
: Ctypes.int
RAISES {};
-<*EXTERNAL*>
+<*EXTERNAL "m3_getpeername"*>
PROCEDURE getpeername(
s: Ctypes.int;
name: UNTRACED REF struct_sockaddr;
@@ -226,7 +260,7 @@
: Ctypes.int
RAISES {};
-<*EXTERNAL*>
+<*EXTERNAL "m3_getsockname"*>
PROCEDURE getsockname(
s: Ctypes.int;
name: UNTRACED REF struct_sockaddr;
@@ -237,52 +271,70 @@
<*EXTERNAL*>
PROCEDURE getsockopt(
s, level, optname: Ctypes.int;
- optval: Ctypes.char_star;
+ optval: Ctypes.void_star;
optlen: Ctypes.int_star)
: Ctypes.int
RAISES {};
-<*EXTERNAL*>
+<*EXTERNAL "m3_listen"*>
PROCEDURE listen(s, backlog: Ctypes.int): Ctypes.int RAISES {};
-<*EXTERNAL*>
-PROCEDURE recv(s: Ctypes.int; buf: Ctypes.char_star; len, flags: Ctypes.int): Ctypes.int RAISES {};
+<*EXTERNAL "m3_recv"*>
+PROCEDURE recv(
+ s: Ctypes.int;
+ buf: Ctypes.void_star;
+ len: Utypes.size_t;
+ flags: Ctypes.int)
+ : Ctypes.int
+ RAISES {};
-<*EXTERNAL*>
+<*EXTERNAL "m3_recvfrom"*>
PROCEDURE recvfrom(
s: Ctypes.int;
- buf: Ctypes.char_star;
- len, flags: Ctypes.int;
+ buf: Ctypes.void_star;
+ len: Utypes.size_t;
+ flags: Ctypes.int;
from: UNTRACED REF struct_sockaddr;
fromlen: Ctypes.int_star)
: Ctypes.int
RAISES {};
-<*EXTERNAL*>
-PROCEDURE send(s: Ctypes.int; msg: Ctypes.char_star; len, flags: Ctypes.int): Ctypes.int RAISES {};
+(* FIXME - recvmsg *)
-<*EXTERNAL*>
+<*EXTERNAL "m3_send"*>
+PROCEDURE send(
+ s: Ctypes.int;
+ msg: Ctypes.const_void_star;
+ len: Utypes.size_t;
+ flags: Ctypes.int)
+ : Ctypes.int
+ RAISES {};
+
+<*EXTERNAL "m3_sendto"*>
PROCEDURE sendto(
s: Ctypes.int;
- msg: Ctypes.char_star;
- len, flags: Ctypes.int;
+ msg: Ctypes.const_void_star;
+ len: Utypes.size_t;
+ flags: Ctypes.int;
to: UNTRACED REF struct_sockaddr;
tolen: Ctypes.int)
: Ctypes.int
RAISES {};
+(* FIXME - sendmsg *)
+
<*EXTERNAL*>
PROCEDURE setsockopt(
s, level, optname: Ctypes.int;
- optval: Ctypes.char_star;
+ optval: Ctypes.const_void_star;
optlen: Ctypes.int)
: Ctypes.int
RAISES {};
-<*EXTERNAL*>
+<*EXTERNAL "m3_shutdown"*>
PROCEDURE shutdown(s, how: Ctypes.int): Ctypes.int RAISES {};
-<*EXTERNAL*>
+<*EXTERNAL "m3_socket" *>
PROCEDURE socket(af, type, protocol: Ctypes.int): Ctypes.int RAISES {};
<*EXTERNAL*>
|