3 ;;; This isn't really lisp, but it's definitely a source file. we
4 ;;; name it thus to avoid having to mess with the clc lpn translations
6 ;;; first, the headers necessary to find definitions of everything
7 ("sys/types.h" "sys/socket.h" "sys/stat.h" "unistd.h" "sys/un.h"
8 "netinet/in.h" "netinet/in_systm.h" "netinet/ip.h" "net/if.h"
9 "arpa/inet.h" ; inet_{ntop,pton}
10 "netdb.h" "errno.h" "netinet/tcp.h" "fcntl.h" )
12 ;;; then the stuff we're looking for
13 ((:integer af-inet
"AF_INET" "IP Protocol family")
14 (:integer af-unspec
"AF_UNSPEC" "Unspecified")
16 #+(or sunos solaris hpux
) "AF_UNIX"
17 #-
(or sunos solaris hpux
) "AF_LOCAL"
18 "Local to host (pipes and file-domain).")
19 (:integer af-inet6
"AF_INET6" "IP version 6")
20 #+linux
(:integer af-route
"AF_NETLINK" "Alias to emulate 4.4BSD ")
22 (:integer sock-stream
"SOCK_STREAM"
23 "Sequenced, reliable, connection-based byte streams.")
24 (:integer sock-dgram
"SOCK_DGRAM"
25 "Connectionless, unreliable datagrams of fixed maximum length.")
26 (:integer sock-raw
"SOCK_RAW"
27 "Raw protocol interface.")
28 (:integer sock-rdm
"SOCK_RDM"
29 "Reliably-delivered messages.")
30 (:integer sock-seqpacket
"SOCK_SEQPACKET"
31 "Sequenced, reliable, connection-based, datagrams of fixed maximum length.")
33 (:integer sol-socket
"SOL_SOCKET")
35 ;; some of these may be linux-specific
36 (:integer so-debug
"SO_DEBUG"
37 "Enable debugging in underlying protocol modules")
38 (:integer so-reuseaddr
"SO_REUSEADDR" "Enable local address reuse")
39 (:integer so-type
"SO_TYPE") ;get only
40 (:integer so-error
"SO_ERROR") ;get only (also clears)
41 (:integer so-dontroute
"SO_DONTROUTE"
42 "Bypass routing facilities: instead send direct to appropriate network interface for the network portion of the destination address")
43 (:integer so-broadcast
"SO_BROADCAST" "Request permission to send broadcast datagrams")
44 (:integer so-sndbuf
"SO_SNDBUF")
45 #+linux
(:integer so-passcred
"SO_PASSCRED")
46 (:integer so-rcvbuf
"SO_RCVBUF")
47 (:integer so-keepalive
"SO_KEEPALIVE"
48 "Send periodic keepalives. If peer does not respond, we get SIGPIPE.")
49 #+linux
(:integer tcp-keepcnt
"TCP_KEEPCNT"
50 "Number of unacknowledged probes before the connection is considered dead.")
51 #+linux
(:integer tcp-keepidle
"TCP_KEEPIDLE"
52 "Seconds between the last data packet sent and the first keepalive probe.")
53 #+linux
(:integer tcp-keepintvl
"TCP_KEEPINTVL" "Seconds between keepalive probes.")
54 (:integer so-oobinline
"SO_OOBINLINE"
55 "Put out-of-band data into the normal input queue when received")
57 (:integer so-no-check
"SO_NO_CHECK")
58 #+linux
(:integer so-priority
"SO_PRIORITY")
59 (:integer so-linger
"SO_LINGER"
60 "For reliable streams, pause a while on closing when unsent messages are queued")
61 #+linux
(:integer so-bsdcompat
"SO_BSDCOMPAT")
62 (:integer so-sndlowat
"SO_SNDLOWAT")
63 (:integer so-rcvlowat
"SO_RCVLOWAT")
64 (:integer so-sndtimeo
"SO_SNDTIMEO")
65 (:integer so-rcvtimeo
"SO_RCVTIMEO")
67 (:integer tcp-nodelay
"TCP_NODELAY")
68 #+linux
(:integer so-bindtodevice
"SO_BINDTODEVICE")
69 (:integer ifnamsiz
"IFNAMSIZ")
71 ;; socket shutdown flags
72 (:integer SHUT_RD
"SHUT_RD")
73 (:integer SHUT_WR
"SHUT_WR")
74 (:integer SHUT_RDWR
"SHUT_RDWR")
77 (:integer EADDRINUSE
"EADDRINUSE")
78 (:integer EAGAIN
"EAGAIN")
79 (:integer EBADF
"EBADF")
80 (:integer ECONNREFUSED
"ECONNREFUSED")
81 (:integer ETIMEDOUT
"ETIMEDOUT")
82 (:integer EINTR
"EINTR")
83 (:integer EINVAL
"EINVAL")
84 (:integer ENOBUFS
"ENOBUFS")
85 (:integer ENOMEM
"ENOMEM")
86 (:integer EOPNOTSUPP
"EOPNOTSUPP")
87 (:integer EPERM
"EPERM")
88 (:integer EPROTONOSUPPORT
"EPROTONOSUPPORT")
89 (:integer ERANGE
"ERANGE")
90 (:integer ESOCKTNOSUPPORT
"ESOCKTNOSUPPORT")
91 (:integer ENETUNREACH
"ENETUNREACH")
92 (:integer ENOTCONN
"ENOTCONN")
93 (:integer EAFNOSUPPORT
"EAFNOSUPPORT")
94 (:integer EINPROGRESS
"EINPROGRESS")
96 (:integer NETDB-INTERNAL
#+hpux
"h_NETDB_INTERNAL" #-hpux
"NETDB_INTERNAL" "See errno.")
97 (:integer NETDB-SUCCESS
#+hpux
"h_NETDB_SUCCESS" #-hpux
"NETDB_SUCCESS" "No problem.")
98 (:integer HOST-NOT-FOUND
"HOST_NOT_FOUND" "Authoritative Answer Host not found.")
99 (:integer TRY-AGAIN
"TRY_AGAIN" "Non-Authoritative Host not found, or SERVERFAIL.")
100 (:integer NO-RECOVERY
"NO_RECOVERY" "Non recoverable errors, FORMERR, REFUSED, NOTIMP.")
101 (:integer NO-DATA
"NO_DATA" "Valid name, no data record of requested type.")
102 (:integer NO-ADDRESS
"NO_ADDRESS" "No address, look for MX record.")
103 #-
(or hpux sunos
) (:function h-strerror
("hstrerror" c-string
(errno int
)))
105 (:integer O-NONBLOCK
"O_NONBLOCK")
106 (:integer f-getfl
"F_GETFL")
107 (:integer f-setfl
"F_SETFL")
109 (:integer msg-oob
"MSG_OOB")
110 (:integer msg-peek
"MSG_PEEK")
111 (:integer msg-trunc
"MSG_TRUNC")
112 (:integer msg-waitall
"MSG_WAITALL")
113 (:integer msg-eor
"MSG_EOR")
114 (:integer msg-dontroute
"MSG_DONTROUTE")
115 (:integer msg-dontwait
"MSG_DONTWAIT")
116 #+linux
(:integer msg-nosignal
"MSG_NOSIGNAL")
117 #+linux
(:integer msg-confirm
"MSG_CONFIRM")
118 #+linux
(:integer msg-more
"MSG_MORE")
120 ;; for socket-receive
121 (:type socklen-t
"socklen_t")
122 (:type size-t
"size_t")
123 (:type ssize-t
"ssize_t")
126 ;;; stat is nothing to do with sockets, but I keep it around for testing
128 (:structure stat
("struct stat"
129 (t dev
"dev_t" "st_dev")
130 ((alien:integer
32) atime
"time_t" "st_atime")))
131 (:function stat
("stat" (integer 32)
135 (:structure protoent
("struct protoent"
136 (c-string-pointer name
"char *" "p_name")
137 ((* (* t
)) aliases
"char **" "p_aliases")
138 (integer proto
"int" "p_proto")))
139 (:function getprotobyname
("getprotobyname" (* protoent
)
142 ;; getprotobyname_r is a thread-safe reentrant version of getprotobyname
143 #+os-provides-getprotoby-r
144 (:function getprotobyname-r
("getprotobyname_r" int
146 (result_buf (* protoent
))
150 (result (* (* protoent
)))))
153 (:function getprotobynumber
("getprotobynumber" (* protoent
)
155 ;;ditto, save for the getprotobynumber part
156 #+os-provides-getprotoby-r
157 (:function getprotobynumber-r
("getprotobynumber_r" int
159 (result_buf (* protoent
))
163 (result (* (* protoent
)))))
165 (:integer inaddr-any
"INADDR_ANY")
166 (:structure in-addr
("struct in_addr"
167 ((array (unsigned 8)) addr
"u_int32_t" "s_addr")))
168 (:structure sockaddr-in
("struct sockaddr_in"
169 #+darwin
((unsigned 8) len
"__uint8_t" "sin_len")
170 (integer family
"sa_family_t" "sin_family")
171 ;; These two could be in-port-t and
172 ;; in-addr-t, but then we'd throw away the
173 ;; convenience (and byte-order agnosticism)
174 ;; of the old sb-grovel scheme.
175 ((array (unsigned 8)) port
"u_int16_t" "sin_port")
176 ((array (unsigned 8)) addr
"struct in_addr" "sin_addr")))
177 (:structure in6-addr
("struct in6_addr"
178 ((array (unsigned 8)) addr
"unsigned char" "s6_addr[16]")))
179 (:structure sockaddr-in6
("struct sockaddr_in6"
180 #+darwin
((unsigned 8) len
"__uint8_t" "sin6_len")
181 (integer family
"sa_family_t" "sin6_family")
182 ;; Like in IN-ADDR, port and addr could be
183 ;; in-port-t and in6-addr-t, but then we'd
184 ;; throw away the convenience (and
185 ;; byte-order agnosticism) of the old
187 ((array (unsigned 8)) port
"u_int16_t" "sin6_port")
188 ((array (unsigned 8)) flowinfo
"u_int32_t" "sin6_flowinfo")
189 ((array (unsigned 8)) addr
"struct in_addr6" "sin6_addr")
190 ((array (unsigned 8)) scope-id
"u_int32_t" "sin6_scope_id")))
191 (:structure sockaddr-un
("struct sockaddr_un"
192 (integer family
"sa_family_t" "sun_family")
193 (c-string path
"char" "sun_path")))
194 (:structure sockaddr-un-abstract
("struct sockaddr_un"
195 (integer family
"sa_family_t" "sun_family")
196 ((array (unsigned 8)) path
"char" "sun_path")))
197 (:integer INET-ADDRSTRLEN
"INET_ADDRSTRLEN")
198 (:integer INET6-ADDRSTRLEN
"INET6_ADDRSTRLEN")
199 (:function inet-ntop
("inet_ntop" c-string
; TODO external-format?
203 ;; size is of type socklen_t in
204 ;; recent Glibc's, butlast size-t
205 ;; seems to be the more portable
208 (:function inet-pton
("inet_pton" int
210 (src c-string
) ; TODO external-format?
212 (:structure hostent
("struct hostent"
213 (c-string-pointer name
"char *" "h_name")
214 ((* c-string
) aliases
"char **" "h_aliases")
215 (integer type
"int" "h_addrtype")
216 (integer length
"int" "h_length")
217 ((* (* (unsigned 8))) addresses
"char **" "h_addr_list")))
218 (:structure msghdr
("struct msghdr"
219 (c-string-pointer name
"void *" "msg_name")
220 (integer namelen
"socklen_t" "msg_namelen")
221 ((* t
) iov
"struct iovec" "msg_iov")
222 (integer iovlen
"size_t" "msg_iovlen")
223 ((* t
) control
"void *" "msg_control")
224 (integer controllen
"socklen_t" "msg_controllen")
225 (integer flags
"int" "msg_flags")))
226 (:function socket
(#-netbsd
"socket" #+netbsd
"_socket" int
230 (:function bind
("bind" int
232 (my-addr (* t
)) ; KLUDGE: sockaddr-in or sockaddr-un?
233 (addrlen socklen-t
)))
234 (:function listen
("listen" int
237 (:function accept
("accept" int
239 (my-addr (* t
)) ; KLUDGE: sockaddr-in or sockaddr-un?
240 (addrlen socklen-t
:in-out
)))
241 (:function getpeername
("getpeername" int
243 (her-addr (* t
)) ; KLUDGE: sockaddr-in or sockaddr-un?
244 (addrlen socklen-t
:in-out
)))
245 (:function getsockname
("getsockname" int
247 (my-addr (* t
)) ; KLUDGE: sockaddr-in or sockaddr-un?
248 (addrlen socklen-t
:in-out
)))
249 (:function connect
("connect" int
251 (his-addr (* t
)) ; KLUDGE: sockaddr-in or sockaddr-un?
252 (addrlen socklen-t
)))
253 (:function close
("close" int
255 (:function shutdown
("shutdown" int
257 (:function recvfrom
("recvfrom" ssize-t
262 (sockaddr (* t
)) ; KLUDGE: sockaddr-in or sockaddr-un?
263 (socklen (* socklen-t
))))
264 (:function recvmsg
("recvmsg" ssize-t
268 (:function send
("send" ssize-t
273 (:function sendto
("sendto" int
278 (sockaddr (* t
)) ; KLUDGE: sockaddr-in or sockaddr-un?
279 (socklen socklen-t
)))
280 (:function sendmsg
("sendmsg" int
284 (:function gethostbyname
("gethostbyname" (* hostent
) (name c-string
)))
286 (:function gethostbyname2
("gethostbyname2" (* hostent
)
289 (:function gethostbyaddr
("gethostbyaddr" (* hostent
)
294 ;; Re-entrant gethostbyname
297 (:function gethostbyname-r
("gethostbyname_r"
303 (result (* (* hostent
)))
305 ;; getaddrinfo / getnameinfo
307 #+sb-bsd-sockets-addrinfo
308 (:structure addrinfo
("struct addrinfo"
309 (integer flags
"int" "ai_flags")
310 (integer family
"int" "ai_family")
311 (integer socktype
"int" "ai_socktype")
312 (integer protocol
"int" "ai_protocol")
313 ;; CLH 20070306 FIXME: ai_addrlen should really
314 ;; be a socklen_t, but I'm not sure if this the
315 ;; case on other platforms. I'm setting this to
316 ;; socklen_t on darwin and hoping that other
317 ;; platform maintainers will do the right thing
319 #+darwin
(integer addrlen
"socklen_t" "ai_addrlen")
320 #-darwin
(integer addrlen
"size_t" "ai_addrlen")
321 ;; This can be a void pointer since it has to
322 ;; be cast to the respectively appropriate
323 ;; address structure anyway.
324 ((* t
) addr
"struct sockaddr*" "ai_addr")
325 (c-string-pointer canonname
"char *" "ai_canonname")
326 ((* (struct addrinfo
)) next
"struct addrinfo*" "ai_next")))
328 #+sb-bsd-sockets-addrinfo
329 (:function getaddrinfo
("getaddrinfo"
334 (res (* (* addrinfo
)))))
336 #+sb-bsd-sockets-addrinfo
337 (:function freeaddrinfo
("freeaddrinfo"
341 #+sb-bsd-sockets-addrinfo
342 (:function gai-strerror
("gai_strerror"
346 #+sb-bsd-sockets-addrinfo
347 (:function getnameinfo
("getnameinfo"
349 ;; This can be a void pointer since it has to
350 ;; be cast to the respectively appropriate
351 ;; address structure anyway.
353 (address-length size-t
)
360 (:integer EAI-FAMILY
"EAI_FAMILY")
361 (:integer EAI-SOCKTYPE
"EAI_SOCKTYPE")
362 (:integer EAI-BADFLAGS
"EAI_BADFLAGS")
363 (:integer EAI-NONAME
"EAI_NONAME")
364 (:integer EAI-SERVICE
"EAI_SERVICE")
365 #-
(or freebsd dragonfly
)
366 (:integer EAI-ADDRFAMILY
"EAI_ADDRFAMILY")
367 (:integer EAI-MEMORY
"EAI_MEMORY")
368 (:integer EAI-FAIL
"EAI_FAIL")
369 (:integer EAI-AGAIN
"EAI_AGAIN")
370 (:integer EAI-SYSTEM
"EAI_SYSTEM")
372 (:integer NI-NAMEREQD
"NI_NAMEREQD")
376 (:function setsockopt
("setsockopt" int
381 (optlen int
))) ;;; should be socklen-t!
382 (:function fcntl
("fcntl" int
386 (:function getsockopt
("getsockopt" int
391 (optlen (* int
)))) ;;; should be socklen-t!
393 ;; Android have those as enums, foiling #ifdef checks
394 (#-android
:integer
#+android
:integer-no-check IPPROTO_IP
"IPPROTO_IP")
395 (#-android
:integer
#+android
:integer-no-check IPPROTO_IPV6
"IPPROTO_IPV6")
396 (#-android
:integer
#+android
:integer-no-check IPPROTO_ICMP
"IPPROTO_ICMP")
397 (#-android
:integer
#+android
:integer-no-check IPPROTO_IGMP
"IPPROTO_IGMP")
398 (#-android
:integer
#+android
:integer-no-check IPPROTO_TCP
"IPPROTO_TCP")
399 (#-android
:integer
#+android
:integer-no-check IPPROTO_UDP
"IPPROTO_UDP")
400 (#-android
:integer
#+android
:integer-no-check IPPROTO_RAW
"IPPROTO_RAW"))