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")
124 ;;; stat is nothing to do with sockets, but I keep it around for testing
126 (:structure stat
("struct stat"
127 (t dev
"dev_t" "st_dev")
128 ((alien:integer
32) atime
"time_t" "st_atime")))
129 (:function stat
("stat" (integer 32)
133 (:structure protoent
("struct protoent"
134 (c-string-pointer name
"char *" "p_name")
135 ((* (* t
)) aliases
"char **" "p_aliases")
136 (integer proto
"int" "p_proto")))
137 (:function getprotobyname
("getprotobyname" (* protoent
)
140 ;; getprotobyname_r is a thread-safe reentrant version of getprotobyname
141 #+os-provides-getprotoby-r
142 (:function getprotobyname-r
("getprotobyname_r" int
144 (result_buf (* protoent
))
148 (result (* (* protoent
)))))
151 (:function getprotobynumber
("getprotobynumber" (* protoent
)
153 ;;ditto, save for the getprotobynumber part
154 #+os-provides-getprotoby-r
155 (:function getprotobynumber-r
("getprotobynumber_r" int
157 (result_buf (* protoent
))
161 (result (* (* protoent
)))))
163 (:integer inaddr-any
"INADDR_ANY")
164 (:structure in-addr
("struct in_addr"
165 ((array (unsigned 8)) addr
"u_int32_t" "s_addr")))
166 (:structure sockaddr-in
("struct sockaddr_in"
167 #+darwin
((unsigned 8) len
"__uint8_t" "sin_len")
168 (integer family
"sa_family_t" "sin_family")
169 ;; These two could be in-port-t and
170 ;; in-addr-t, but then we'd throw away the
171 ;; convenience (and byte-order agnosticism)
172 ;; of the old sb-grovel scheme.
173 ((array (unsigned 8)) port
"u_int16_t" "sin_port")
174 ((array (unsigned 8)) addr
"struct in_addr" "sin_addr")))
175 (:structure in6-addr
("struct in6_addr"
176 ((array (unsigned 8)) addr
"unsigned char" "s6_addr[16]")))
177 (:structure sockaddr-in6
("struct sockaddr_in6"
178 #+darwin
((unsigned 8) len
"__uint8_t" "sin6_len")
179 (integer family
"sa_family_t" "sin6_family")
180 ;; Like in IN-ADDR, port and addr could be
181 ;; in-port-t and in6-addr-t, but then we'd
182 ;; throw away the convenience (and
183 ;; byte-order agnosticism) of the old
185 ((array (unsigned 8)) port
"u_int16_t" "sin6_port")
186 ((array (unsigned 8)) flowinfo
"u_int32_t" "sin6_flowinfo")
187 ((array (unsigned 8)) addr
"struct in_addr6" "sin6_addr")
188 ((array (unsigned 8)) scope-id
"u_int32_t" "sin6_scope_id")))
189 (:structure sockaddr-un
("struct sockaddr_un"
190 (integer family
"sa_family_t" "sun_family")
191 (c-string path
"char" "sun_path")))
192 (:structure sockaddr-un-abstract
("struct sockaddr_un"
193 (integer family
"sa_family_t" "sun_family")
194 ((array (unsigned 8)) path
"char" "sun_path")))
195 (:integer INET-ADDRSTRLEN
"INET_ADDRSTRLEN")
196 (:integer INET6-ADDRSTRLEN
"INET6_ADDRSTRLEN")
197 (:function inet-ntop
("inet_ntop" c-string
; TODO external-format?
201 ;; size is of type socklen_t in
202 ;; recent Glibc's, butlast size-t
203 ;; seems to be the more portable
206 (:function inet-pton
("inet_pton" int
208 (src c-string
) ; TODO external-format?
210 (:structure hostent
("struct hostent"
211 (c-string-pointer name
"char *" "h_name")
212 ((* c-string
) aliases
"char **" "h_aliases")
213 (integer type
"int" "h_addrtype")
214 (integer length
"int" "h_length")
215 ((* (* (unsigned 8))) addresses
"char **" "h_addr_list")))
216 (:structure msghdr
("struct msghdr"
217 (c-string-pointer name
"void *" "msg_name")
218 (integer namelen
"socklen_t" "msg_namelen")
219 ((* t
) iov
"struct iovec" "msg_iov")
220 (integer iovlen
"size_t" "msg_iovlen")
221 ((* t
) control
"void *" "msg_control")
222 (integer controllen
"socklen_t" "msg_controllen")
223 (integer flags
"int" "msg_flags")))
224 (:function socket
(#-netbsd
"socket" #+netbsd
"_socket" int
228 (:function bind
("bind" int
230 (my-addr (* t
)) ; KLUDGE: sockaddr-in or sockaddr-un?
231 (addrlen socklen-t
)))
232 (:function listen
("listen" int
235 (:function accept
("accept" int
237 (my-addr (* t
)) ; KLUDGE: sockaddr-in or sockaddr-un?
238 (addrlen socklen-t
:in-out
)))
239 (:function getpeername
("getpeername" int
241 (her-addr (* t
)) ; KLUDGE: sockaddr-in or sockaddr-un?
242 (addrlen socklen-t
:in-out
)))
243 (:function getsockname
("getsockname" int
245 (my-addr (* t
)) ; KLUDGE: sockaddr-in or sockaddr-un?
246 (addrlen socklen-t
:in-out
)))
247 (:function connect
("connect" int
249 (his-addr (* t
)) ; KLUDGE: sockaddr-in or sockaddr-un?
250 (addrlen socklen-t
)))
251 (:function close
("close" int
253 (:function shutdown
("shutdown" int
255 (:function recvfrom
("recvfrom" ssize-t
260 (sockaddr (* t
)) ; KLUDGE: sockaddr-in or sockaddr-un?
261 (socklen (* socklen-t
))))
262 (:function recvmsg
("recvmsg" ssize-t
266 (:function send
("send" ssize-t
271 (:function sendto
("sendto" int
276 (sockaddr (* t
)) ; KLUDGE: sockaddr-in or sockaddr-un?
277 (socklen socklen-t
)))
278 (:function sendmsg
("sendmsg" int
282 (:function gethostbyname
("gethostbyname" (* hostent
) (name c-string
)))
284 (:function gethostbyname2
("gethostbyname2" (* hostent
)
287 (:function gethostbyaddr
("gethostbyaddr" (* hostent
)
292 ;; Re-entrant gethostbyname
295 (:function gethostbyname-r
("gethostbyname_r"
301 (result (* (* hostent
)))
303 ;; getaddrinfo / getnameinfo
305 #+sb-bsd-sockets-addrinfo
306 (:structure addrinfo
("struct addrinfo"
307 (integer flags
"int" "ai_flags")
308 (integer family
"int" "ai_family")
309 (integer socktype
"int" "ai_socktype")
310 (integer protocol
"int" "ai_protocol")
311 ;; CLH 20070306 FIXME: ai_addrlen should really
312 ;; be a socklen_t, but I'm not sure if this the
313 ;; case on other platforms. I'm setting this to
314 ;; socklen_t on darwin and hoping that other
315 ;; platform maintainers will do the right thing
317 #+darwin
(integer addrlen
"socklen_t" "ai_addrlen")
318 #-darwin
(integer addrlen
"size_t" "ai_addrlen")
319 ;; This can be a void pointer since it has to
320 ;; be cast to the respectively appropriate
321 ;; address structure anyway.
322 ((* t
) addr
"struct sockaddr*" "ai_addr")
323 (c-string-pointer canonname
"char *" "ai_canonname")
324 ((* (struct addrinfo
)) next
"struct addrinfo*" "ai_next")))
326 #+sb-bsd-sockets-addrinfo
327 (:function getaddrinfo
("getaddrinfo"
332 (res (* (* addrinfo
)))))
334 #+sb-bsd-sockets-addrinfo
335 (:function freeaddrinfo
("freeaddrinfo"
339 #+sb-bsd-sockets-addrinfo
340 (:function gai-strerror
("gai_strerror"
344 #+sb-bsd-sockets-addrinfo
345 (:function getnameinfo
("getnameinfo"
347 ;; This can be a void pointer since it has to
348 ;; be cast to the respectively appropriate
349 ;; address structure anyway.
351 (address-length size-t
)
358 (:integer EAI-FAMILY
"EAI_FAMILY")
359 (:integer EAI-SOCKTYPE
"EAI_SOCKTYPE")
360 (:integer EAI-BADFLAGS
"EAI_BADFLAGS")
361 (:integer EAI-NONAME
"EAI_NONAME")
362 (:integer EAI-SERVICE
"EAI_SERVICE")
363 #-
(or freebsd dragonfly
)
364 (:integer EAI-ADDRFAMILY
"EAI_ADDRFAMILY")
365 (:integer EAI-MEMORY
"EAI_MEMORY")
366 (:integer EAI-FAIL
"EAI_FAIL")
367 (:integer EAI-AGAIN
"EAI_AGAIN")
368 (:integer EAI-SYSTEM
"EAI_SYSTEM")
370 (:integer NI-NAMEREQD
"NI_NAMEREQD")
374 (:function setsockopt
("setsockopt" int
379 (optlen int
))) ;;; should be socklen-t!
380 (:function fcntl
("fcntl" int
384 (:function getsockopt
("getsockopt" int
389 (optlen (* int
)))) ;;; should be socklen-t!
391 ;; Android have those as enums, foiling #ifdef checks
392 (#-android
:integer
#+android
:integer-no-check IPPROTO_IP
"IPPROTO_IP")
393 (#-android
:integer
#+android
:integer-no-check IPPROTO_IPV6
"IPPROTO_IPV6")
394 (#-android
:integer
#+android
:integer-no-check IPPROTO_ICMP
"IPPROTO_ICMP")
395 (#-android
:integer
#+android
:integer-no-check IPPROTO_IGMP
"IPPROTO_IGMP")
396 (#-android
:integer
#+android
:integer-no-check IPPROTO_TCP
"IPPROTO_TCP")
397 (#-android
:integer
#+android
:integer-no-check IPPROTO_UDP
"IPPROTO_UDP")
398 (#-android
:integer
#+android
:integer-no-check IPPROTO_RAW
"IPPROTO_RAW"))