6369d40f3c93e974a403c3c1f0f551afa631f46c
[iolib.git] / src / sockets / grovel.lisp
blob6369d40f3c93e974a403c3c1f0f551afa631f46c
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"
34 "net/if.h" "netinet/in.h" "netinet/tcp.h" "netinet/ip.h"
35 #+linux "linux/errqueue.h" #+linux "linux/icmp.h"
36 "arpa/inet.h")
38 (in-package :iolib.sockets)
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")
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")
70 (:ebadf "EBADF")
71 (:einval "EINVAL")
72 (:enomem "ENOMEM")
73 (:eacces "EACCES")
74 (:efault "EFAULT")
75 (:emfile "EMFILE")
76 (:einprogress "EINPROGRESS")
77 (:ealready "EALREADY")
78 (:eloop "ELOOP")
79 (:enametoolong "ENAMETOOLONG")
80 (:enotempty "ENOTEMPTY")
81 (:eusers "EUSERS")
82 (:edquot "EDQUOT")
83 (:estale "ESTALE"))
85 ;;;; sys/socket.h
87 (ctype socklen-t "socklen_t")
88 (ctype sa-family-t "sa_family_t")
90 ;;; socket() - socket address family
91 (constant (af-unspec "AF_UNSPEC" "PF_UNSPEC"))
92 (constant (af-inet "AF_INET" "PF_INET")
93 :documentation "IPv4 Protocol family")
94 (constant (af-inet6 "AF_INET6" "PF_INET6")
95 :documentation "IPv6 Protocol family")
96 (constant (af-local "AF_UNIX" "AF_LOCAL" "PF_UNIX" "PF_LOCAL")
97 :documentation "File domain sockets")
98 (constant (af-packet "AF_PACKET" "PF_PACKET")
99 :documentation "Raw packet access"
100 :optional t)
101 (constant (af-route "AF_ROUTE" "PF_ROUTE")
102 :documentation "Routing sockets"
103 :optional t)
104 (constant (af-key "AF_KEY" "PF_KEY"))
105 (constant (af-netlink "AF_NETLINK" "PF_NETLINK")
106 :documentation "Linux Netlink sockets" :optional t)
108 ;;; socket() - socket type
109 (constant (sock-stream "SOCK_STREAM")
110 :documentation "TCP")
111 (constant (sock-dgram "SOCK_DGRAM")
112 :documentation "UDP")
113 (constant (sock-seqpacket "SOCK_SEQPACKET")
114 :documentation "Reliable Sequenced Datagram Protocol"
115 :optional t)
116 (constant (sock-raw "SOCK_RAW")
117 :documentation "Raw protocol access"
118 :optional t)
119 (constant (sock-rdm "SOCK_RDM")
120 :documentation "Reliable Unordered Datagram Protocol"
121 :optional t)
123 ;;; socket() - socket protocol
124 (constant (ipproto-ip "IPPROTO_IP"))
125 (constant (ipproto-ipv6 "IPPROTO_IPV6"))
126 (constant (ipproto-icmp "IPPROTO_ICMP"))
127 (constant (ipproto-icmpv6 "IPPROTO_ICMPV6"))
128 (constant (ipproto-raw "IPPROTO_RAW"))
129 (constant (ipproto-tcp "IPPROTO_TCP"))
130 (constant (ipproto-udp "IPPROTO_UDP"))
131 (constant (ipproto-sctp "IPPROTO_SCTP") :optional t)
133 (cstruct sockaddr "struct sockaddr"
134 (family "sa_family" :type sa-family-t))
136 (cstruct sockaddr-storage "struct sockaddr_storage"
137 (family "ss_family" :type sa-family-t))
139 (constant (somaxconn "SOMAXCONN")
140 :documentation "Maximum listen() queue length")
142 (constant (sol-socket "SOL_SOCKET")
143 :documentation "get/setsockopt socket level constant.")
145 (constant (sol-tcp "SOL_TCP")
146 :documentation "get/setsockopt TCP level constant."
147 :optional t)
148 (constant (sol-ip "SOL_IP")
149 :documentation "get/setsockopt IP level constant."
150 :optional t)
151 (constant (sol-raw "SOL_RAW")
152 :documentation "get/setsockopt raw level constant."
153 :optional t)
155 ;;; getsockopt/setsockopt()
156 (constant (so-acceptconn "SO_ACCEPTCONN"))
157 (constant (so-acceptfilter "SO_ACCEPTFILTER") :optional t) ; freebsd
158 (constant (so-bindtodevice "SO_BINDTODEVICE") :optional t) ; linux
159 (constant (so-bintime "SO_BINTIME") :optional t) ; freebsd
160 (constant (so-broadcast "SO_BROADCAST"))
161 (constant (so-debug "SO_DEBUG"))
162 (constant (so-dontroute "SO_DONTROUTE"))
163 (constant (so-error "SO_ERROR"))
164 (constant (so-keepalive "SO_KEEPALIVE"))
165 (constant (so-label "SO_LABEL") :optional t) ; freebsd
166 (constant (so-linger "SO_LINGER"))
167 (constant (so-listenincqlen "SO_LISTENINCQLEN") :optional t) ; freebsd
168 (constant (so-listenqlen "SO_LISTENQLEN") :optional t) ; freebsd
169 (constant (so-listenqlimit "SO_LISTENQLIMIT") :optional t) ; freebsd
170 (constant (so-nosigpipe "SO_NOSIGPIPE") :optional t) ; freebsd
171 (constant (so-oobinline "SO_OOBINLINE"))
172 (constant (so-passcred "SO_PASSCRED") :optional t) ; linux
173 (constant (so-peercred "SO_PEERCRED") :optional t) ; linux
174 (constant (so-peerlabel "SO_PEERLABEL") :optional t) ; freebsd
175 (constant (so-priority "SO_PRIORITY") :optional t) ; linux
176 (constant (so-rcvbuf "SO_RCVBUF"))
177 (constant (so-rcvlowat "SO_RCVLOWAT"))
178 (constant (so-rcvtimeo "SO_RCVTIMEO"))
179 (constant (so-reuseaddr "SO_REUSEADDR"))
180 (constant (so-reuseport "SO_REUSEPORT") :optional t) ; freebsd
181 (constant (so-sndbuf "SO_SNDBUF"))
182 (constant (so-sndlowat "SO_SNDLOWAT"))
183 (constant (so-sndtimeo "SO_SNDTIMEO"))
184 (constant (so-timestamp "SO_TIMESTAMP"))
185 (constant (so-type "SO_TYPE"))
186 (constant (so-useloopback "SO_USELOOPBACK") :optional t) ; freebsd
188 ;; TCP options
189 (constant (tcp-cork "TCP_CORK") :optional t) ; linux
190 (constant (tcp-defer-accept "TCP_DEFER_ACCEPT") :optional t) ; linux
191 (constant (tcp-info "TCP_INFO") :optional t) ; linux
192 (constant (tcp-keepcnt "TCP_KEEPCNT") :optional t) ; linux
193 (constant (tcp-keepidle "TCP_KEEPIDLE") :optional t) ; linux
194 (constant (tcp-keepintvl "TCP_KEEPINTVL") :optional t) ; linux
195 (constant (tcp-linger2 "TCP_LINGER2") :optional t) ; linux
196 (constant (tcp-maxseg "TCP_MAXSEG") :optional t) ; linux, freebsd
197 (constant (tcp-nodelay "TCP_NODELAY") :optional t) ; linux, freebsd
198 (constant (tcp-noopt "TCP_NOOPT") :optional t) ; freebsd
199 (constant (tcp-nopush "TCP_NOPUSH") :optional t) ; freebsd
200 (constant (tcp-quickack "TCP_QUICKACK") :optional t) ; linux
201 (constant (tcp-syncnt "TCP_SYNCNT") :optional t) ; linux
202 (constant (tcp-window-clamp "TCP_WINDOW_CLAMP") :optional t) ; linux
204 ;; IP options
205 (constant (ip-hdrincl "IP_HDRINCL"))
206 (constant (ip-recverr "IP_RECVERR") :optional t)
208 #+linux
209 (progn
210 (cenum extended-error-origin
211 (:none "SO_EE_ORIGIN_NONE")
212 (:local "SO_EE_ORIGIN_LOCAL")
213 (:icmp "SO_EE_ORIGIN_ICMP")
214 (:icmp6 "SO_EE_ORIGIN_ICMP6")
215 (:timestamping "SO_EE_ORIGIN_TIMESTAMPING"))
217 (cstruct sock-extended-err "struct sock_extended_err"
218 (errno "ee_errno" :type :uint32)
219 (origin "ee_origin" :type extended-error-origin)
220 (type "ee_type" :type :uint8)
221 (code "ee_code" :type :uint8)
222 (info "ee_info" :type :uint8)
223 (data "ee_data" :type :uint8)))
225 ;; RAW options
226 #+linux
227 (progn
228 (constant (icmp-filter "ICMP_FILTER"))
230 (constantenum (icmp-types :define-constants t)
231 (:icmp-echo-request "ICMP_ECHO")
232 (:icmp-echo-reply "ICMP_ECHOREPLY")
233 (:icmp-dest-unreach "ICMP_DEST_UNREACH")
234 (:icmp-source-quench "ICMP_SOURCE_QUENCH")
235 (:icmp-redirect "ICMP_REDIRECT")
236 (:icmp-time-exceeded "ICMP_TIME_EXCEEDED")
237 (:icmp-parameter-prob "ICMP_PARAMETERPROB")
238 (:icmp-timestamp-request "ICMP_TIMESTAMP")
239 (:icmp-timestamp-reply "ICMP_TIMESTAMPREPLY")
240 (:icmp-info-request "ICMP_INFO_REQUEST")
241 (:icmp-info-reply "ICMP_INFO_REPLY")
242 (:icmp-address-request "ICMP_ADDRESS")
243 (:icmp-address-reply "ICMP_ADDRESSREPLY"))
245 (constantenum (icmp-unreach :define-constants t)
246 (:icmp-net-unreach "ICMP_NET_UNREACH")
247 (:icmp-host-unreach "ICMP_HOST_UNREACH")
248 (:icmp-prot-unreach "ICMP_PROT_UNREACH")
249 (:icmp-port-unreach "ICMP_PORT_UNREACH")
250 (:icmp-frag-needed "ICMP_FRAG_NEEDED")
251 (:icmp-sr-failed "ICMP_SR_FAILED")
252 (:icmp-net-unknown "ICMP_NET_UNKNOWN")
253 (:icmp-host-unknown "ICMP_HOST_UNKNOWN")
254 (:icmp-host-isolated "ICMP_HOST_ISOLATED")
255 (:icmp-net-ano "ICMP_NET_ANO")
256 (:icmp-host-ano "ICMP_HOST_ANO")
257 (:icmp-net-unr-tos "ICMP_NET_UNR_TOS")
258 (:icmp-host-unr-tos "ICMP_HOST_UNR_TOS")
259 (:icmp-pkt-filtered "ICMP_PKT_FILTERED")
260 (:icmp-prec-violation "ICMP_PREC_VIOLATION")
261 (:icmp-prec-cutoff "ICMP_PREC_CUTOFF"))
263 (constantenum (icmp-redirect :define-constants t)
264 (:icmp-redir-net "ICMP_REDIR_NET")
265 (:icmp-redir-host "ICMP_REDIR_HOST")
266 (:icmp-redir-nettos "ICMP_REDIR_NETTOS")
267 (:icmp-redir-hosttos "ICMP_REDIR_HOSTTOS"))
269 (constantenum (icmp-time-exceeded :define-constants t)
270 (:icmp-exc-ttl "ICMP_EXC_TTL")
271 (:icmp-exc-fragtime "ICMP_EXC_FRAGTIME")))
273 ;;; shutdown()
274 (constant (shut-rd "SHUT_RD" "SD_RECEIVE"))
275 (constant (shut-wr "SHUT_WR" "SD_SEND"))
276 (constant (shut-rdwr "SHUT_RDWR" "SD_BOTH"))
278 ;;; recvmsg/sendmsg()
279 (constant (msg-dontroute "MSG_DONTROUTE")) ; sendmsg
280 (constant (msg-oob "MSG_OOB")) ; recvmsg sendmsg
281 (constant (msg-peek "MSG_PEEK")) ; recvmsg
282 (constant (msg-errqueue "MSG_ERRQUEUE") :optional t) ; recvmsg
283 (constant (msg-more "MSG_MORE") :optional t) ; sendmsg
284 (constant (msg-confirm "MSG_CONFIRM") :optional t) ; sendmsg sendmsg
285 (constant (msg-proxy "MSG_PROXY") :optional t) ;
286 (constant (msg-fin "MSG_FIN") :optional t) ;
287 (constant (msg-syn "MSG_SYN") :optional t) ;
288 (constant (msg-eof "MSG_EOF") :optional t) ;
289 (constant (msg-nbio "MSG_NBIO") :optional t) ;
290 (constant (msg-compat "MSG_COMPAT") :optional t) ;
291 (constant (msg-trunc "MSG_TRUNC")) ; recvmsg
292 (constant (msg-waitall "MSG_WAITALL")) ; recvmsg
293 (constant (msg-dontwait "MSG_DONTWAIT")) ; recvmsg sendmsg
294 (constant (msg-nosignal "MSG_NOSIGNAL") :optional t) ; sendmsg
295 (constant (msg-eor "MSG_EOR")) ; recvmsg sendmsg
296 (constant (msg-ctrunc "MSG_CTRUNC")) ; recvmsg
298 (cstruct msghdr "struct msghdr"
299 (name "msg_name" :type :pointer)
300 (namelen "msg_namelen" :type socklen-t)
301 (iov "msg_iov" :type :pointer)
302 (iovlen "msg_iovlen" :type size-t)
303 (control "msg_control" :type :pointer)
304 (controllen "msg_controllen" :type socklen-t)
305 (flags "msg_flags" :type :int))
307 (cstruct cmsghdr "struct cmsghdr"
308 (len "cmsg_len" :type socklen-t)
309 (level "cmsg_level" :type :int)
310 (type "cmsg_type" :type :int))
312 #-(and) ; unused
313 (constant (cmgroup-max "CMGROUP_MAX") :optional t)
315 #+(or (or) freebsd) ; unused
316 (cstruct cmsgcred "struct cmsgcred"
317 (pid "cmcred_pid" :type pid-t)
318 (uid "cmcred_uid" :type uid-t)
319 (euid "cmcred_euid" :type uid-t)
320 (gid "cmcred_gid" :type gid-t)
321 (ngroups "cmcred_ngroups" :type :short)
322 (groups "cmcred_groups" :type gid-t :count :auto))
324 (constant (scm-rights "SCM_RIGHTS"))
325 (constant (scm-credentials "SCM_CREDENTIALS") :optional t)
327 #+(and nil linux)
328 (cstruct ucred "struct ucred"
329 "Socket credential messages."
330 (pid "pid" :type pid-t)
331 (uid "uid" :type uid-t)
332 (gid "gid" :type gid-t))
334 #+(and nil freebsd)
335 (cstruct sockcred "struct sockcred"
336 (uid "sc_uid" :type uid-t)
337 (euid "sc_euid" :type uid-t)
338 (gid "sc_gid" :type gid-t)
339 (egid "sc_egid" :type gid-t)
340 (ngroups "sc_ngroups" :type :int)
341 (groups "sc_groups" :type gid-t :count :auto))
343 (cstruct linger "struct linger"
344 "SO_LINGER manipulation record."
345 (onoff "l_onoff" :type :int)
346 (linger "l_linger" :type :int))
348 #+freebsd
349 (cstruct accept-filter-arg "struct accept_filter_arg"
350 (name "af_name" :type :uint8 :count :auto)
351 (arg "af_arg" :type :uint8 :count :auto))
353 ;;;; from sys/un.h
355 (cstruct sockaddr-un "struct sockaddr_un"
356 "A UNIX-domain socket address."
357 (family "sun_family" :type sa-family-t)
358 (path "sun_path" :type :uint8 :count :auto))
360 #+freebsd
361 (progn
362 (constant (local-peercred "LOCAL_PEERCRED"))
363 (constant (local-creds "LOCAL_CREDS"))
364 (constant (local-connwait "LOCAL_CONNWAIT")))
366 ;;;; from netinet/in.h
368 (ctype in-port-t "in_port_t")
369 (ctype in-addr-t "in_addr_t")
371 (cstruct sockaddr-in "struct sockaddr_in"
372 "An IPv4 socket address."
373 (family "sin_family" :type sa-family-t)
374 (port "sin_port" :type in-port-t)
375 (addr "sin_addr" :type in-addr-t))
377 (cstruct in-addr-struct "struct in_addr"
378 (addr "s_addr" :type :uint32))
380 (cunion in6-addr "struct in6_addr"
381 "An IPv6 address."
382 (addr8 "s6_addr" :type :uint8 :count :auto))
384 (cstruct sockaddr-in6 "struct sockaddr_in6"
385 "An IPv6 socket address."
386 (family "sin6_family" :type sa-family-t)
387 (port "sin6_port" :type in-port-t)
388 (flowinfo "sin6_flowinfo" :type :uint32)
389 (addr "sin6_addr" :type in6-addr)
390 (scope-id "sin6_scope_id" :type :uint32))
392 #-(and) ; unused
393 (progn
394 (constant (inaddr-any "INADDR_ANY"))
395 (constant (inaddr-broadcast "INADDR_BROADCAST"))
396 (constant (inaddr-none "INADDR_NONE"))
397 (constant (in-loopbacknet "IN_LOOPBACKNET"))
398 (constant (inaddr-loopback "INADDR_LOOPBACK"))
399 (constant (inaddr-unspec-group "INADDR_UNSPEC_GROUP"))
400 (constant (inaddr-allhosts-group "INADDR_ALLHOSTS_GROUP"))
401 (constant (inaddr-allrtrs-group "INADDR_ALLRTRS_GROUP"))
402 (constant (inaddr-max-local-group "INADDR_MAX_LOCAL_GROUP")))
404 (constant (inet-addrstrlen "INET_ADDRSTRLEN"))
405 (constant (inet6-addrstrlen "INET6_ADDRSTRLEN"))
407 (constant (ipv6-join-group "IPV6_JOIN_GROUP"))
408 (constant (ipv6-leave-group "IPV6_LEAVE_GROUP"))
409 (constant (ipv6-multicast-hops "IPV6_MULTICAST_HOPS"))
410 (constant (ipv6-multicast-if "IPV6_MULTICAST_IF"))
411 (constant (ipv6-multicast-loop "IPV6_MULTICAST_LOOP"))
412 (constant (ipv6-unicast-hops "IPV6_UNICAST_HOPS"))
413 (constant (ipv6-v6only "IPV6_V6ONLY"))
415 ;;;; from netinet/tcp.h
417 #+linux
418 (cenum connstates
419 (:tcp-established "TCP_ESTABLISHED")
420 (:tcp-syn-sent "TCP_SYN_SENT")
421 (:tcp-syn-recv "TCP_SYN_RECV")
422 (:tcp-fin-wait1 "TCP_FIN_WAIT1")
423 (:tcp-fin-wait2 "TCP_FIN_WAIT2")
424 (:tcp-time-wait "TCP_TIME_WAIT")
425 (:tcp-close "TCP_CLOSE")
426 (:tcp-close-wait "TCP_CLOSE_WAIT")
427 (:tcp-last-ack "TCP_LAST_ACK")
428 (:tcp-listen "TCP_LISTEN")
429 (:tcp-closing "TCP_CLOSING"))
431 ;;;; from net/if.h
433 (cstruct if-nameindex "struct if_nameindex"
434 (index "if_index" :type :unsigned-int)
435 (name "if_name" :type :string))
437 (constant (ifnamesize "IF_NAMESIZE"))
438 (constant (ifnamsiz "IFNAMSIZ"))
440 (cstruct ifreq "struct ifreq"
441 (name "ifr_name" :type :char :count :auto))