1 ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
3 ;;; grovel.lisp --- Grovelling for socket constants and types.
5 ;;; Copyright (C) 2005-2006, Matthew Backes <lucca@accela.net>
6 ;;; Copyright (C) 2005-2006, Dan Knapp <dankna@accela.net>
7 ;;; Copyright (C) 2007, Stelian Ionescu <stelian.ionescu-zeus@poste.it>
8 ;;; Copyright (C) 2007, Luis Oliveira <loliveira@common-lisp.net>
10 ;;; Permission is hereby granted, free of charge, to any person
11 ;;; obtaining a copy of this software and associated documentation
12 ;;; files (the "Software"), to deal in the Software without
13 ;;; restriction, including without limitation the rights to use, copy,
14 ;;; modify, merge, publish, distribute, sublicense, and/or sell copies
15 ;;; of the Software, and to permit persons to whom the Software is
16 ;;; furnished to do so, subject to the following conditions:
18 ;;; The above copyright notice and this permission notice shall be
19 ;;; included in all copies or substantial portions of the Software.
21 ;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 ;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 ;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 ;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 ;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 ;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 ;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 ;;; DEALINGS IN THE SOFTWARE.
31 (include "sys/socket.h" "sys/un.h" "netinet/in.h" "netinet/in_systm.h"
32 "netinet/ip.h" "net/if.h" "netinet/tcp.h" "netdb.h" "errno.h"
36 (include "Winsock2.h" "Ws2tcpip.h")
38 (in-package #:bsd-sockets
)
40 ;;; TODO: check if I didn't miss any from CL-POSIX. --luis
41 (constantenum socket-error-values
42 ((:enotsock
"ENOTSOCK"))
43 ((:edestaddrreq
"EDESTADDRREQ"))
44 ((:emsgsize
"EMSGSIZE"))
45 ((:eprototype
"EPROTOTYPE"))
46 ((:enoprotoopt
"ENOPROTOOPT"))
47 ((:eremote
"EREMOTE"))
48 ((:enolink
"ENOLINK"))
49 ((:epfnosupport
"EPFNOSUPPORT"))
50 ((:eafnosupport
"EAFNOSUPPORT"))
51 ((:eaddrinuse
"EADDRINUSE"))
52 ((:eaddrnotavail
"EADDRNOTAVAIL"))
53 ((:enetdown
"ENETDOWN"))
54 ((:enetunreach
"ENETUNREACH"))
55 ((:enetreset
"ENETRESET"))
56 ((:econnaborted
"ECONNABORTED"))
57 ((:econnreset
"ECONNRESET"))
58 ((:eisconn
"EISCONN"))
59 ((:enotconn
"ENOTCONN"))
60 ((:eshutdown
"ESHUTDOWN"))
61 ((:etoomanyrefs
"ETOOMANYREFS"))
62 ((:etimedout
"ETIMEDOUT"))
63 ((:econnrefused
"ECONNREFUSED"))
64 ((:ehostdown
"EHOSTDOWN"))
65 ((:ehostunreach
"EHOSTUNREACH"))
66 ((:enonet
"ENONET") :optional t
)
67 ((:enobufs
"ENOBUFS"))
68 ((:eopnotsupp
"EOPNOTSUPP")))
72 (ctype socklen
"socklen_t")
73 (ctype sa-family
"sa_family_t")
75 ;;; socket() - socket address family
76 (constant (af-unspec "AF_UNSPEC" "PF_UNSPEC"))
77 (constant (af-inet "AF_INET" "PF_INET") :documentation
"IPv4 Protocol family")
78 (constant (af-inet6 "AF_INET6" "PF_INET6")
79 :documentation
"IPv6 Protocol family")
80 (constant (af-local "AF_UNIX" "AF_LOCAL" "PF_UNIX" "PF_LOCAL")
81 :documentation
"File domain sockets")
82 (constant (af-packet "AF_PACKET" "PF_PACKET") :documentation
"Raw packet access"
84 (constant (af-route "AF_ROUTE" "PF_ROUTE")
85 :documentation
"Routing sockets" :optional t
)
86 (constant (af-key "AF_KEY" "PF_KEY"))
87 (constant (af-netlink "AF_NETLINK" "PF_NETLINK")
88 :documentation
"Linux Netlink sockets" :optional t
)
90 ;;; socket() - socket type
91 (constant (sock-stream "SOCK_STREAM") :documentation
"TCP")
92 (constant (sock-dgram "SOCK_DGRAM") :documentation
"UDP")
93 (constant (sock-seqpacket "SOCK_SEQPACKET")
94 :documentation
"Reliable Sequenced Datagram Protocol" :optional t
)
95 (constant (sock-raw "SOCK_RAW") :documentation
"Raw protocol access"
97 (constant (sock-rdm "SOCK_RDM")
98 :documentation
"Reliable Unordered Datagram Protocol" :optional t
)
100 ;;; socket() - socket protocol
101 (constant (ipproto-ip "IPPROTO_IP"))
102 (constant (ipproto-ipv6 "IPPROTO_IPV6"))
103 (constant (ipproto-icmp "IPPROTO_ICMP"))
104 (constant (ipproto-icmpv6 "IPPROTO_ICMPV6"))
105 (constant (ipproto-raw "IPPROTO_RAW"))
106 (constant (ipproto-tcp "IPPROTO_TCP"))
107 (constant (ipproto-udp "IPPROTO_UDP"))
108 #-darwin
(constant (ipproto-sctp "IPPROTO_SCTP"))
110 (cstruct sockaddr
"struct sockaddr"
111 (family "sa_family" :type sa-family
))
113 (cstruct sockaddr-storage
"struct sockaddr_storage"
114 (family "ss_family" :type sa-family
))
116 (cstruct hostent
"struct hostent"
117 (name "h_name" :type
:string
)
118 (aliases "h_aliases" :type
:pointer
)
119 (type "h_addrtype" :type
:int
)
120 (length "h_length" :type
:int
)
121 (addresses "h_addr_list" :type
:pointer
))
123 (cstruct servent
"struct servent"
124 (name "s_name" :type
:string
)
125 (aliases "s_aliases" :type
:pointer
)
126 (port "s_port" :type
:int
)
127 (proto "s_proto" :type
:string
))
129 (constant (somaxconn "SOMAXCONN")
130 :documentation
"Maximum listen() queue length")
132 (constant (sol-socket "SOL_SOCKET")
133 :documentation
"get/setsockopt socket level constant.")
137 (constant (sol-tcp "SOL_TCP")
138 :documentation
"get/setsockopt TCP level constant.")
139 (constant (sol-ip "SOL_IP")
140 :documentation
"get/setsockopt IP level constant.")
141 (constant (sol-raw "SOL_RAW")
142 :documentation
"get/setsockopt raw level constant."))
144 ;;; getsockopt/setsockopt()
145 (constant (so-acceptconn "SO_ACCEPTCONN"))
146 (constant (so-acceptfilter "SO_ACCEPTFILTER") :optional t
) ; freebsd
147 (constant (so-bindtodevice "SO_BINDTODEVICE") :optional t
) ; linux
148 (constant (so-bintime "SO_BINTIME") :optional t
) ; freebsd
149 (constant (so-broadcast "SO_BROADCAST"))
150 (constant (so-bsdcompat "SO_BSDCOMPAT") :optional t
) ; linux
151 (constant (so-debug "SO_DEBUG"))
152 (constant (so-dontroute "SO_DONTROUTE"))
153 (constant (so-error "SO_ERROR"))
154 (constant (so-keepalive "SO_KEEPALIVE"))
155 (constant (so-label "SO_LABEL") :optional t
) ; freebsd
156 (constant (so-linger "SO_LINGER"))
157 (constant (so-listenincqlen "SO_LISTENINCQLEN") :optional t
) ; freebsd
158 (constant (so-listenqlen "SO_LISTENQLEN") :optional t
) ; freebsd
159 (constant (so-listenqlimit "SO_LISTENQLIMIT") :optional t
) ; freebsd
160 (constant (so-nosigpipe "SO_NOSIGPIPE") :optional t
) ; freebsd
161 (constant (so-oobinline "SO_OOBINLINE"))
162 (constant (so-passcred "SO_PASSCRED") :optional t
) ; linux
163 (constant (so-peercred "SO_PEERCRED") :optional t
) ; linux
164 (constant (so-peerlabel "SO_PEERLABEL") :optional t
) ; freebsd
165 (constant (so-priority "SO_PRIORITY") :optional t
) ; linux
166 (constant (so-rcvbuf "SO_RCVBUF"))
167 (constant (so-rcvlowat "SO_RCVLOWAT"))
168 (constant (so-rcvtimeo "SO_RCVTIMEO"))
169 (constant (so-reuseaddr "SO_REUSEADDR"))
170 (constant (so-reuseport "SO_REUSEPORT") :optional t
) ; freebsd
171 (constant (so-sndbuf "SO_SNDBUF"))
172 (constant (so-sndlowat "SO_SNDLOWAT"))
173 (constant (so-sndtimeo "SO_SNDTIMEO"))
174 (constant (so-timestamp "SO_TIMESTAMP"))
175 (constant (so-type "SO_TYPE"))
176 (constant (so-useloopback "SO_USELOOPBACK") :optional t
) ; freebsd
177 (constant (tcp-cork "TCP_CORK") :optional t
) ; linux
178 (constant (tcp-defer-accept "TCP_DEFER_ACCEPT") :optional t
) ; linux
179 (constant (tcp-info "TCP_INFO") :optional t
) ; linux
180 (constant (tcp-keepcnt "TCP_KEEPCNT") :optional t
) ; linux
181 (constant (tcp-keepidle "TCP_KEEPIDLE") :optional t
) ; linux
182 (constant (tcp-keepintvl "TCP_KEEPINTVL") :optional t
) ; linux
183 (constant (tcp-linger2 "TCP_LINGER2") :optional t
) ; linux
184 (constant (tcp-maxseg "TCP_MAXSEG") :optional t
) ; linux, freebsd
185 (constant (tcp-nodelay "TCP_NODELAY") :optional t
) ; linux, freebsd
186 (constant (tcp-noopt "TCP_NOOPT") :optional t
) ; freebsd
187 (constant (tcp-nopush "TCP_NOPUSH") :optional t
) ; freebsd
188 (constant (tcp-quickack "TCP_QUICKACK") :optional t
) ; linux
189 (constant (tcp-syncnt "TCP_SYNCNT") :optional t
) ; linux
190 (constant (tcp-window "TCP_WINDOW") :optional t
) ; linux
193 (constant (shut-rd "SHUT_RD"))
194 (constant (shut-wr "SHUT_WR"))
195 (constant (shut-rdwr "SHUT_RDWR"))
197 ;;; recvmsg/sendmsg()
198 (constant (msg-ctrunc "MSG_CTRUNC")) ; recvmsg
199 (constant (msg-dontroute "MSG_DONTROUTE")) ; sendmsg
200 (constant (msg-eor "MSG_EOR")) ; recvmsg sendmsg
201 (constant (msg-oob "MSG_OOB")) ; recvmsg sendmsg
202 (constant (msg-peek "MSG_PEEK")) ; recvmsg
203 (constant (msg-trunc "MSG_TRUNC")) ; recvmsg
204 (constant (msg-waitall "MSG_WAITALL")) ; recvmsg
205 (constant (msg-dontwait "MSG_DONTWAIT")) ; recvmsg sendmsg
206 #-darwin
(constant (msg-nosignal "MSG_NOSIGNAL")) ; sendmsg
207 (constant (msg-errqueue "MSG_ERRQUEUE") :optional t
) ; recvmsg
208 (constant (msg-more "MSG_MORE") :optional t
) ; sendmsg
209 (constant (msg-confirm "MSG_CONFIRM") :optional t
) ; sendmsg sendmsg
210 (constant (msg-proxy "MSG_PROXY") :optional t
) ;
211 (constant (msg-fin "MSG_FIN") :optional t
) ;
212 (constant (msg-syn "MSG_SYN") :optional t
) ;
213 (constant (msg-eof "MSG_EOF") :optional t
) ;
214 (constant (msg-nbio "MSG_NBIO") :optional t
) ;
215 (constant (msg-compat "MSG_COMPAT") :optional t
) ;
217 (cstruct msghdr
"struct msghdr"
218 (name "msg_name" :type
:pointer
)
219 (namelen "msg_namelen" :type socklen
)
220 (iov "msg_iov" :type
:pointer
)
221 (iovlen "msg_iovlen" :type size
)
222 (control "msg_control" :type
:pointer
)
223 (controllen "msg_controllen" :type socklen
)
224 (flags "msg_flags" :type
:int
))
226 (cstruct cmsghdr
"struct cmsghdr"
227 (len "cmsg_len" :type socklen
)
228 (level "cmsg_level" :type
:int
)
229 (type "cmsg_type" :type
:int
))
231 (constant (cmgroup-max "CMGROUP_MAX") :optional t
)
234 (cstruct cmsgcred
"struct cmsgcred"
235 (pid "cmcred_pid" :type pid
)
236 (uid "cmcred_uid" :type uid
)
237 (euid "cmcred_euid" :type uid
)
238 (gid "cmcred_gid" :type gid
)
239 (ngroups "cmcred_ngroups" :type
:short
)
240 (groups "cmcred_groups" :type gid
:count
:auto
))
242 (constant (scm-rights "SCM_RIGHTS"))
243 (constant (scm-credentials "SCM_CREDENTIALS") :optional t
)
246 (cstruct ucred
"struct ucred"
247 "Socket credential messages."
248 (pid "pid" :type pid
)
249 (uid "uid" :type uid
)
250 (gid "gid" :type gid
))
253 (cstruct sockcred
"struct sockcred"
254 (uid "sc_uid" :type uid
)
255 (euid "sc_euid" :type uid
)
256 (gid "sc_gid" :type gid
)
257 (egid "sc_egid" :type gid
)
258 (ngroups "sc_ngroups" :type
:int
)
259 (groups "sc_groups" :type gid
:count
:auto
))
262 (cstruct linger
"struct linger"
263 "SO_LINGER manipulation record."
264 (onoff "l_onoff" :type
:int
)
265 (linger "l_linger" :type
:int
))
268 (cstruct accept-filter-arg
"struct accept_filter_arg"
269 (name "af_name" :type
:uint8
:count
:auto
)
270 (arg "af_arg" :type
:uint8
:count
:auto
))
274 (cstruct sockaddr-un
"struct sockaddr_un"
275 "A UNIX-domain socket address."
276 (family "sun_family" :type sa-family
)
277 (path "sun_path" :type
:uint8
:count
:auto
))
281 (constant (local-peercred "LOCAL_PEERCRED"))
282 (constant (local-creds "LOCAL_CREDS"))
283 (constant (local-connwait "LOCAL_CONNWAIT")))
285 ;;;; from netinet/in.h
287 (ctype in-port
"in_port_t")
288 (ctype in-addr
"in_addr_t")
290 (cstruct sockaddr-in
"struct sockaddr_in"
291 "An IPv4 socket address."
292 (family "sin_family" :type sa-family
)
293 (port "sin_port" :type in-port
)
294 (addr "sin_addr" :type in-addr
))
296 (cstruct in-addr-struct
"struct in_addr"
297 (addr "s_addr" :type
:uint32
))
299 (cunion in6-addr
"struct in6_addr"
301 (addr8 "s6_addr" :type
:uint8
:count
:auto
)
302 (addr16 "s6_addr16" :type
:uint16
:count
:auto
)
303 (addr32 "s6_addr32" :type
:uint32
:count
:auto
))
305 (cstruct sockaddr-in6
"struct sockaddr_in6"
306 "An IPv6 socket address."
307 (family "sin6_family" :type sa-family
)
308 (port "sin6_port" :type in-port
)
309 (flowinfo "sin6_flowinfo" :type
:uint32
)
310 (addr "sin6_addr" :type in6-addr
)
311 (scope-id "sin6_scope_id" :type
:uint32
))
313 (constant (inaddr-any "INADDR_ANY"))
314 (constant (inaddr-broadcast "INADDR_BROADCAST"))
315 (constant (inaddr-none "INADDR_NONE"))
316 (constant (in-loopbacknet "IN_LOOPBACKNET"))
317 (constant (inaddr-loopback "INADDR_LOOPBACK"))
318 (constant (inaddr-unspec-group "INADDR_UNSPEC_GROUP"))
319 (constant (inaddr-allhosts-group "INADDR_ALLHOSTS_GROUP"))
320 (constant (inaddr-allrtrs-group "INADDR_ALLRTRS_GROUP"))
321 (constant (inaddr-max-local-group "INADDR_MAX_LOCAL_GROUP"))
323 (constant (inet-addrstrlen "INET_ADDRSTRLEN"))
324 (constant (inet6-addrstrlen "INET6_ADDRSTRLEN"))
326 (constant (ipv6-join-group "IPV6_JOIN_GROUP"))
327 (constant (ipv6-leave-group "IPV6_LEAVE_GROUP"))
328 (constant (ipv6-multicast-hops "IPV6_MULTICAST_HOPS"))
329 (constant (ipv6-multicast-if "IPV6_MULTICAST_IF"))
330 (constant (ipv6-multicast-loop "IPV6_MULTICAST_LOOP"))
331 (constant (ipv6-unicast-hops "IPV6_UNICAST_HOPS"))
332 (constant (ipv6-v6only "IPV6_V6ONLY"))
334 ;;;; from netinet/tcp.h
336 (constant (tcp-nodelay "TCP_NODELAY"))
337 (constant (tcp-maxseg "TCP_MAXSEG"))
339 (constant (tcp-cork "TCP_CORK"))
340 (constant (tcp-keepidle "TCP_KEEPIDLE") :optional t
)
341 (constant (tcp-keepintvl "TCP_KEEPINTVL") :optional t
)
342 (constant (tcp-keepcnt "TCP_KEEPCNT") :optional t
)
343 (constant (tcp-syncnt "TCP_SYNCNT") :optional t
)
344 (constant (tcp-linger2 "TCP_LINGER2") :optional t
)
345 (constant (tcp-defer-accept "TCP_DEFER_ACCEPT") :optional t
)
346 (constant (tcp-window-clamp "TCP_WINDOW_CLAMP") :optional t
)
347 #-darwin
(constant (tcp-info "TCP_INFO"))
348 (constant (tcp-quickack "TCP_QUICKACK") :optional t
)
352 ((:tcp-established
"TCP_ESTABLISHED"))
353 ((:tcp-syn-sent
"TCP_SYN_SENT"))
354 ((:tcp-syn-recv
"TCP_SYN_RECV"))
355 ((:tcp-fin-wait1
"TCP_FIN_WAIT1"))
356 ((:tcp-fin-wait2
"TCP_FIN_WAIT2"))
357 ((:tcp-time-wait
"TCP_TIME_WAIT"))
358 ((:tcp-close
"TCP_CLOSE"))
359 ((:tcp-close-wait
"TCP_CLOSE_WAIT"))
360 ((:tcp-last-ack
"TCP_LAST_ACK"))
361 ((:tcp-listen
"TCP_LISTEN"))
362 ((:tcp-closing
"TCP_CLOSING")))
366 (constant (ipport-reserved "IPPORT_RESERVED"))
368 (cstruct addrinfo
"struct addrinfo"
369 (flags "ai_flags" :type
:int
)
370 (family "ai_family" :type
:int
)
371 (socktype "ai_socktype" :type
:int
)
372 (protocol "ai_protocol" :type
:int
)
373 (addrlen "ai_addrlen" :type socklen
)
374 (addr "ai_addr" :type
:pointer
)
375 (canonname "ai_canonname" :type
:pointer
)
376 (next "ai_next" :type
:pointer
))
379 (constant (ai-passive "AI_PASSIVE"))
380 (constant (ai-canonname "AI_CANONNAME"))
381 (constant (ai-numerichost "AI_NUMERICHOST"))
382 #-darwin
(constant (ai-numericserv "AI_NUMERICSERV"))
383 (constant (ai-v4mapped "AI_V4MAPPED"))
384 (constant (ai-v4mapped-cfg "AI_V4MAPPED_CFG") :optional t
) ; freebsd
385 (constant (ai-all "AI_ALL"))
386 (constant (ai-addrconfig "AI_ADDRCONFIG"))
388 (constant (ni-maxhost "NI_MAXHOST"))
389 (constant (ni-maxserv "NI_MAXSERV"))
392 (constant (ni-nofqdn "NI_NOFQDN"))
393 (constant (ni-numerichost "NI_NUMERICHOST"))
394 (constant (ni-namereqd "NI_NAMEREQD"))
395 (constant (ni-numericserv "NI_NUMERICSERV"))
396 (constant (ni-numericscope "NI_NUMERICSCOPE") :optional t
)
397 (constant (ni-dgram "NI_DGRAM"))
400 (constant (netdb-success "NETDB_SUCCESS"))
401 (constant (netdb-internal "NETDB_INTERNAL"))
403 (constantenum addrinfo-errors
404 ((:netdb-success
"NETDB_SUCCESS"))
405 ((:eai-addrfamily
"EAI_ADDRFAMILY") :optional t
) ; linux
406 ((:eai-again
"EAI_AGAIN"))
407 ((:eai-badflags
"EAI_BADFLAGS"))
408 ((:eai-fail
"EAI_FAIL"))
409 ((:eai-family
"EAI_FAMILY"))
410 ((:eai-memory
"EAI_MEMORY"))
411 ((:eai-noname
"EAI_NONAME"))
412 ((:eai-nodata
"EAI_NODATA") :optional t
) ; linux
413 ((:eai-service
"EAI_SERVICE"))
414 ((:eai-socktype
"EAI_SOCKTYPE"))
415 ((:eai-system
"EAI_SYSTEM"))
416 ((:eai-badhints
"EAI_BADHINTS") :optional t
) ; freebsd
417 ((:eai-protocol
"EAI_PROTOCOL") :optional t
) ; freebsd
418 ((:eai-max
"EAI_MAX") :optional t
) ; freebsd
419 ((:eai-overflow
"EAI_OVERFLOW") :optional t
)) ; linux
421 (cstruct protoent
"struct protoent"
422 (name "p_name" :type
:string
)
423 (aliases "p_aliases" :type
:pointer
)
424 (proto "p_proto" :type
:int
))
428 (cstruct if-nameindex
"struct if_nameindex"
429 (index "if_index" :type
:unsigned-int
)
430 (name "if_name" :type
:string
))
432 (constant (ifnamesize "IF_NAMESIZE"))
433 (constant (ifnamsiz "IFNAMSIZ"))