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 <sionescu@common-lisp.net>
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.
30 ;;; This file contains a lot of unused types and constants that should
31 ;;; be cleaned up or at least commented out.
33 (include "sys/socket.h" "sys/un.h" "netinet/in.h"
34 "net/if.h" "netinet/tcp.h" "netdb.h" "errno.h"
37 (in-package :net.sockets
)
39 ;;; TODO: check if I didn't miss any from CL-POSIX. --luis
40 (constantenum socket-error-values
41 ((:eprotonosupport
"EPROTONOSUPPORT"))
42 ((:esocktnosupport
"ESOCKTNOSUPPORT"))
43 ((:enotsock
"ENOTSOCK"))
44 ((:edestaddrreq
"EDESTADDRREQ"))
45 ((:emsgsize
"EMSGSIZE"))
46 ((:eprototype
"EPROTOTYPE"))
47 ((:enoprotoopt
"ENOPROTOOPT"))
48 ((:eremote
"EREMOTE"))
49 ((:enolink
"ENOLINK"))
50 ((:epfnosupport
"EPFNOSUPPORT"))
51 ((:eafnosupport
"EAFNOSUPPORT"))
52 ((:eaddrinuse
"EADDRINUSE" "WSAEADDRINUSE"))
53 ((:eaddrnotavail
"EADDRNOTAVAIL"))
54 ((:enetdown
"ENETDOWN"))
55 ((:enetunreach
"ENETUNREACH"))
56 ((:enetreset
"ENETRESET"))
57 ((:econnaborted
"ECONNABORTED"))
58 ((:econnreset
"ECONNRESET"))
59 ((:eisconn
"EISCONN"))
60 ((:enotconn
"ENOTCONN"))
61 ((:eshutdown
"ESHUTDOWN"))
62 ((:etoomanyrefs
"ETOOMANYREFS"))
63 ((:etimedout
"ETIMEDOUT"))
64 ((:econnrefused
"ECONNREFUSED"))
65 ((:ehostdown
"EHOSTDOWN"))
66 ((:ehostunreach
"EHOSTUNREACH"))
67 ((:enonet
"ENONET") :optional t
)
68 ((:enobufs
"ENOBUFS"))
69 ((:eopnotsupp
"EOPNOTSUPP"))
78 ((:einprogress
"EINPROGRESS"))
79 ((:ealready
"EALREADY"))
81 ((:enametoolong
"ENAMETOOLONG"))
82 ((:enotempty
"ENOTEMPTY"))
89 (ctype socklen
"socklen_t")
90 (ctype sa-family
"sa_family_t")
92 ;;; socket() - socket address family
93 (constant (af-unspec "AF_UNSPEC" "PF_UNSPEC"))
94 (constant (af-inet "AF_INET" "PF_INET") :documentation
"IPv4 Protocol family")
95 (constant (af-inet6 "AF_INET6" "PF_INET6")
96 :documentation
"IPv6 Protocol family")
97 (constant (af-local "AF_UNIX" "AF_LOCAL" "PF_UNIX" "PF_LOCAL")
98 :documentation
"File domain sockets")
99 (constant (af-packet "AF_PACKET" "PF_PACKET") :documentation
"Raw packet access"
101 (constant (af-route "AF_ROUTE" "PF_ROUTE")
102 :documentation
"Routing sockets" :optional t
)
103 (constant (af-key "AF_KEY" "PF_KEY"))
104 (constant (af-netlink "AF_NETLINK" "PF_NETLINK")
105 :documentation
"Linux Netlink sockets" :optional t
)
107 ;;; socket() - socket type
108 (constant (sock-stream "SOCK_STREAM") :documentation
"TCP")
109 (constant (sock-dgram "SOCK_DGRAM") :documentation
"UDP")
110 (constant (sock-seqpacket "SOCK_SEQPACKET")
111 :documentation
"Reliable Sequenced Datagram Protocol" :optional t
)
112 (constant (sock-raw "SOCK_RAW") :documentation
"Raw protocol access"
114 (constant (sock-rdm "SOCK_RDM")
115 :documentation
"Reliable Unordered Datagram Protocol" :optional t
)
117 ;;; socket() - socket protocol
118 (constant (ipproto-ip "IPPROTO_IP"))
119 (constant (ipproto-ipv6 "IPPROTO_IPV6"))
120 (constant (ipproto-icmp "IPPROTO_ICMP"))
121 (constant (ipproto-icmpv6 "IPPROTO_ICMPV6"))
122 (constant (ipproto-raw "IPPROTO_RAW"))
123 (constant (ipproto-tcp "IPPROTO_TCP"))
124 (constant (ipproto-udp "IPPROTO_UDP"))
125 #-darwin
(constant (ipproto-sctp "IPPROTO_SCTP"))
127 (cstruct sockaddr
"struct sockaddr"
128 (family "sa_family" :type sa-family
))
130 (cstruct sockaddr-storage
"struct sockaddr_storage"
131 (family "ss_family" :type sa-family
))
133 (cstruct hostent
"struct hostent"
134 (name "h_name" :type
:string
)
135 (aliases "h_aliases" :type
:pointer
)
136 (type "h_addrtype" :type
:int
)
137 (length "h_length" :type
:int
)
138 (addresses "h_addr_list" :type
:pointer
))
140 (cstruct servent
"struct servent"
141 (name "s_name" :type
:string
)
142 (aliases "s_aliases" :type
:pointer
)
143 (port "s_port" :type
:int
)
144 (proto "s_proto" :type
:string
))
146 (constant (somaxconn "SOMAXCONN")
147 :documentation
"Maximum listen() queue length")
149 (constant (sol-socket "SOL_SOCKET")
150 :documentation
"get/setsockopt socket level constant.")
154 (constant (sol-tcp "SOL_TCP")
155 :documentation
"get/setsockopt TCP level constant.")
156 (constant (sol-ip "SOL_IP")
157 :documentation
"get/setsockopt IP level constant.")
158 (constant (sol-raw "SOL_RAW")
159 :documentation
"get/setsockopt raw level constant."))
161 ;;; getsockopt/setsockopt()
162 (constant (so-acceptconn "SO_ACCEPTCONN"))
163 (constant (so-acceptfilter "SO_ACCEPTFILTER") :optional t
) ; freebsd
164 (constant (so-bindtodevice "SO_BINDTODEVICE") :optional t
) ; linux
165 (constant (so-bintime "SO_BINTIME") :optional t
) ; freebsd
166 (constant (so-broadcast "SO_BROADCAST"))
167 (constant (so-bsdcompat "SO_BSDCOMPAT") :optional t
) ; linux
168 (constant (so-debug "SO_DEBUG"))
169 (constant (so-dontroute "SO_DONTROUTE"))
170 (constant (so-error "SO_ERROR"))
171 (constant (so-keepalive "SO_KEEPALIVE"))
172 (constant (so-label "SO_LABEL") :optional t
) ; freebsd
173 (constant (so-linger "SO_LINGER"))
174 (constant (so-listenincqlen "SO_LISTENINCQLEN") :optional t
) ; freebsd
175 (constant (so-listenqlen "SO_LISTENQLEN") :optional t
) ; freebsd
176 (constant (so-listenqlimit "SO_LISTENQLIMIT") :optional t
) ; freebsd
177 (constant (so-nosigpipe "SO_NOSIGPIPE") :optional t
) ; freebsd
178 (constant (so-oobinline "SO_OOBINLINE"))
179 (constant (so-passcred "SO_PASSCRED") :optional t
) ; linux
180 (constant (so-peercred "SO_PEERCRED") :optional t
) ; linux
181 (constant (so-peerlabel "SO_PEERLABEL") :optional t
) ; freebsd
182 (constant (so-priority "SO_PRIORITY") :optional t
) ; linux
183 (constant (so-rcvbuf "SO_RCVBUF"))
184 (constant (so-rcvlowat "SO_RCVLOWAT"))
185 (constant (so-rcvtimeo "SO_RCVTIMEO"))
186 (constant (so-reuseaddr "SO_REUSEADDR"))
187 (constant (so-reuseport "SO_REUSEPORT") :optional t
) ; freebsd
188 (constant (so-sndbuf "SO_SNDBUF"))
189 (constant (so-sndlowat "SO_SNDLOWAT"))
190 (constant (so-sndtimeo "SO_SNDTIMEO"))
191 (constant (so-timestamp "SO_TIMESTAMP"))
192 (constant (so-type "SO_TYPE"))
193 (constant (so-useloopback "SO_USELOOPBACK") :optional t
) ; freebsd
194 (constant (tcp-cork "TCP_CORK") :optional t
) ; linux
195 (constant (tcp-defer-accept "TCP_DEFER_ACCEPT") :optional t
) ; linux
196 (constant (tcp-info "TCP_INFO") :optional t
) ; linux
197 (constant (tcp-keepcnt "TCP_KEEPCNT") :optional t
) ; linux
198 (constant (tcp-keepidle "TCP_KEEPIDLE") :optional t
) ; linux
199 (constant (tcp-keepintvl "TCP_KEEPINTVL") :optional t
) ; linux
200 (constant (tcp-linger2 "TCP_LINGER2") :optional t
) ; linux
201 (constant (tcp-maxseg "TCP_MAXSEG") :optional t
) ; linux, freebsd
202 (constant (tcp-nodelay "TCP_NODELAY") :optional t
) ; linux, freebsd
203 (constant (tcp-noopt "TCP_NOOPT") :optional t
) ; freebsd
204 (constant (tcp-nopush "TCP_NOPUSH") :optional t
) ; freebsd
205 (constant (tcp-quickack "TCP_QUICKACK") :optional t
) ; linux
206 (constant (tcp-syncnt "TCP_SYNCNT") :optional t
) ; linux
207 (constant (tcp-window "TCP_WINDOW") :optional t
) ; linux
210 (constant (shut-rd "SHUT_RD" "SD_RECEIVE"))
211 (constant (shut-wr "SHUT_WR" "SD_SEND"))
212 (constant (shut-rdwr "SHUT_RDWR" "SD_BOTH"))
214 ;;; recvmsg/sendmsg()
215 (constant (msg-dontroute "MSG_DONTROUTE")) ; sendmsg
216 (constant (msg-oob "MSG_OOB")) ; recvmsg sendmsg
217 (constant (msg-peek "MSG_PEEK")) ; recvmsg
218 (constant (msg-errqueue "MSG_ERRQUEUE") :optional t
) ; recvmsg
219 (constant (msg-more "MSG_MORE") :optional t
) ; sendmsg
220 (constant (msg-confirm "MSG_CONFIRM") :optional t
) ; sendmsg sendmsg
221 (constant (msg-proxy "MSG_PROXY") :optional t
) ;
222 (constant (msg-fin "MSG_FIN") :optional t
) ;
223 (constant (msg-syn "MSG_SYN") :optional t
) ;
224 (constant (msg-eof "MSG_EOF") :optional t
) ;
225 (constant (msg-nbio "MSG_NBIO") :optional t
) ;
226 (constant (msg-compat "MSG_COMPAT") :optional t
) ;
227 (constant (msg-trunc "MSG_TRUNC")) ; recvmsg
228 (constant (msg-waitall "MSG_WAITALL")) ; recvmsg
229 (constant (msg-dontwait "MSG_DONTWAIT")) ; recvmsg sendmsg
230 #-darwin
(constant (msg-nosignal "MSG_NOSIGNAL")) ; sendmsg
231 (constant (msg-eor "MSG_EOR")) ; recvmsg sendmsg
232 (constant (msg-ctrunc "MSG_CTRUNC")) ; recvmsg
235 (cstruct msghdr
"struct msghdr"
236 (name "msg_name" :type
:pointer
)
237 (namelen "msg_namelen" :type socklen
)
238 (iov "msg_iov" :type
:pointer
)
239 (iovlen "msg_iovlen" :type size
)
240 (control "msg_control" :type
:pointer
)
241 (controllen "msg_controllen" :type socklen
)
242 (flags "msg_flags" :type
:int
))
245 (cstruct cmsghdr
"struct cmsghdr"
246 (len "cmsg_len" :type socklen
)
247 (level "cmsg_level" :type
:int
)
248 (type "cmsg_type" :type
:int
))
251 (constant (cmgroup-max "CMGROUP_MAX") :optional t
)
253 #+(or (or) freebsd
) ; unused
254 (cstruct cmsgcred
"struct cmsgcred"
255 (pid "cmcred_pid" :type pid
)
256 (uid "cmcred_uid" :type uid
)
257 (euid "cmcred_euid" :type uid
)
258 (gid "cmcred_gid" :type gid
)
259 (ngroups "cmcred_ngroups" :type
:short
)
260 (groups "cmcred_groups" :type gid
:count
:auto
))
263 (constant (scm-rights "SCM_RIGHTS"))
264 (constant (scm-credentials "SCM_CREDENTIALS") :optional t
)
267 (cstruct ucred
"struct ucred"
268 "Socket credential messages."
269 (pid "pid" :type pid
)
270 (uid "uid" :type uid
)
271 (gid "gid" :type gid
))
274 (cstruct sockcred
"struct sockcred"
275 (uid "sc_uid" :type uid
)
276 (euid "sc_euid" :type uid
)
277 (gid "sc_gid" :type gid
)
278 (egid "sc_egid" :type gid
)
279 (ngroups "sc_ngroups" :type
:int
)
280 (groups "sc_groups" :type gid
:count
:auto
))
282 (cstruct linger
"struct linger"
283 "SO_LINGER manipulation record."
284 (onoff "l_onoff" :type
:int
)
285 (linger "l_linger" :type
:int
))
288 (cstruct accept-filter-arg
"struct accept_filter_arg"
289 (name "af_name" :type
:uint8
:count
:auto
)
290 (arg "af_arg" :type
:uint8
:count
:auto
))
294 (cstruct sockaddr-un
"struct sockaddr_un"
295 "A UNIX-domain socket address."
296 (family "sun_family" :type sa-family
)
297 (path "sun_path" :type
:uint8
:count
:auto
))
301 (constant (local-peercred "LOCAL_PEERCRED"))
302 (constant (local-creds "LOCAL_CREDS"))
303 (constant (local-connwait "LOCAL_CONNWAIT")))
305 ;;;; from netinet/in.h
307 (ctype in-port
"in_port_t")
308 (ctype in-addr
"in_addr_t")
310 (cstruct sockaddr-in
"struct sockaddr_in"
311 "An IPv4 socket address."
312 (family "sin_family" :type sa-family
)
313 (port "sin_port" :type in-port
)
314 (addr "sin_addr" :type in-addr
))
316 (cstruct in-addr-struct
"struct in_addr"
317 (addr "s_addr" :type
:uint32
))
319 (cunion in6-addr
"struct in6_addr"
321 (addr8 "s6_addr" :type
:uint8
:count
:auto
)
322 (addr16 "s6_addr16" :type
:uint16
:count
:auto
)
323 (addr32 "s6_addr32" :type
:uint32
:count
:auto
))
325 (cstruct sockaddr-in6
"struct sockaddr_in6"
326 "An IPv6 socket address."
327 (family "sin6_family" :type sa-family
)
328 (port "sin6_port" :type in-port
)
329 (flowinfo "sin6_flowinfo" :type
:uint32
)
330 (addr "sin6_addr" :type in6-addr
)
331 (scope-id "sin6_scope_id" :type
:uint32
))
335 (constant (inaddr-any "INADDR_ANY"))
336 (constant (inaddr-broadcast "INADDR_BROADCAST"))
337 (constant (inaddr-none "INADDR_NONE"))
338 (constant (in-loopbacknet "IN_LOOPBACKNET"))
339 (constant (inaddr-loopback "INADDR_LOOPBACK"))
340 (constant (inaddr-unspec-group "INADDR_UNSPEC_GROUP"))
341 (constant (inaddr-allhosts-group "INADDR_ALLHOSTS_GROUP"))
342 (constant (inaddr-allrtrs-group "INADDR_ALLRTRS_GROUP"))
343 (constant (inaddr-max-local-group "INADDR_MAX_LOCAL_GROUP")))
345 (constant (inet-addrstrlen "INET_ADDRSTRLEN"))
346 (constant (inet6-addrstrlen "INET6_ADDRSTRLEN"))
348 (constant (ipv6-join-group "IPV6_JOIN_GROUP"))
349 (constant (ipv6-leave-group "IPV6_LEAVE_GROUP"))
350 (constant (ipv6-multicast-hops "IPV6_MULTICAST_HOPS"))
351 (constant (ipv6-multicast-if "IPV6_MULTICAST_IF"))
352 (constant (ipv6-multicast-loop "IPV6_MULTICAST_LOOP"))
353 (constant (ipv6-unicast-hops "IPV6_UNICAST_HOPS"))
354 (constant (ipv6-v6only "IPV6_V6ONLY"))
356 ;;;; from netinet/tcp.h
358 (constant (tcp-nodelay "TCP_NODELAY"))
359 (constant (tcp-maxseg "TCP_MAXSEG"))
361 (constant (tcp-cork "TCP_CORK"))
362 (constant (tcp-keepidle "TCP_KEEPIDLE") :optional t
)
363 (constant (tcp-keepintvl "TCP_KEEPINTVL") :optional t
)
364 (constant (tcp-keepcnt "TCP_KEEPCNT") :optional t
)
365 (constant (tcp-syncnt "TCP_SYNCNT") :optional t
)
366 (constant (tcp-linger2 "TCP_LINGER2") :optional t
)
367 (constant (tcp-defer-accept "TCP_DEFER_ACCEPT") :optional t
)
368 (constant (tcp-window-clamp "TCP_WINDOW_CLAMP") :optional t
)
369 #-darwin
(constant (tcp-info "TCP_INFO"))
370 (constant (tcp-quickack "TCP_QUICKACK") :optional t
)
374 ((:tcp-established
"TCP_ESTABLISHED"))
375 ((:tcp-syn-sent
"TCP_SYN_SENT"))
376 ((:tcp-syn-recv
"TCP_SYN_RECV"))
377 ((:tcp-fin-wait1
"TCP_FIN_WAIT1"))
378 ((:tcp-fin-wait2
"TCP_FIN_WAIT2"))
379 ((:tcp-time-wait
"TCP_TIME_WAIT"))
380 ((:tcp-close
"TCP_CLOSE"))
381 ((:tcp-close-wait
"TCP_CLOSE_WAIT"))
382 ((:tcp-last-ack
"TCP_LAST_ACK"))
383 ((:tcp-listen
"TCP_LISTEN"))
384 ((:tcp-closing
"TCP_CLOSING")))
388 (constant (ipport-reserved "IPPORT_RESERVED"))
390 (cstruct addrinfo
"struct addrinfo"
391 (flags "ai_flags" :type
:int
)
392 (family "ai_family" :type
:int
)
393 (socktype "ai_socktype" :type
:int
)
394 (protocol "ai_protocol" :type
:int
)
395 (addrlen "ai_addrlen" :type socklen
)
396 (addr "ai_addr" :type
:pointer
)
397 (canonname "ai_canonname" :type
:pointer
)
398 (next "ai_next" :type
:pointer
))
401 (constant (ai-passive "AI_PASSIVE"))
402 (constant (ai-canonname "AI_CANONNAME"))
403 (constant (ai-numerichost "AI_NUMERICHOST"))
404 #-darwin
(constant (ai-numericserv "AI_NUMERICSERV"))
405 (constant (ai-v4mapped "AI_V4MAPPED"))
406 (constant (ai-v4mapped-cfg "AI_V4MAPPED_CFG") :optional t
) ; freebsd
407 (constant (ai-all "AI_ALL"))
408 (constant (ai-addrconfig "AI_ADDRCONFIG"))
410 (constant (ni-maxhost "NI_MAXHOST"))
411 (constant (ni-maxserv "NI_MAXSERV"))
414 (constant (ni-nofqdn "NI_NOFQDN"))
415 (constant (ni-numerichost "NI_NUMERICHOST"))
416 (constant (ni-namereqd "NI_NAMEREQD"))
417 (constant (ni-numericserv "NI_NUMERICSERV"))
418 (constant (ni-numericscope "NI_NUMERICSCOPE") :optional t
)
419 (constant (ni-dgram "NI_DGRAM"))
422 (constant (netdb-success "NETDB_SUCCESS"))
423 (constant (netdb-internal "NETDB_INTERNAL"))
425 (constantenum addrinfo-errors
426 ((:netdb-success
"NETDB_SUCCESS"))
427 ((:eai-addrfamily
"EAI_ADDRFAMILY") :optional t
) ; linux
428 ((:eai-again
"EAI_AGAIN"))
429 ((:eai-badflags
"EAI_BADFLAGS"))
430 ((:eai-fail
"EAI_FAIL"))
431 ((:eai-family
"EAI_FAMILY"))
432 ((:eai-memory
"EAI_MEMORY"))
433 ((:eai-noname
"EAI_NONAME"))
434 ((:eai-nodata
"EAI_NODATA") :optional t
) ; linux
435 ((:eai-service
"EAI_SERVICE"))
436 ((:eai-socktype
"EAI_SOCKTYPE"))
437 ((:eai-system
"EAI_SYSTEM"))
438 ((:eai-badhints
"EAI_BADHINTS") :optional t
) ; freebsd
439 ((:eai-protocol
"EAI_PROTOCOL") :optional t
) ; freebsd
440 ((:eai-max
"EAI_MAX") :optional t
) ; freebsd
441 ((:eai-overflow
"EAI_OVERFLOW") :optional t
)) ; linux
443 (cstruct protoent
"struct protoent"
444 (name "p_name" :type
:string
)
445 (aliases "p_aliases" :type
:pointer
)
446 (proto "p_proto" :type
:int
))
450 (cstruct if-nameindex
"struct if_nameindex"
451 (index "if_index" :type
:unsigned-int
)
452 (name "if_name" :type
:string
))
454 (constant (ifnamesize "IF_NAMESIZE"))
455 (constant (ifnamsiz "IFNAMSIZ"))