Fix many incorrect things in the Usocket interface for FreeBSD. Also make provisions for using SOCKS. Index: m3/m3core/src/unix/freebsd-2/Usocket.i3 --- Usocket.i3.orig Sat Jan 7 14:22:22 1995 +++ 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*>