Remove duplicate definitions of socket option constants
[iolib.git] / src / sockets / grovel.lisp
blob866f2ec7993c13f740c4f6bed25aa5383d97f7b9
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" "netinet/in.h"
34 "net/if.h" "netinet/tcp.h" "netdb.h" "errno.h"
35 "arpa/inet.h")
37 (in-package :iolib.sockets)
39 (constantenum socket-error-values
40 (:eprotonosupport "EPROTONOSUPPORT")
41 (:esocktnosupport "ESOCKTNOSUPPORT")
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")
69 (:ebadf "EBADF")
70 (:einval "EINVAL")
71 (:enomem "ENOMEM")
72 (:eacces "EACCES")
73 (:efault "EFAULT")
74 (:emfile "EMFILE")
75 (:einprogress "EINPROGRESS")
76 (:ealready "EALREADY")
77 (:eloop "ELOOP")
78 (:enametoolong "ENAMETOOLONG")
79 (:enotempty "ENOTEMPTY")
80 (:eusers "EUSERS")
81 (:edquot "EDQUOT")
82 (:estale "ESTALE"))
84 ;;;; sys/socket.h
86 (ctype socklen-t "socklen_t")
87 (ctype sa-family-t "sa_family_t")
89 ;;; socket() - socket address family
90 (constant (af-unspec "AF_UNSPEC" "PF_UNSPEC"))
91 (constant (af-inet "AF_INET" "PF_INET")
92 :documentation "IPv4 Protocol family")
93 (constant (af-inet6 "AF_INET6" "PF_INET6")
94 :documentation "IPv6 Protocol family")
95 (constant (af-local "AF_UNIX" "AF_LOCAL" "PF_UNIX" "PF_LOCAL")
96 :documentation "File domain sockets")
97 (constant (af-packet "AF_PACKET" "PF_PACKET")
98 :documentation "Raw packet access"
99 :optional t)
100 (constant (af-route "AF_ROUTE" "PF_ROUTE")
101 :documentation "Routing sockets"
102 :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")
109 :documentation "TCP")
110 (constant (sock-dgram "SOCK_DGRAM")
111 :documentation "UDP")
112 (constant (sock-seqpacket "SOCK_SEQPACKET")
113 :documentation "Reliable Sequenced Datagram Protocol"
114 :optional t)
115 (constant (sock-raw "SOCK_RAW")
116 :documentation "Raw protocol access"
117 :optional t)
118 (constant (sock-rdm "SOCK_RDM")
119 :documentation "Reliable Unordered Datagram Protocol"
120 :optional t)
122 ;;; socket() - socket protocol
123 (constant (ipproto-ip "IPPROTO_IP"))
124 (constant (ipproto-ipv6 "IPPROTO_IPV6"))
125 (constant (ipproto-icmp "IPPROTO_ICMP"))
126 (constant (ipproto-icmpv6 "IPPROTO_ICMPV6"))
127 (constant (ipproto-raw "IPPROTO_RAW"))
128 (constant (ipproto-tcp "IPPROTO_TCP"))
129 (constant (ipproto-udp "IPPROTO_UDP"))
130 (constant (ipproto-sctp "IPPROTO_SCTP") :optional t)
132 (cstruct sockaddr "struct sockaddr"
133 (family "sa_family" :type sa-family-t))
135 (cstruct sockaddr-storage "struct sockaddr_storage"
136 (family "ss_family" :type sa-family-t))
138 (constant (somaxconn "SOMAXCONN")
139 :documentation "Maximum listen() queue length")
141 (constant (sol-socket "SOL_SOCKET")
142 :documentation "get/setsockopt socket level constant.")
144 (constant (sol-tcp "SOL_TCP")
145 :documentation "get/setsockopt TCP level constant."
146 :optional t)
147 (constant (sol-ip "SOL_IP")
148 :documentation "get/setsockopt IP level constant."
149 :optional t)
150 (constant (sol-raw "SOL_RAW")
151 :documentation "get/setsockopt raw level constant."
152 :optional t)
154 ;;; getsockopt/setsockopt()
155 (constant (so-acceptconn "SO_ACCEPTCONN"))
156 (constant (so-acceptfilter "SO_ACCEPTFILTER") :optional t) ; freebsd
157 (constant (so-bindtodevice "SO_BINDTODEVICE") :optional t) ; linux
158 (constant (so-bintime "SO_BINTIME") :optional t) ; freebsd
159 (constant (so-broadcast "SO_BROADCAST"))
160 (constant (so-debug "SO_DEBUG"))
161 (constant (so-dontroute "SO_DONTROUTE"))
162 (constant (so-error "SO_ERROR"))
163 (constant (so-keepalive "SO_KEEPALIVE"))
164 (constant (so-label "SO_LABEL") :optional t) ; freebsd
165 (constant (so-linger "SO_LINGER"))
166 (constant (so-listenincqlen "SO_LISTENINCQLEN") :optional t) ; freebsd
167 (constant (so-listenqlen "SO_LISTENQLEN") :optional t) ; freebsd
168 (constant (so-listenqlimit "SO_LISTENQLIMIT") :optional t) ; freebsd
169 (constant (so-nosigpipe "SO_NOSIGPIPE") :optional t) ; freebsd
170 (constant (so-oobinline "SO_OOBINLINE"))
171 (constant (so-passcred "SO_PASSCRED") :optional t) ; linux
172 (constant (so-peercred "SO_PEERCRED") :optional t) ; linux
173 (constant (so-peerlabel "SO_PEERLABEL") :optional t) ; freebsd
174 (constant (so-priority "SO_PRIORITY") :optional t) ; linux
175 (constant (so-rcvbuf "SO_RCVBUF"))
176 (constant (so-rcvlowat "SO_RCVLOWAT"))
177 (constant (so-rcvtimeo "SO_RCVTIMEO"))
178 (constant (so-reuseaddr "SO_REUSEADDR"))
179 (constant (so-reuseport "SO_REUSEPORT") :optional t) ; freebsd
180 (constant (so-sndbuf "SO_SNDBUF"))
181 (constant (so-sndlowat "SO_SNDLOWAT"))
182 (constant (so-sndtimeo "SO_SNDTIMEO"))
183 (constant (so-timestamp "SO_TIMESTAMP"))
184 (constant (so-type "SO_TYPE"))
185 (constant (so-useloopback "SO_USELOOPBACK") :optional t) ; freebsd
187 ;; TCP options
188 (constant (tcp-cork "TCP_CORK") :optional t) ; linux
189 (constant (tcp-defer-accept "TCP_DEFER_ACCEPT") :optional t) ; linux
190 (constant (tcp-info "TCP_INFO") :optional t) ; linux
191 (constant (tcp-keepcnt "TCP_KEEPCNT") :optional t) ; linux
192 (constant (tcp-keepidle "TCP_KEEPIDLE") :optional t) ; linux
193 (constant (tcp-keepintvl "TCP_KEEPINTVL") :optional t) ; linux
194 (constant (tcp-linger2 "TCP_LINGER2") :optional t) ; linux
195 (constant (tcp-maxseg "TCP_MAXSEG") :optional t) ; linux, freebsd
196 (constant (tcp-nodelay "TCP_NODELAY") :optional t) ; linux, freebsd
197 (constant (tcp-noopt "TCP_NOOPT") :optional t) ; freebsd
198 (constant (tcp-nopush "TCP_NOPUSH") :optional t) ; freebsd
199 (constant (tcp-quickack "TCP_QUICKACK") :optional t) ; linux
200 (constant (tcp-syncnt "TCP_SYNCNT") :optional t) ; linux
201 (constant (tcp-window-clamp "TCP_WINDOW_CLAMP") :optional t) ; linux
203 ;; IP options
204 (constant (ip-hdrincl "IP_HDRINCL") :optional t)
206 ;;; shutdown()
207 (constant (shut-rd "SHUT_RD" "SD_RECEIVE"))
208 (constant (shut-wr "SHUT_WR" "SD_SEND"))
209 (constant (shut-rdwr "SHUT_RDWR" "SD_BOTH"))
211 ;;; recvmsg/sendmsg()
212 (constant (msg-dontroute "MSG_DONTROUTE")) ; sendmsg
213 (constant (msg-oob "MSG_OOB")) ; recvmsg sendmsg
214 (constant (msg-peek "MSG_PEEK")) ; recvmsg
215 (constant (msg-errqueue "MSG_ERRQUEUE") :optional t) ; recvmsg
216 (constant (msg-more "MSG_MORE") :optional t) ; sendmsg
217 (constant (msg-confirm "MSG_CONFIRM") :optional t) ; sendmsg sendmsg
218 (constant (msg-proxy "MSG_PROXY") :optional t) ;
219 (constant (msg-fin "MSG_FIN") :optional t) ;
220 (constant (msg-syn "MSG_SYN") :optional t) ;
221 (constant (msg-eof "MSG_EOF") :optional t) ;
222 (constant (msg-nbio "MSG_NBIO") :optional t) ;
223 (constant (msg-compat "MSG_COMPAT") :optional t) ;
224 (constant (msg-trunc "MSG_TRUNC")) ; recvmsg
225 (constant (msg-waitall "MSG_WAITALL")) ; recvmsg
226 (constant (msg-dontwait "MSG_DONTWAIT")) ; recvmsg sendmsg
227 #-darwin (constant (msg-nosignal "MSG_NOSIGNAL")) ; sendmsg
228 (constant (msg-eor "MSG_EOR")) ; recvmsg sendmsg
229 (constant (msg-ctrunc "MSG_CTRUNC")) ; recvmsg
231 (cstruct msghdr "struct msghdr"
232 (name "msg_name" :type :pointer)
233 (namelen "msg_namelen" :type socklen-t)
234 (iov "msg_iov" :type :pointer)
235 (iovlen "msg_iovlen" :type size-t)
236 (control "msg_control" :type :pointer)
237 (controllen "msg_controllen" :type socklen-t)
238 (flags "msg_flags" :type :int))
240 (cstruct cmsghdr "struct cmsghdr"
241 (len "cmsg_len" :type socklen-t)
242 (level "cmsg_level" :type :int)
243 (type "cmsg_type" :type :int))
245 #-(and) ; unused
246 (constant (cmgroup-max "CMGROUP_MAX") :optional t)
248 #+(or (or) freebsd) ; unused
249 (cstruct cmsgcred "struct cmsgcred"
250 (pid "cmcred_pid" :type pid-t)
251 (uid "cmcred_uid" :type uid-t)
252 (euid "cmcred_euid" :type uid-t)
253 (gid "cmcred_gid" :type gid-t)
254 (ngroups "cmcred_ngroups" :type :short)
255 (groups "cmcred_groups" :type gid-t :count :auto))
257 (constant (scm-rights "SCM_RIGHTS"))
258 (constant (scm-credentials "SCM_CREDENTIALS") :optional t)
260 #+(and nil linux)
261 (cstruct ucred "struct ucred"
262 "Socket credential messages."
263 (pid "pid" :type pid-t)
264 (uid "uid" :type uid-t)
265 (gid "gid" :type gid-t))
267 #+(and nil freebsd)
268 (cstruct sockcred "struct sockcred"
269 (uid "sc_uid" :type uid-t)
270 (euid "sc_euid" :type uid-t)
271 (gid "sc_gid" :type gid-t)
272 (egid "sc_egid" :type gid-t)
273 (ngroups "sc_ngroups" :type :int)
274 (groups "sc_groups" :type gid-t :count :auto))
276 (cstruct linger "struct linger"
277 "SO_LINGER manipulation record."
278 (onoff "l_onoff" :type :int)
279 (linger "l_linger" :type :int))
281 #+freebsd
282 (cstruct accept-filter-arg "struct accept_filter_arg"
283 (name "af_name" :type :uint8 :count :auto)
284 (arg "af_arg" :type :uint8 :count :auto))
286 ;;;; from sys/un.h
288 (cstruct sockaddr-un "struct sockaddr_un"
289 "A UNIX-domain socket address."
290 (family "sun_family" :type sa-family-t)
291 (path "sun_path" :type :uint8 :count :auto))
293 #+freebsd
294 (progn
295 (constant (local-peercred "LOCAL_PEERCRED"))
296 (constant (local-creds "LOCAL_CREDS"))
297 (constant (local-connwait "LOCAL_CONNWAIT")))
299 ;;;; from netinet/in.h
301 (ctype in-port-t "in_port_t")
302 (ctype in-addr-t "in_addr_t")
304 (cstruct sockaddr-in "struct sockaddr_in"
305 "An IPv4 socket address."
306 (family "sin_family" :type sa-family-t)
307 (port "sin_port" :type in-port-t)
308 (addr "sin_addr" :type in-addr-t))
310 (cstruct in-addr-struct "struct in_addr"
311 (addr "s_addr" :type :uint32))
313 (cunion in6-addr "struct in6_addr"
314 "An IPv6 address."
315 (addr8 "s6_addr" :type :uint8 :count :auto))
317 (cstruct sockaddr-in6 "struct sockaddr_in6"
318 "An IPv6 socket address."
319 (family "sin6_family" :type sa-family-t)
320 (port "sin6_port" :type in-port-t)
321 (flowinfo "sin6_flowinfo" :type :uint32)
322 (addr "sin6_addr" :type in6-addr)
323 (scope-id "sin6_scope_id" :type :uint32))
325 #-(and) ; unused
326 (progn
327 (constant (inaddr-any "INADDR_ANY"))
328 (constant (inaddr-broadcast "INADDR_BROADCAST"))
329 (constant (inaddr-none "INADDR_NONE"))
330 (constant (in-loopbacknet "IN_LOOPBACKNET"))
331 (constant (inaddr-loopback "INADDR_LOOPBACK"))
332 (constant (inaddr-unspec-group "INADDR_UNSPEC_GROUP"))
333 (constant (inaddr-allhosts-group "INADDR_ALLHOSTS_GROUP"))
334 (constant (inaddr-allrtrs-group "INADDR_ALLRTRS_GROUP"))
335 (constant (inaddr-max-local-group "INADDR_MAX_LOCAL_GROUP")))
337 (constant (inet-addrstrlen "INET_ADDRSTRLEN"))
338 (constant (inet6-addrstrlen "INET6_ADDRSTRLEN"))
340 (constant (ipv6-join-group "IPV6_JOIN_GROUP"))
341 (constant (ipv6-leave-group "IPV6_LEAVE_GROUP"))
342 (constant (ipv6-multicast-hops "IPV6_MULTICAST_HOPS"))
343 (constant (ipv6-multicast-if "IPV6_MULTICAST_IF"))
344 (constant (ipv6-multicast-loop "IPV6_MULTICAST_LOOP"))
345 (constant (ipv6-unicast-hops "IPV6_UNICAST_HOPS"))
346 (constant (ipv6-v6only "IPV6_V6ONLY"))
348 ;;;; from netinet/tcp.h
350 #+linux
351 (cenum connstates
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"))
364 ;;;; from net/if.h
366 (cstruct if-nameindex "struct if_nameindex"
367 (index "if_index" :type :unsigned-int)
368 (name "if_name" :type :string))
370 (constant (ifnamesize "IF_NAMESIZE"))
371 (constant (ifnamsiz "IFNAMSIZ"))
373 (cstruct ifreq "struct ifreq"
374 (name "ifr_name" :type :char :count :auto))