Make sure that OPEN-STREAM-P works on stream sockets.
[iolib.git] / src / sockets / grovel.lisp
blob9a35726ad34f7f0d4c18f9ff6c613288cd45e256
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") :documentation "IPv4 Protocol family")
92 (constant (af-inet6 "AF_INET6" "PF_INET6")
93 :documentation "IPv6 Protocol family")
94 (constant (af-local "AF_UNIX" "AF_LOCAL" "PF_UNIX" "PF_LOCAL")
95 :documentation "File domain sockets")
96 (constant (af-packet "AF_PACKET" "PF_PACKET") :documentation "Raw packet access"
97 :optional t)
98 (constant (af-route "AF_ROUTE" "PF_ROUTE")
99 :documentation "Routing sockets" :optional t)
100 (constant (af-key "AF_KEY" "PF_KEY"))
101 (constant (af-netlink "AF_NETLINK" "PF_NETLINK")
102 :documentation "Linux Netlink sockets" :optional t)
104 ;;; socket() - socket type
105 (constant (sock-stream "SOCK_STREAM") :documentation "TCP")
106 (constant (sock-dgram "SOCK_DGRAM") :documentation "UDP")
107 (constant (sock-seqpacket "SOCK_SEQPACKET")
108 :documentation "Reliable Sequenced Datagram Protocol" :optional t)
109 (constant (sock-raw "SOCK_RAW") :documentation "Raw protocol access"
110 :optional t)
111 (constant (sock-rdm "SOCK_RDM")
112 :documentation "Reliable Unordered Datagram Protocol" :optional t)
114 ;;; socket() - socket protocol
115 (constant (ipproto-ip "IPPROTO_IP"))
116 (constant (ipproto-ipv6 "IPPROTO_IPV6"))
117 (constant (ipproto-icmp "IPPROTO_ICMP"))
118 (constant (ipproto-icmpv6 "IPPROTO_ICMPV6"))
119 (constant (ipproto-raw "IPPROTO_RAW"))
120 (constant (ipproto-tcp "IPPROTO_TCP"))
121 (constant (ipproto-udp "IPPROTO_UDP"))
122 #-darwin (constant (ipproto-sctp "IPPROTO_SCTP"))
124 (cstruct sockaddr "struct sockaddr"
125 (family "sa_family" :type sa-family-t))
127 (cstruct sockaddr-storage "struct sockaddr_storage"
128 (family "ss_family" :type sa-family-t))
130 (constant (somaxconn "SOMAXCONN")
131 :documentation "Maximum listen() queue length")
133 (constant (sol-socket "SOL_SOCKET")
134 :documentation "get/setsockopt socket level constant.")
136 #+linux
137 (progn
138 (constant (sol-tcp "SOL_TCP")
139 :documentation "get/setsockopt TCP level constant.")
140 (constant (sol-ip "SOL_IP")
141 :documentation "get/setsockopt IP level constant.")
142 (constant (sol-raw "SOL_RAW")
143 :documentation "get/setsockopt raw level constant."))
145 ;;; getsockopt/setsockopt()
146 (constant (so-acceptconn "SO_ACCEPTCONN"))
147 (constant (so-acceptfilter "SO_ACCEPTFILTER") :optional t) ; freebsd
148 (constant (so-bindtodevice "SO_BINDTODEVICE") :optional t) ; linux
149 (constant (so-bintime "SO_BINTIME") :optional t) ; freebsd
150 (constant (so-broadcast "SO_BROADCAST"))
151 (constant (so-debug "SO_DEBUG"))
152 (constant (so-dontroute "SO_DONTROUTE"))
153 (constant (so-error "SO_ERROR"))
154 (constant (so-keepalive "SO_KEEPALIVE"))
155 (constant (so-label "SO_LABEL") :optional t) ; freebsd
156 (constant (so-linger "SO_LINGER"))
157 (constant (so-listenincqlen "SO_LISTENINCQLEN") :optional t) ; freebsd
158 (constant (so-listenqlen "SO_LISTENQLEN") :optional t) ; freebsd
159 (constant (so-listenqlimit "SO_LISTENQLIMIT") :optional t) ; freebsd
160 (constant (so-nosigpipe "SO_NOSIGPIPE") :optional t) ; freebsd
161 (constant (so-oobinline "SO_OOBINLINE"))
162 (constant (so-passcred "SO_PASSCRED") :optional t) ; linux
163 (constant (so-peercred "SO_PEERCRED") :optional t) ; linux
164 (constant (so-peerlabel "SO_PEERLABEL") :optional t) ; freebsd
165 (constant (so-priority "SO_PRIORITY") :optional t) ; linux
166 (constant (so-rcvbuf "SO_RCVBUF"))
167 (constant (so-rcvlowat "SO_RCVLOWAT"))
168 (constant (so-rcvtimeo "SO_RCVTIMEO"))
169 (constant (so-reuseaddr "SO_REUSEADDR"))
170 (constant (so-reuseport "SO_REUSEPORT") :optional t) ; freebsd
171 (constant (so-sndbuf "SO_SNDBUF"))
172 (constant (so-sndlowat "SO_SNDLOWAT"))
173 (constant (so-sndtimeo "SO_SNDTIMEO"))
174 (constant (so-timestamp "SO_TIMESTAMP"))
175 (constant (so-type "SO_TYPE"))
176 (constant (so-useloopback "SO_USELOOPBACK") :optional t) ; freebsd
177 (constant (tcp-cork "TCP_CORK") :optional t) ; linux
178 (constant (tcp-defer-accept "TCP_DEFER_ACCEPT") :optional t) ; linux
179 (constant (tcp-info "TCP_INFO") :optional t) ; linux
180 (constant (tcp-keepcnt "TCP_KEEPCNT") :optional t) ; linux
181 (constant (tcp-keepidle "TCP_KEEPIDLE") :optional t) ; linux
182 (constant (tcp-keepintvl "TCP_KEEPINTVL") :optional t) ; linux
183 (constant (tcp-linger2 "TCP_LINGER2") :optional t) ; linux
184 (constant (tcp-maxseg "TCP_MAXSEG") :optional t) ; linux, freebsd
185 (constant (tcp-nodelay "TCP_NODELAY") :optional t) ; linux, freebsd
186 (constant (tcp-noopt "TCP_NOOPT") :optional t) ; freebsd
187 (constant (tcp-nopush "TCP_NOPUSH") :optional t) ; freebsd
188 (constant (tcp-quickack "TCP_QUICKACK") :optional t) ; linux
189 (constant (tcp-syncnt "TCP_SYNCNT") :optional t) ; linux
190 (constant (tcp-window "TCP_WINDOW_CLAMP") :optional t) ; linux
192 ;;; shutdown()
193 (constant (shut-rd "SHUT_RD" "SD_RECEIVE"))
194 (constant (shut-wr "SHUT_WR" "SD_SEND"))
195 (constant (shut-rdwr "SHUT_RDWR" "SD_BOTH"))
197 ;;; recvmsg/sendmsg()
198 (constant (msg-dontroute "MSG_DONTROUTE")) ; sendmsg
199 (constant (msg-oob "MSG_OOB")) ; recvmsg sendmsg
200 (constant (msg-peek "MSG_PEEK")) ; recvmsg
201 (constant (msg-errqueue "MSG_ERRQUEUE") :optional t) ; recvmsg
202 (constant (msg-more "MSG_MORE") :optional t) ; sendmsg
203 (constant (msg-confirm "MSG_CONFIRM") :optional t) ; sendmsg sendmsg
204 (constant (msg-proxy "MSG_PROXY") :optional t) ;
205 (constant (msg-fin "MSG_FIN") :optional t) ;
206 (constant (msg-syn "MSG_SYN") :optional t) ;
207 (constant (msg-eof "MSG_EOF") :optional t) ;
208 (constant (msg-nbio "MSG_NBIO") :optional t) ;
209 (constant (msg-compat "MSG_COMPAT") :optional t) ;
210 (constant (msg-trunc "MSG_TRUNC")) ; recvmsg
211 (constant (msg-waitall "MSG_WAITALL")) ; recvmsg
212 (constant (msg-dontwait "MSG_DONTWAIT")) ; recvmsg sendmsg
213 #-darwin (constant (msg-nosignal "MSG_NOSIGNAL")) ; sendmsg
214 (constant (msg-eor "MSG_EOR")) ; recvmsg sendmsg
215 (constant (msg-ctrunc "MSG_CTRUNC")) ; recvmsg
217 (cstruct msghdr "struct msghdr"
218 (name "msg_name" :type :pointer)
219 (namelen "msg_namelen" :type socklen-t)
220 (iov "msg_iov" :type :pointer)
221 (iovlen "msg_iovlen" :type size-t)
222 (control "msg_control" :type :pointer)
223 (controllen "msg_controllen" :type socklen-t)
224 (flags "msg_flags" :type :int))
226 (cstruct cmsghdr "struct cmsghdr"
227 (len "cmsg_len" :type socklen-t)
228 (level "cmsg_level" :type :int)
229 (type "cmsg_type" :type :int))
231 #-(and) ; unused
232 (constant (cmgroup-max "CMGROUP_MAX") :optional t)
234 #+(or (or) freebsd) ; unused
235 (cstruct cmsgcred "struct cmsgcred"
236 (pid "cmcred_pid" :type pid-t)
237 (uid "cmcred_uid" :type uid-t)
238 (euid "cmcred_euid" :type uid-t)
239 (gid "cmcred_gid" :type gid-t)
240 (ngroups "cmcred_ngroups" :type :short)
241 (groups "cmcred_groups" :type gid-t :count :auto))
243 (constant (scm-rights "SCM_RIGHTS"))
244 (constant (scm-credentials "SCM_CREDENTIALS") :optional t)
246 #+(and nil linux)
247 (cstruct ucred "struct ucred"
248 "Socket credential messages."
249 (pid "pid" :type pid-t)
250 (uid "uid" :type uid-t)
251 (gid "gid" :type gid-t))
253 #+(and nil freebsd)
254 (cstruct sockcred "struct sockcred"
255 (uid "sc_uid" :type uid-t)
256 (euid "sc_euid" :type uid-t)
257 (gid "sc_gid" :type gid-t)
258 (egid "sc_egid" :type gid-t)
259 (ngroups "sc_ngroups" :type :int)
260 (groups "sc_groups" :type gid-t :count :auto))
262 (cstruct linger "struct linger"
263 "SO_LINGER manipulation record."
264 (onoff "l_onoff" :type :int)
265 (linger "l_linger" :type :int))
267 #+freebsd
268 (cstruct accept-filter-arg "struct accept_filter_arg"
269 (name "af_name" :type :uint8 :count :auto)
270 (arg "af_arg" :type :uint8 :count :auto))
272 ;;;; from sys/un.h
274 (cstruct sockaddr-un "struct sockaddr_un"
275 "A UNIX-domain socket address."
276 (family "sun_family" :type sa-family-t)
277 (path "sun_path" :type :uint8 :count :auto))
279 #+freebsd
280 (progn
281 (constant (local-peercred "LOCAL_PEERCRED"))
282 (constant (local-creds "LOCAL_CREDS"))
283 (constant (local-connwait "LOCAL_CONNWAIT")))
285 ;;;; from netinet/in.h
287 (ctype in-port-t "in_port_t")
288 (ctype in-addr-t "in_addr_t")
290 (cstruct sockaddr-in "struct sockaddr_in"
291 "An IPv4 socket address."
292 (family "sin_family" :type sa-family-t)
293 (port "sin_port" :type in-port-t)
294 (addr "sin_addr" :type in-addr-t))
296 (cstruct in-addr-struct "struct in_addr"
297 (addr "s_addr" :type :uint32))
299 (cunion in6-addr "struct in6_addr"
300 "An IPv6 address."
301 (addr8 "s6_addr" :type :uint8 :count :auto))
303 (cstruct sockaddr-in6 "struct sockaddr_in6"
304 "An IPv6 socket address."
305 (family "sin6_family" :type sa-family-t)
306 (port "sin6_port" :type in-port-t)
307 (flowinfo "sin6_flowinfo" :type :uint32)
308 (addr "sin6_addr" :type in6-addr)
309 (scope-id "sin6_scope_id" :type :uint32))
311 #-(and) ; unused
312 (progn
313 (constant (inaddr-any "INADDR_ANY"))
314 (constant (inaddr-broadcast "INADDR_BROADCAST"))
315 (constant (inaddr-none "INADDR_NONE"))
316 (constant (in-loopbacknet "IN_LOOPBACKNET"))
317 (constant (inaddr-loopback "INADDR_LOOPBACK"))
318 (constant (inaddr-unspec-group "INADDR_UNSPEC_GROUP"))
319 (constant (inaddr-allhosts-group "INADDR_ALLHOSTS_GROUP"))
320 (constant (inaddr-allrtrs-group "INADDR_ALLRTRS_GROUP"))
321 (constant (inaddr-max-local-group "INADDR_MAX_LOCAL_GROUP")))
323 (constant (inet-addrstrlen "INET_ADDRSTRLEN"))
324 (constant (inet6-addrstrlen "INET6_ADDRSTRLEN"))
326 (constant (ipv6-join-group "IPV6_JOIN_GROUP"))
327 (constant (ipv6-leave-group "IPV6_LEAVE_GROUP"))
328 (constant (ipv6-multicast-hops "IPV6_MULTICAST_HOPS"))
329 (constant (ipv6-multicast-if "IPV6_MULTICAST_IF"))
330 (constant (ipv6-multicast-loop "IPV6_MULTICAST_LOOP"))
331 (constant (ipv6-unicast-hops "IPV6_UNICAST_HOPS"))
332 (constant (ipv6-v6only "IPV6_V6ONLY"))
334 ;;;; from netinet/tcp.h
336 (constant (tcp-nodelay "TCP_NODELAY"))
337 (constant (tcp-maxseg "TCP_MAXSEG"))
338 #+linux
339 (constant (tcp-cork "TCP_CORK"))
340 (constant (tcp-keepidle "TCP_KEEPIDLE") :optional t)
341 (constant (tcp-keepintvl "TCP_KEEPINTVL") :optional t)
342 (constant (tcp-keepcnt "TCP_KEEPCNT") :optional t)
343 (constant (tcp-syncnt "TCP_SYNCNT") :optional t)
344 (constant (tcp-linger2 "TCP_LINGER2") :optional t)
345 (constant (tcp-defer-accept "TCP_DEFER_ACCEPT") :optional t)
346 (constant (tcp-window-clamp "TCP_WINDOW_CLAMP") :optional t)
347 #-darwin (constant (tcp-info "TCP_INFO"))
348 (constant (tcp-quickack "TCP_QUICKACK") :optional t)
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))