Better buffer synchronization macro.
[iolib/alendvai.git] / net.sockets / grovel.lisp
blob42e84be4830721ca729ffce9b02f8725e3f29e08
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
2 ;;;
3 ;;; --- Grovelling for socket constants and types.
4 ;;;
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>
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 :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"))
70 ((:eagain "EAGAIN"))
71 ((:ebadf "EBADF"))
72 ((:eintr "EINTR"))
73 ((:einval "EINVAL"))
74 ((:enomem "ENOMEM"))
75 ((:eacces "EACCES"))
76 ((:efault "EFAULT"))
77 ((:emfile "EMFILE"))
78 ((:einprogress "EINPROGRESS"))
79 ((:ealready "EALREADY"))
80 ((:eloop "ELOOP"))
81 ((:enametoolong "ENAMETOOLONG"))
82 ((:enotempty "ENOTEMPTY"))
83 ((:eusers "EUSERS"))
84 ((:edquot "EDQUOT"))
85 ((:estale "ESTALE")))
87 ;;;; sys/socket.h
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"
100 :optional t)
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"
113 :optional t)
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.")
139 #+linux
140 (progn
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
196 ;;; shutdown()
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
221 (cstruct msghdr "struct msghdr"
222 (name "msg_name" :type :pointer)
223 (namelen "msg_namelen" :type socklen)
224 (iov "msg_iov" :type :pointer)
225 (iovlen "msg_iovlen" :type size)
226 (control "msg_control" :type :pointer)
227 (controllen "msg_controllen" :type socklen)
228 (flags "msg_flags" :type :int))
230 (cstruct cmsghdr "struct cmsghdr"
231 (len "cmsg_len" :type socklen)
232 (level "cmsg_level" :type :int)
233 (type "cmsg_type" :type :int))
235 #-(and) ; unused
236 (constant (cmgroup-max "CMGROUP_MAX") :optional t)
238 #+(or (or) freebsd) ; unused
239 (cstruct cmsgcred "struct cmsgcred"
240 (pid "cmcred_pid" :type pid)
241 (uid "cmcred_uid" :type uid)
242 (euid "cmcred_euid" :type uid)
243 (gid "cmcred_gid" :type gid)
244 (ngroups "cmcred_ngroups" :type :short)
245 (groups "cmcred_groups" :type gid :count :auto))
247 (constant (scm-rights "SCM_RIGHTS"))
248 (constant (scm-credentials "SCM_CREDENTIALS") :optional t)
250 #+linux
251 (cstruct ucred "struct ucred"
252 "Socket credential messages."
253 (pid "pid" :type pid)
254 (uid "uid" :type uid)
255 (gid "gid" :type gid))
257 #+freebsd
258 (cstruct sockcred "struct sockcred"
259 (uid "sc_uid" :type uid)
260 (euid "sc_euid" :type uid)
261 (gid "sc_gid" :type gid)
262 (egid "sc_egid" :type gid)
263 (ngroups "sc_ngroups" :type :int)
264 (groups "sc_groups" :type gid :count :auto))
266 (cstruct linger "struct linger"
267 "SO_LINGER manipulation record."
268 (onoff "l_onoff" :type :int)
269 (linger "l_linger" :type :int))
271 #+freebsd
272 (cstruct accept-filter-arg "struct accept_filter_arg"
273 (name "af_name" :type :uint8 :count :auto)
274 (arg "af_arg" :type :uint8 :count :auto))
276 ;;;; from sys/un.h
278 (cstruct sockaddr-un "struct sockaddr_un"
279 "A UNIX-domain socket address."
280 (family "sun_family" :type sa-family)
281 (path "sun_path" :type :uint8 :count :auto))
283 #+freebsd
284 (progn
285 (constant (local-peercred "LOCAL_PEERCRED"))
286 (constant (local-creds "LOCAL_CREDS"))
287 (constant (local-connwait "LOCAL_CONNWAIT")))
289 ;;;; from netinet/in.h
291 (ctype in-port "in_port_t")
292 (ctype in-addr "in_addr_t")
294 (cstruct sockaddr-in "struct sockaddr_in"
295 "An IPv4 socket address."
296 (family "sin_family" :type sa-family)
297 (port "sin_port" :type in-port)
298 (addr "sin_addr" :type in-addr))
300 (cstruct in-addr-struct "struct in_addr"
301 (addr "s_addr" :type :uint32))
303 (cunion in6-addr "struct in6_addr"
304 "An IPv6 address."
305 (addr8 "s6_addr" :type :uint8 :count :auto)
306 (addr16 "s6_addr16" :type :uint16 :count :auto)
307 (addr32 "s6_addr32" :type :uint32 :count :auto))
309 (cstruct sockaddr-in6 "struct sockaddr_in6"
310 "An IPv6 socket address."
311 (family "sin6_family" :type sa-family)
312 (port "sin6_port" :type in-port)
313 (flowinfo "sin6_flowinfo" :type :uint32)
314 (addr "sin6_addr" :type in6-addr)
315 (scope-id "sin6_scope_id" :type :uint32))
317 #-(and) ; unused
318 (progn
319 (constant (inaddr-any "INADDR_ANY"))
320 (constant (inaddr-broadcast "INADDR_BROADCAST"))
321 (constant (inaddr-none "INADDR_NONE"))
322 (constant (in-loopbacknet "IN_LOOPBACKNET"))
323 (constant (inaddr-loopback "INADDR_LOOPBACK"))
324 (constant (inaddr-unspec-group "INADDR_UNSPEC_GROUP"))
325 (constant (inaddr-allhosts-group "INADDR_ALLHOSTS_GROUP"))
326 (constant (inaddr-allrtrs-group "INADDR_ALLRTRS_GROUP"))
327 (constant (inaddr-max-local-group "INADDR_MAX_LOCAL_GROUP")))
329 (constant (inet-addrstrlen "INET_ADDRSTRLEN"))
330 (constant (inet6-addrstrlen "INET6_ADDRSTRLEN"))
332 (constant (ipv6-join-group "IPV6_JOIN_GROUP"))
333 (constant (ipv6-leave-group "IPV6_LEAVE_GROUP"))
334 (constant (ipv6-multicast-hops "IPV6_MULTICAST_HOPS"))
335 (constant (ipv6-multicast-if "IPV6_MULTICAST_IF"))
336 (constant (ipv6-multicast-loop "IPV6_MULTICAST_LOOP"))
337 (constant (ipv6-unicast-hops "IPV6_UNICAST_HOPS"))
338 (constant (ipv6-v6only "IPV6_V6ONLY"))
340 ;;;; from netinet/tcp.h
342 (constant (tcp-nodelay "TCP_NODELAY"))
343 (constant (tcp-maxseg "TCP_MAXSEG"))
344 #+linux
345 (constant (tcp-cork "TCP_CORK"))
346 (constant (tcp-keepidle "TCP_KEEPIDLE") :optional t)
347 (constant (tcp-keepintvl "TCP_KEEPINTVL") :optional t)
348 (constant (tcp-keepcnt "TCP_KEEPCNT") :optional t)
349 (constant (tcp-syncnt "TCP_SYNCNT") :optional t)
350 (constant (tcp-linger2 "TCP_LINGER2") :optional t)
351 (constant (tcp-defer-accept "TCP_DEFER_ACCEPT") :optional t)
352 (constant (tcp-window-clamp "TCP_WINDOW_CLAMP") :optional t)
353 #-darwin (constant (tcp-info "TCP_INFO"))
354 (constant (tcp-quickack "TCP_QUICKACK") :optional t)
356 #+linux
357 (cenum connstates
358 ((:tcp-established "TCP_ESTABLISHED"))
359 ((:tcp-syn-sent "TCP_SYN_SENT"))
360 ((:tcp-syn-recv "TCP_SYN_RECV"))
361 ((:tcp-fin-wait1 "TCP_FIN_WAIT1"))
362 ((:tcp-fin-wait2 "TCP_FIN_WAIT2"))
363 ((:tcp-time-wait "TCP_TIME_WAIT"))
364 ((:tcp-close "TCP_CLOSE"))
365 ((:tcp-close-wait "TCP_CLOSE_WAIT"))
366 ((:tcp-last-ack "TCP_LAST_ACK"))
367 ((:tcp-listen "TCP_LISTEN"))
368 ((:tcp-closing "TCP_CLOSING")))
370 ;;;; from net/if.h
372 (cstruct if-nameindex "struct if_nameindex"
373 (index "if_index" :type :unsigned-int)
374 (name "if_name" :type :string))
376 (constant (ifnamesize "IF_NAMESIZE"))
377 (constant (ifnamsiz "IFNAMSIZ"))
379 (cstruct ifreq "struct ifreq"
380 (name "ifr_name" :type :char :count :auto))