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"))
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 (constant (somaxconn "SOMAXCONN")
134 :documentation
"Maximum listen() queue length")
136 (constant (sol-socket "SOL_SOCKET")
137 :documentation
"get/setsockopt socket level constant.")
141 (constant (sol-tcp "SOL_TCP")
142 :documentation
"get/setsockopt TCP level constant.")
143 (constant (sol-ip "SOL_IP")
144 :documentation
"get/setsockopt IP level constant.")
145 (constant (sol-raw "SOL_RAW")
146 :documentation
"get/setsockopt raw level constant."))
148 ;;; getsockopt/setsockopt()
149 (constant (so-acceptconn "SO_ACCEPTCONN"))
150 (constant (so-acceptfilter "SO_ACCEPTFILTER") :optional t
) ; freebsd
151 (constant (so-bindtodevice "SO_BINDTODEVICE") :optional t
) ; linux
152 (constant (so-bintime "SO_BINTIME") :optional t
) ; freebsd
153 (constant (so-broadcast "SO_BROADCAST"))
154 (constant (so-bsdcompat "SO_BSDCOMPAT") :optional t
) ; linux
155 (constant (so-debug "SO_DEBUG"))
156 (constant (so-dontroute "SO_DONTROUTE"))
157 (constant (so-error "SO_ERROR"))
158 (constant (so-keepalive "SO_KEEPALIVE"))
159 (constant (so-label "SO_LABEL") :optional t
) ; freebsd
160 (constant (so-linger "SO_LINGER"))
161 (constant (so-listenincqlen "SO_LISTENINCQLEN") :optional t
) ; freebsd
162 (constant (so-listenqlen "SO_LISTENQLEN") :optional t
) ; freebsd
163 (constant (so-listenqlimit "SO_LISTENQLIMIT") :optional t
) ; freebsd
164 (constant (so-nosigpipe "SO_NOSIGPIPE") :optional t
) ; freebsd
165 (constant (so-oobinline "SO_OOBINLINE"))
166 (constant (so-passcred "SO_PASSCRED") :optional t
) ; linux
167 (constant (so-peercred "SO_PEERCRED") :optional t
) ; linux
168 (constant (so-peerlabel "SO_PEERLABEL") :optional t
) ; freebsd
169 (constant (so-priority "SO_PRIORITY") :optional t
) ; linux
170 (constant (so-rcvbuf "SO_RCVBUF"))
171 (constant (so-rcvlowat "SO_RCVLOWAT"))
172 (constant (so-rcvtimeo "SO_RCVTIMEO"))
173 (constant (so-reuseaddr "SO_REUSEADDR"))
174 (constant (so-reuseport "SO_REUSEPORT") :optional t
) ; freebsd
175 (constant (so-sndbuf "SO_SNDBUF"))
176 (constant (so-sndlowat "SO_SNDLOWAT"))
177 (constant (so-sndtimeo "SO_SNDTIMEO"))
178 (constant (so-timestamp "SO_TIMESTAMP"))
179 (constant (so-type "SO_TYPE"))
180 (constant (so-useloopback "SO_USELOOPBACK") :optional t
) ; freebsd
181 (constant (tcp-cork "TCP_CORK") :optional t
) ; linux
182 (constant (tcp-defer-accept "TCP_DEFER_ACCEPT") :optional t
) ; linux
183 (constant (tcp-info "TCP_INFO") :optional t
) ; linux
184 (constant (tcp-keepcnt "TCP_KEEPCNT") :optional t
) ; linux
185 (constant (tcp-keepidle "TCP_KEEPIDLE") :optional t
) ; linux
186 (constant (tcp-keepintvl "TCP_KEEPINTVL") :optional t
) ; linux
187 (constant (tcp-linger2 "TCP_LINGER2") :optional t
) ; linux
188 (constant (tcp-maxseg "TCP_MAXSEG") :optional t
) ; linux, freebsd
189 (constant (tcp-nodelay "TCP_NODELAY") :optional t
) ; linux, freebsd
190 (constant (tcp-noopt "TCP_NOOPT") :optional t
) ; freebsd
191 (constant (tcp-nopush "TCP_NOPUSH") :optional t
) ; freebsd
192 (constant (tcp-quickack "TCP_QUICKACK") :optional t
) ; linux
193 (constant (tcp-syncnt "TCP_SYNCNT") :optional t
) ; linux
194 (constant (tcp-window "TCP_WINDOW") :optional t
) ; linux
197 (constant (shut-rd "SHUT_RD" "SD_RECEIVE"))
198 (constant (shut-wr "SHUT_WR" "SD_SEND"))
199 (constant (shut-rdwr "SHUT_RDWR" "SD_BOTH"))
201 ;;; recvmsg/sendmsg()
202 (constant (msg-dontroute "MSG_DONTROUTE")) ; sendmsg
203 (constant (msg-oob "MSG_OOB")) ; recvmsg sendmsg
204 (constant (msg-peek "MSG_PEEK")) ; recvmsg
205 (constant (msg-errqueue "MSG_ERRQUEUE") :optional t
) ; recvmsg
206 (constant (msg-more "MSG_MORE") :optional t
) ; sendmsg
207 (constant (msg-confirm "MSG_CONFIRM") :optional t
) ; sendmsg sendmsg
208 (constant (msg-proxy "MSG_PROXY") :optional t
) ;
209 (constant (msg-fin "MSG_FIN") :optional t
) ;
210 (constant (msg-syn "MSG_SYN") :optional t
) ;
211 (constant (msg-eof "MSG_EOF") :optional t
) ;
212 (constant (msg-nbio "MSG_NBIO") :optional t
) ;
213 (constant (msg-compat "MSG_COMPAT") :optional t
) ;
214 (constant (msg-trunc "MSG_TRUNC")) ; recvmsg
215 (constant (msg-waitall "MSG_WAITALL")) ; recvmsg
216 (constant (msg-dontwait "MSG_DONTWAIT")) ; recvmsg sendmsg
217 #-darwin
(constant (msg-nosignal "MSG_NOSIGNAL")) ; sendmsg
218 (constant (msg-eor "MSG_EOR")) ; recvmsg sendmsg
219 (constant (msg-ctrunc "MSG_CTRUNC")) ; recvmsg
222 (cstruct msghdr
"struct msghdr"
223 (name "msg_name" :type
:pointer
)
224 (namelen "msg_namelen" :type socklen
)
225 (iov "msg_iov" :type
:pointer
)
226 (iovlen "msg_iovlen" :type size
)
227 (control "msg_control" :type
:pointer
)
228 (controllen "msg_controllen" :type socklen
)
229 (flags "msg_flags" :type
:int
))
232 (cstruct cmsghdr
"struct cmsghdr"
233 (len "cmsg_len" :type socklen
)
234 (level "cmsg_level" :type
:int
)
235 (type "cmsg_type" :type
:int
))
238 (constant (cmgroup-max "CMGROUP_MAX") :optional t
)
240 #+(or (or) freebsd
) ; unused
241 (cstruct cmsgcred
"struct cmsgcred"
242 (pid "cmcred_pid" :type pid
)
243 (uid "cmcred_uid" :type uid
)
244 (euid "cmcred_euid" :type uid
)
245 (gid "cmcred_gid" :type gid
)
246 (ngroups "cmcred_ngroups" :type
:short
)
247 (groups "cmcred_groups" :type gid
:count
:auto
))
250 (constant (scm-rights "SCM_RIGHTS"))
251 (constant (scm-credentials "SCM_CREDENTIALS") :optional t
)
254 (cstruct ucred
"struct ucred"
255 "Socket credential messages."
256 (pid "pid" :type pid
)
257 (uid "uid" :type uid
)
258 (gid "gid" :type gid
))
261 (cstruct sockcred
"struct sockcred"
262 (uid "sc_uid" :type uid
)
263 (euid "sc_euid" :type uid
)
264 (gid "sc_gid" :type gid
)
265 (egid "sc_egid" :type gid
)
266 (ngroups "sc_ngroups" :type
:int
)
267 (groups "sc_groups" :type gid
:count
:auto
))
269 (cstruct linger
"struct linger"
270 "SO_LINGER manipulation record."
271 (onoff "l_onoff" :type
:int
)
272 (linger "l_linger" :type
:int
))
275 (cstruct accept-filter-arg
"struct accept_filter_arg"
276 (name "af_name" :type
:uint8
:count
:auto
)
277 (arg "af_arg" :type
:uint8
:count
:auto
))
281 (cstruct sockaddr-un
"struct sockaddr_un"
282 "A UNIX-domain socket address."
283 (family "sun_family" :type sa-family
)
284 (path "sun_path" :type
:uint8
:count
:auto
))
288 (constant (local-peercred "LOCAL_PEERCRED"))
289 (constant (local-creds "LOCAL_CREDS"))
290 (constant (local-connwait "LOCAL_CONNWAIT")))
292 ;;;; from netinet/in.h
294 (ctype in-port
"in_port_t")
295 (ctype in-addr
"in_addr_t")
297 (cstruct sockaddr-in
"struct sockaddr_in"
298 "An IPv4 socket address."
299 (family "sin_family" :type sa-family
)
300 (port "sin_port" :type in-port
)
301 (addr "sin_addr" :type in-addr
))
303 (cstruct in-addr-struct
"struct in_addr"
304 (addr "s_addr" :type
:uint32
))
306 (cunion in6-addr
"struct in6_addr"
308 (addr8 "s6_addr" :type
:uint8
:count
:auto
)
309 (addr16 "s6_addr16" :type
:uint16
:count
:auto
)
310 (addr32 "s6_addr32" :type
:uint32
:count
:auto
))
312 (cstruct sockaddr-in6
"struct sockaddr_in6"
313 "An IPv6 socket address."
314 (family "sin6_family" :type sa-family
)
315 (port "sin6_port" :type in-port
)
316 (flowinfo "sin6_flowinfo" :type
:uint32
)
317 (addr "sin6_addr" :type in6-addr
)
318 (scope-id "sin6_scope_id" :type
:uint32
))
322 (constant (inaddr-any "INADDR_ANY"))
323 (constant (inaddr-broadcast "INADDR_BROADCAST"))
324 (constant (inaddr-none "INADDR_NONE"))
325 (constant (in-loopbacknet "IN_LOOPBACKNET"))
326 (constant (inaddr-loopback "INADDR_LOOPBACK"))
327 (constant (inaddr-unspec-group "INADDR_UNSPEC_GROUP"))
328 (constant (inaddr-allhosts-group "INADDR_ALLHOSTS_GROUP"))
329 (constant (inaddr-allrtrs-group "INADDR_ALLRTRS_GROUP"))
330 (constant (inaddr-max-local-group "INADDR_MAX_LOCAL_GROUP")))
332 (constant (inet-addrstrlen "INET_ADDRSTRLEN"))
333 (constant (inet6-addrstrlen "INET6_ADDRSTRLEN"))
335 (constant (ipv6-join-group "IPV6_JOIN_GROUP"))
336 (constant (ipv6-leave-group "IPV6_LEAVE_GROUP"))
337 (constant (ipv6-multicast-hops "IPV6_MULTICAST_HOPS"))
338 (constant (ipv6-multicast-if "IPV6_MULTICAST_IF"))
339 (constant (ipv6-multicast-loop "IPV6_MULTICAST_LOOP"))
340 (constant (ipv6-unicast-hops "IPV6_UNICAST_HOPS"))
341 (constant (ipv6-v6only "IPV6_V6ONLY"))
343 ;;;; from netinet/tcp.h
345 (constant (tcp-nodelay "TCP_NODELAY"))
346 (constant (tcp-maxseg "TCP_MAXSEG"))
348 (constant (tcp-cork "TCP_CORK"))
349 (constant (tcp-keepidle "TCP_KEEPIDLE") :optional t
)
350 (constant (tcp-keepintvl "TCP_KEEPINTVL") :optional t
)
351 (constant (tcp-keepcnt "TCP_KEEPCNT") :optional t
)
352 (constant (tcp-syncnt "TCP_SYNCNT") :optional t
)
353 (constant (tcp-linger2 "TCP_LINGER2") :optional t
)
354 (constant (tcp-defer-accept "TCP_DEFER_ACCEPT") :optional t
)
355 (constant (tcp-window-clamp "TCP_WINDOW_CLAMP") :optional t
)
356 #-darwin
(constant (tcp-info "TCP_INFO"))
357 (constant (tcp-quickack "TCP_QUICKACK") :optional t
)
361 ((:tcp-established
"TCP_ESTABLISHED"))
362 ((:tcp-syn-sent
"TCP_SYN_SENT"))
363 ((:tcp-syn-recv
"TCP_SYN_RECV"))
364 ((:tcp-fin-wait1
"TCP_FIN_WAIT1"))
365 ((:tcp-fin-wait2
"TCP_FIN_WAIT2"))
366 ((:tcp-time-wait
"TCP_TIME_WAIT"))
367 ((:tcp-close
"TCP_CLOSE"))
368 ((:tcp-close-wait
"TCP_CLOSE_WAIT"))
369 ((:tcp-last-ack
"TCP_LAST_ACK"))
370 ((:tcp-listen
"TCP_LISTEN"))
371 ((:tcp-closing
"TCP_CLOSING")))
375 (cstruct if-nameindex
"struct if_nameindex"
376 (index "if_index" :type
:unsigned-int
)
377 (name "if_name" :type
:string
))
379 (constant (ifnamesize "IF_NAMESIZE"))
380 (constant (ifnamsiz "IFNAMSIZ"))
382 (cstruct ifreq
"struct ifreq"
383 (name "ifr_name" :type
:char
:count
:auto
))