Mark ENOLINK and EMULTIHOP as optional
[iolib.git] / src / sockets / grovel.lisp
blobd1bb1dd5b57db1920dabf516800dffb8d1e9d7e6
1 ;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*-
2 ;;;
3 ;;; --- Grovelling for socket constants and types.
4 ;;;
5 ;;; Copyright (C) 2005-2006, Emily Backes <lucca@accela.net>
6 ;;; Copyright (C) 2005-2006, Dan Knapp <dankna@accela.net>
7 ;;; Copyright (C) 2007, Stelian Ionescu <sionescu@cddr.org>
8 ;;; Copyright (C) 2007, Luis Oliveira <loliveira@common-lisp.net>
9 ;;;
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:
17 ;;;
18 ;;; The above copyright notice and this permission notice shall be
19 ;;; included in all copies or substantial portions of the Software.
20 ;;;
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" "netdb.h" "errno.h" "time.h"
34 "net/if.h" "netinet/in.h" "netinet/tcp.h" "netinet/ip.h"
35 #+linux "linux/errqueue.h" #+linux "linux/icmp.h"
36 #+linux "linux/netlink.h"
37 "arpa/inet.h")
39 (in-package :iolib/sockets)
41 (constantenum socket-error-values
42 ((:eprotonosupport "EPROTONOSUPPORT"))
43 ((:esocktnosupport "ESOCKTNOSUPPORT"))
44 ((:enotsock "ENOTSOCK"))
45 ((:edestaddrreq "EDESTADDRREQ"))
46 ((:emsgsize "EMSGSIZE"))
47 ((:eprototype "EPROTOTYPE"))
48 ((:enoprotoopt "ENOPROTOOPT"))
49 ((:eremote "EREMOTE"))
50 ((:enolink "ENOLINK") :optional t)
51 ((:epfnosupport "EPFNOSUPPORT"))
52 ((:eafnosupport "EAFNOSUPPORT"))
53 ((:eaddrinuse "EADDRINUSE"))
54 ((:eaddrnotavail "EADDRNOTAVAIL"))
55 ((:enetdown "ENETDOWN"))
56 ((:enetunreach "ENETUNREACH"))
57 ((:enetreset "ENETRESET"))
58 ((:econnaborted "ECONNABORTED"))
59 ((:econnreset "ECONNRESET"))
60 ((:eisconn "EISCONN"))
61 ((:enotconn "ENOTCONN"))
62 ((:eshutdown "ESHUTDOWN"))
63 ((:etoomanyrefs "ETOOMANYREFS"))
64 ((:etimedout "ETIMEDOUT"))
65 ((:econnrefused "ECONNREFUSED"))
66 ((:ehostdown "EHOSTDOWN"))
67 ((:ehostunreach "EHOSTUNREACH"))
68 ((:enonet "ENONET") :optional t)
69 ((:enobufs "ENOBUFS"))
70 ((:eopnotsupp "EOPNOTSUPP"))
71 ((:ebadf "EBADF"))
72 ((:einval "EINVAL"))
73 ((:enomem "ENOMEM"))
74 ((:eacces "EACCES"))
75 ((:efault "EFAULT"))
76 ((:emfile "EMFILE"))
77 ((:einprogress "EINPROGRESS"))
78 ((:ealready "EALREADY"))
79 ((:eloop "ELOOP"))
80 ((:enametoolong "ENAMETOOLONG"))
81 ((:enotempty "ENOTEMPTY"))
82 ((:eusers "EUSERS"))
83 ((:edquot "EDQUOT"))
84 ((:estale "ESTALE")))
86 ;;;; sys/socket.h
88 (ctype socklen-t "socklen_t")
89 (ctype sa-family-t "sa_family_t")
91 ;;; socket() - socket address family
92 (constant (af-unspec "AF_UNSPEC" "PF_UNSPEC"))
93 (constant (af-inet "AF_INET" "PF_INET")
94 :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")
100 :documentation "Raw packet access"
101 :optional t)
102 (constant (af-route "AF_ROUTE" "PF_ROUTE")
103 :documentation "Routing sockets"
104 :optional t)
105 (constant (af-key "AF_KEY" "PF_KEY"))
106 (constant (af-netlink "AF_NETLINK" "PF_NETLINK")
107 :documentation "Linux Netlink sockets" :optional t)
109 ;;; socket() - socket type
110 (constant (sock-stream "SOCK_STREAM")
111 :documentation "TCP")
112 (constant (sock-dgram "SOCK_DGRAM")
113 :documentation "UDP")
114 (constant (sock-seqpacket "SOCK_SEQPACKET")
115 :documentation "Reliable Sequenced Datagram Protocol"
116 :optional t)
117 (constant (sock-raw "SOCK_RAW")
118 :documentation "Raw protocol access"
119 :optional t)
120 (constant (sock-rdm "SOCK_RDM")
121 :documentation "Reliable Unordered Datagram Protocol"
122 :optional t)
124 ;;; socket() - socket protocol
125 (constant (ipproto-ip "IPPROTO_IP"))
126 (constant (ipproto-ipv6 "IPPROTO_IPV6"))
127 (constant (ipproto-icmp "IPPROTO_ICMP"))
128 (constant (ipproto-icmpv6 "IPPROTO_ICMPV6"))
129 (constant (ipproto-raw "IPPROTO_RAW"))
130 (constant (ipproto-tcp "IPPROTO_TCP"))
131 (constant (ipproto-udp "IPPROTO_UDP"))
132 (constant (ipproto-sctp "IPPROTO_SCTP") :optional t)
134 (cstruct sockaddr "struct sockaddr"
135 (family "sa_family" :type sa-family-t))
137 (cstruct sockaddr-storage "struct sockaddr_storage"
138 (family "ss_family" :type sa-family-t))
140 (constant (somaxconn "SOMAXCONN")
141 :documentation "Maximum listen() queue length")
143 (constant (sol-socket "SOL_SOCKET")
144 :documentation "get/setsockopt socket level constant.")
146 (constant (sol-tcp "SOL_TCP")
147 :documentation "get/setsockopt TCP level constant."
148 :optional t)
149 (constant (sol-ip "SOL_IP")
150 :documentation "get/setsockopt IP level constant."
151 :optional t)
152 (constant (sol-raw "SOL_RAW")
153 :documentation "get/setsockopt raw level constant."
154 :optional t)
156 ;;; getsockopt/setsockopt()
157 (constant (so-acceptconn "SO_ACCEPTCONN"))
158 (constant (so-acceptfilter "SO_ACCEPTFILTER") :optional t) ; freebsd
159 (constant (so-bindtodevice "SO_BINDTODEVICE") :optional t) ; linux
160 (constant (so-bintime "SO_BINTIME") :optional t) ; freebsd
161 (constant (so-broadcast "SO_BROADCAST"))
162 (constant (so-debug "SO_DEBUG"))
163 (constant (so-dontroute "SO_DONTROUTE"))
164 (constant (so-error "SO_ERROR"))
165 (constant (so-keepalive "SO_KEEPALIVE"))
166 (constant (so-label "SO_LABEL") :optional t) ; freebsd
167 (constant (so-linger "SO_LINGER"))
168 (constant (so-listenincqlen "SO_LISTENINCQLEN") :optional t) ; freebsd
169 (constant (so-listenqlen "SO_LISTENQLEN") :optional t) ; freebsd
170 (constant (so-listenqlimit "SO_LISTENQLIMIT") :optional t) ; freebsd
171 (constant (so-nosigpipe "SO_NOSIGPIPE") :optional t) ; freebsd
172 (constant (so-oobinline "SO_OOBINLINE"))
173 (constant (so-passcred "SO_PASSCRED") :optional t) ; linux
174 (constant (so-peercred "SO_PEERCRED") :optional t) ; linux
175 (constant (so-peerlabel "SO_PEERLABEL") :optional t) ; freebsd
176 (constant (so-priority "SO_PRIORITY") :optional t) ; linux
177 (constant (so-rcvbuf "SO_RCVBUF"))
178 (constant (so-rcvlowat "SO_RCVLOWAT"))
179 (constant (so-rcvtimeo "SO_RCVTIMEO"))
180 (constant (so-reuseaddr "SO_REUSEADDR"))
181 (constant (so-reuseport "SO_REUSEPORT") :optional t) ; freebsd
182 (constant (so-sndbuf "SO_SNDBUF"))
183 (constant (so-sndlowat "SO_SNDLOWAT"))
184 (constant (so-sndtimeo "SO_SNDTIMEO"))
185 (constant (so-timestamp "SO_TIMESTAMP"))
186 (constant (so-type "SO_TYPE"))
187 (constant (so-useloopback "SO_USELOOPBACK") :optional t) ; freebsd
189 ;; TCP options
190 (constant (tcp-cork "TCP_CORK") :optional t) ; linux
191 (constant (tcp-defer-accept "TCP_DEFER_ACCEPT") :optional t) ; linux
192 (constant (tcp-info "TCP_INFO") :optional t) ; linux
193 (constant (tcp-keepcnt "TCP_KEEPCNT") :optional t) ; linux
194 (constant (tcp-keepidle "TCP_KEEPIDLE") :optional t) ; linux
195 (constant (tcp-keepintvl "TCP_KEEPINTVL") :optional t) ; linux
196 (constant (tcp-linger2 "TCP_LINGER2") :optional t) ; linux
197 (constant (tcp-maxseg "TCP_MAXSEG") :optional t) ; linux, freebsd
198 (constant (tcp-nodelay "TCP_NODELAY") :optional t) ; linux, freebsd
199 (constant (tcp-noopt "TCP_NOOPT") :optional t) ; freebsd
200 (constant (tcp-nopush "TCP_NOPUSH") :optional t) ; freebsd
201 (constant (tcp-quickack "TCP_QUICKACK") :optional t) ; linux
202 (constant (tcp-syncnt "TCP_SYNCNT") :optional t) ; linux
203 (constant (tcp-window-clamp "TCP_WINDOW_CLAMP") :optional t) ; linux
205 ;; IP options
206 (constant (ip-hdrincl "IP_HDRINCL"))
207 (constant (ip-recverr "IP_RECVERR") :optional t)
209 #+linux
210 (progn
211 (cenum extended-error-origin
212 ((:none "SO_EE_ORIGIN_NONE"))
213 ((:local "SO_EE_ORIGIN_LOCAL"))
214 ((:icmp "SO_EE_ORIGIN_ICMP"))
215 ((:icmp6 "SO_EE_ORIGIN_ICMP6"))
216 ((:timestamping "SO_EE_ORIGIN_TIMESTAMPING")))
218 (cstruct sock-extended-err "struct sock_extended_err"
219 (errno "ee_errno" :type :uint32)
220 (origin "ee_origin" :type extended-error-origin)
221 (type "ee_type" :type :uint8)
222 (code "ee_code" :type :uint8)
223 (info "ee_info" :type :uint8)
224 (data "ee_data" :type :uint8)))
226 ;; RAW options
227 #+linux
228 (progn
229 (constant (icmp-filter "ICMP_FILTER"))
231 (constantenum (icmp-types :define-constants t)
232 ((:icmp-echo-request "ICMP_ECHO"))
233 ((:icmp-echo-reply "ICMP_ECHOREPLY"))
234 ((:icmp-dest-unreach "ICMP_DEST_UNREACH"))
235 ((:icmp-source-quench "ICMP_SOURCE_QUENCH"))
236 ((:icmp-redirect "ICMP_REDIRECT"))
237 ((:icmp-time-exceeded "ICMP_TIME_EXCEEDED"))
238 ((:icmp-parameter-prob "ICMP_PARAMETERPROB"))
239 ((:icmp-timestamp-request "ICMP_TIMESTAMP"))
240 ((:icmp-timestamp-reply "ICMP_TIMESTAMPREPLY"))
241 ((:icmp-info-request "ICMP_INFO_REQUEST"))
242 ((:icmp-info-reply "ICMP_INFO_REPLY"))
243 ((:icmp-address-request "ICMP_ADDRESS"))
244 ((:icmp-address-reply "ICMP_ADDRESSREPLY")))
246 (constantenum (icmp-unreach :define-constants t)
247 ((:icmp-net-unreach "ICMP_NET_UNREACH"))
248 ((:icmp-host-unreach "ICMP_HOST_UNREACH"))
249 ((:icmp-prot-unreach "ICMP_PROT_UNREACH"))
250 ((:icmp-port-unreach "ICMP_PORT_UNREACH"))
251 ((:icmp-frag-needed "ICMP_FRAG_NEEDED"))
252 ((:icmp-sr-failed "ICMP_SR_FAILED"))
253 ((:icmp-net-unknown "ICMP_NET_UNKNOWN"))
254 ((:icmp-host-unknown "ICMP_HOST_UNKNOWN"))
255 ((:icmp-host-isolated "ICMP_HOST_ISOLATED"))
256 ((:icmp-net-ano "ICMP_NET_ANO"))
257 ((:icmp-host-ano "ICMP_HOST_ANO"))
258 ((:icmp-net-unr-tos "ICMP_NET_UNR_TOS"))
259 ((:icmp-host-unr-tos "ICMP_HOST_UNR_TOS"))
260 ((:icmp-pkt-filtered "ICMP_PKT_FILTERED"))
261 ((:icmp-prec-violation "ICMP_PREC_VIOLATION"))
262 ((:icmp-prec-cutoff "ICMP_PREC_CUTOFF")))
264 (constantenum (icmp-redirect :define-constants t)
265 ((:icmp-redir-net "ICMP_REDIR_NET"))
266 ((:icmp-redir-host "ICMP_REDIR_HOST"))
267 ((:icmp-redir-nettos "ICMP_REDIR_NETTOS"))
268 ((:icmp-redir-hosttos "ICMP_REDIR_HOSTTOS")))
270 (constantenum (icmp-time-exceeded :define-constants t)
271 ((:icmp-exc-ttl "ICMP_EXC_TTL"))
272 ((:icmp-exc-fragtime "ICMP_EXC_FRAGTIME"))))
274 ;;; shutdown()
275 (constant (shut-rd "SHUT_RD" "SD_RECEIVE"))
276 (constant (shut-wr "SHUT_WR" "SD_SEND"))
277 (constant (shut-rdwr "SHUT_RDWR" "SD_BOTH"))
279 ;;; recvmsg/sendmsg()
280 (constant (msg-dontroute "MSG_DONTROUTE")) ; sendmsg
281 (constant (msg-oob "MSG_OOB")) ; recvmsg sendmsg
282 (constant (msg-peek "MSG_PEEK")) ; recvmsg
283 (constant (msg-errqueue "MSG_ERRQUEUE") :optional t) ; recvmsg
284 (constant (msg-more "MSG_MORE") :optional t) ; sendmsg
285 (constant (msg-confirm "MSG_CONFIRM") :optional t) ; sendmsg sendmsg
286 (constant (msg-proxy "MSG_PROXY") :optional t) ;
287 (constant (msg-fin "MSG_FIN") :optional t) ;
288 (constant (msg-syn "MSG_SYN") :optional t) ;
289 (constant (msg-eof "MSG_EOF") :optional t) ;
290 (constant (msg-nbio "MSG_NBIO") :optional t) ;
291 (constant (msg-compat "MSG_COMPAT") :optional t) ;
292 (constant (msg-trunc "MSG_TRUNC")) ; recvmsg
293 (constant (msg-waitall "MSG_WAITALL")) ; recvmsg
294 (constant (msg-dontwait "MSG_DONTWAIT")) ; recvmsg sendmsg
295 (constant (msg-nosignal "MSG_NOSIGNAL") :optional t) ; sendmsg
296 (constant (msg-eor "MSG_EOR")) ; recvmsg sendmsg
297 (constant (msg-ctrunc "MSG_CTRUNC")) ; recvmsg
299 (cstruct msghdr "struct msghdr"
300 (name "msg_name" :type :pointer)
301 (namelen "msg_namelen" :type socklen-t)
302 (iov "msg_iov" :type :pointer)
303 (iovlen "msg_iovlen" :type size-t)
304 (control "msg_control" :type :pointer)
305 (controllen "msg_controllen" :type socklen-t)
306 (flags "msg_flags" :type :int))
308 (cstruct cmsghdr "struct cmsghdr"
309 (len "cmsg_len" :type socklen-t)
310 (level "cmsg_level" :type :int)
311 (type "cmsg_type" :type :int))
313 #-(and) ; unused
314 (constant (cmgroup-max "CMGROUP_MAX") :optional t)
316 #+(or (or) freebsd) ; unused
317 (cstruct cmsgcred "struct cmsgcred"
318 (pid "cmcred_pid" :type pid-t)
319 (uid "cmcred_uid" :type uid-t)
320 (euid "cmcred_euid" :type uid-t)
321 (gid "cmcred_gid" :type gid-t)
322 (ngroups "cmcred_ngroups" :type :short)
323 (groups "cmcred_groups" :type gid-t :count :auto))
325 (constant (scm-rights "SCM_RIGHTS"))
326 (constant (scm-credentials "SCM_CREDENTIALS") :optional t)
328 #+(and nil linux)
329 (cstruct ucred "struct ucred"
330 "Socket credential messages."
331 (pid "pid" :type pid-t)
332 (uid "uid" :type uid-t)
333 (gid "gid" :type gid-t))
335 #+(and nil freebsd)
336 (cstruct sockcred "struct sockcred"
337 (uid "sc_uid" :type uid-t)
338 (euid "sc_euid" :type uid-t)
339 (gid "sc_gid" :type gid-t)
340 (egid "sc_egid" :type gid-t)
341 (ngroups "sc_ngroups" :type :int)
342 (groups "sc_groups" :type gid-t :count :auto))
344 (cstruct linger "struct linger"
345 "SO_LINGER manipulation record."
346 (onoff "l_onoff" :type :int)
347 (linger "l_linger" :type :int))
349 #+(or freebsd dragonfly)
350 (cstruct accept-filter-arg "struct accept_filter_arg"
351 (name "af_name" :type :uint8 :count :auto)
352 (arg "af_arg" :type :uint8 :count :auto))
354 ;;;; from sys/un.h
356 (cstruct sockaddr-un "struct sockaddr_un"
357 "A UNIX-domain socket address."
358 (family "sun_family" :type sa-family-t)
359 (path "sun_path" :type :uint8 :count :auto))
361 #+dragonfly
362 (constant (local-peercred "LOCAL_PEERCRED"))
364 #+freebsd
365 (progn
366 (constant (local-peercred "LOCAL_PEERCRED"))
367 (constant (local-creds "LOCAL_CREDS"))
368 (constant (local-connwait "LOCAL_CONNWAIT")))
370 ;;;; from netinet/in.h
372 (ctype in-port-t "in_port_t")
373 (ctype in-addr-t "in_addr_t")
375 (cstruct sockaddr-in "struct sockaddr_in"
376 "An IPv4 socket address."
377 (family "sin_family" :type sa-family-t)
378 (port "sin_port" :type in-port-t)
379 (addr "sin_addr" :type in-addr-t))
381 (cstruct in-addr-struct "struct in_addr"
382 (addr "s_addr" :type :uint32))
384 (cunion in6-addr "struct in6_addr"
385 "An IPv6 address."
386 (addr8 "s6_addr" :type :uint8 :count :auto))
388 (cstruct sockaddr-in6 "struct sockaddr_in6"
389 "An IPv6 socket address."
390 (family "sin6_family" :type sa-family-t)
391 (port "sin6_port" :type in-port-t)
392 (flowinfo "sin6_flowinfo" :type :uint32)
393 (addr "sin6_addr" :type (:union in6-addr))
394 (scope-id "sin6_scope_id" :type :uint32))
396 #-(and) ; unused
397 (progn
398 (constant (inaddr-any "INADDR_ANY"))
399 (constant (inaddr-broadcast "INADDR_BROADCAST"))
400 (constant (inaddr-none "INADDR_NONE"))
401 (constant (in-loopbacknet "IN_LOOPBACKNET"))
402 (constant (inaddr-loopback "INADDR_LOOPBACK"))
403 (constant (inaddr-unspec-group "INADDR_UNSPEC_GROUP"))
404 (constant (inaddr-allhosts-group "INADDR_ALLHOSTS_GROUP"))
405 (constant (inaddr-allrtrs-group "INADDR_ALLRTRS_GROUP"))
406 (constant (inaddr-max-local-group "INADDR_MAX_LOCAL_GROUP")))
408 (constant (inet-addrstrlen "INET_ADDRSTRLEN"))
409 (constant (inet6-addrstrlen "INET6_ADDRSTRLEN"))
411 (constant (ipv6-join-group "IPV6_JOIN_GROUP"))
412 (constant (ipv6-leave-group "IPV6_LEAVE_GROUP"))
413 (constant (ipv6-multicast-hops "IPV6_MULTICAST_HOPS"))
414 (constant (ipv6-multicast-if "IPV6_MULTICAST_IF"))
415 (constant (ipv6-multicast-loop "IPV6_MULTICAST_LOOP"))
416 (constant (ipv6-unicast-hops "IPV6_UNICAST_HOPS"))
417 (constant (ipv6-v6only "IPV6_V6ONLY"))
419 ;;;; from netinet/tcp.h
421 #+linux
422 (cenum connstates
423 ((:tcp-established "TCP_ESTABLISHED"))
424 ((:tcp-syn-sent "TCP_SYN_SENT"))
425 ((:tcp-syn-recv "TCP_SYN_RECV"))
426 ((:tcp-fin-wait1 "TCP_FIN_WAIT1"))
427 ((:tcp-fin-wait2 "TCP_FIN_WAIT2"))
428 ((:tcp-time-wait "TCP_TIME_WAIT"))
429 ((:tcp-close "TCP_CLOSE"))
430 ((:tcp-close-wait "TCP_CLOSE_WAIT"))
431 ((:tcp-last-ack "TCP_LAST_ACK"))
432 ((:tcp-listen "TCP_LISTEN"))
433 ((:tcp-closing "TCP_CLOSING")))
435 ;;;; from net/if.h
437 (cstruct if-nameindex "struct if_nameindex"
438 (index "if_index" :type :unsigned-int)
439 (name "if_name" :type :string))
441 (constant (ifnamesize "IF_NAMESIZE"))
442 (constant (ifnamsiz "IFNAMSIZ"))
444 (cstruct ifreq "struct ifreq"
445 (name "ifr_name" :type :char :count :auto))
447 ;;;; from linux/netlink.h
449 #+linux
450 (cstruct sockaddr-nl "struct sockaddr_nl"
451 "A Netlink socket address."
452 (family "nl_family" :type sa-family-t)
453 (port "nl_pid" :type :uint32)
454 (groups "nl_groups" :type :uint32))