Add SOCKET-SHUTDOWN in contrib/sb-bsd-sockets
[sbcl.git] / contrib / sb-bsd-sockets / constants.lisp
1 ;;; -*- Lisp -*-
2
3 ;;; This isn't really lisp, but it's definitely a source file.  we
4 ;;; name it thus to avoid having to mess with the clc lpn translations
5
6 ;;; first, the headers necessary to find definitions of everything
7 ("sys/types.h" "sys/socket.h" "sys/stat.h" "unistd.h" "sys/un.h"
8  "netinet/in.h" "netinet/in_systm.h" "netinet/ip.h" "net/if.h"
9  "netdb.h" "errno.h" "netinet/tcp.h" "fcntl.h" )
10
11 ;;; then the stuff we're looking for
12 ((:integer af-inet "AF_INET" "IP Protocol family")
13  (:integer af-unspec "AF_UNSPEC" "Unspecified")
14  (:integer af-local
15            #+(or sunos solaris hpux) "AF_UNIX"
16            #-(or sunos solaris hpux) "AF_LOCAL"
17            "Local to host (pipes and file-domain).")
18  #+linux (:integer af-inet6 "AF_INET6"   "IP version 6")
19  #+linux (:integer af-route "AF_NETLINK" "Alias to emulate 4.4BSD ")
20
21  (:integer sock-stream "SOCK_STREAM"
22            "Sequenced, reliable, connection-based byte streams.")
23  (:integer sock-dgram "SOCK_DGRAM"
24            "Connectionless, unreliable datagrams of fixed maximum length.")
25  (:integer sock-raw "SOCK_RAW"
26            "Raw protocol interface.")
27  (:integer sock-rdm "SOCK_RDM"
28            "Reliably-delivered messages.")
29  (:integer sock-seqpacket "SOCK_SEQPACKET"
30            "Sequenced, reliable, connection-based, datagrams of fixed maximum length.")
31
32  (:integer sol-socket "SOL_SOCKET")
33
34  ;; some of these may be linux-specific
35  (:integer so-debug "SO_DEBUG"
36            "Enable debugging in underlying protocol modules")
37  (:integer so-reuseaddr "SO_REUSEADDR" "Enable local address reuse")
38  (:integer so-type "SO_TYPE")                   ;get only
39  (:integer so-error "SO_ERROR")         ;get only (also clears)
40  (:integer so-dontroute "SO_DONTROUTE"
41            "Bypass routing facilities: instead send direct to appropriate network interface for the network portion of the destination address")
42  (:integer so-broadcast "SO_BROADCAST" "Request permission to send broadcast datagrams")
43  (:integer so-sndbuf "SO_SNDBUF")
44  #+linux (:integer so-passcred "SO_PASSCRED")
45  (:integer so-rcvbuf "SO_RCVBUF")
46  (:integer so-keepalive "SO_KEEPALIVE"
47            "Send periodic keepalives.  If peer does not respond, we get SIGPIPE.")
48  #+linux (:integer tcp-keepcnt "TCP_KEEPCNT"
49                    "Number of unacknowledged probes before the connection is considered dead.")
50  #+linux (:integer tcp-keepidle "TCP_KEEPIDLE"
51                    "Seconds between the last data packet sent and the first keepalive probe.")
52  #+linux (:integer tcp-keepintvl "TCP_KEEPINTVL" "Seconds between keepalive probes.")
53  (:integer so-oobinline "SO_OOBINLINE"
54            "Put out-of-band data into the normal input queue when received")
55  #+linux
56  (:integer so-no-check "SO_NO_CHECK")
57  #+linux (:integer so-priority "SO_PRIORITY")
58  (:integer so-linger "SO_LINGER"
59            "For reliable streams, pause a while on closing when unsent messages are queued")
60  #+linux (:integer so-bsdcompat "SO_BSDCOMPAT")
61  (:integer so-sndlowat "SO_SNDLOWAT")
62  (:integer so-rcvlowat "SO_RCVLOWAT")
63  (:integer so-sndtimeo "SO_SNDTIMEO")
64  (:integer so-rcvtimeo "SO_RCVTIMEO")
65
66  (:integer tcp-nodelay "TCP_NODELAY")
67  #+linux (:integer so-bindtodevice "SO_BINDTODEVICE")
68  (:integer ifnamsiz "IFNAMSIZ")
69
70 ;; socket shutdown flags
71 (:integer SHUT_RD "SHUT_RD")
72 (:integer SHUT_WR "SHUT_WR")
73 (:integer SHUT_RDWR "SHUT_RDWR")
74
75 ;; errors
76  (:integer EADDRINUSE "EADDRINUSE")
77  (:integer EAGAIN "EAGAIN")
78  (:integer EBADF "EBADF")
79  (:integer ECONNREFUSED "ECONNREFUSED")
80  (:integer ETIMEDOUT "ETIMEDOUT")
81  (:integer EINTR "EINTR")
82  (:integer EINVAL "EINVAL")
83  (:integer ENOBUFS "ENOBUFS")
84  (:integer ENOMEM "ENOMEM")
85  (:integer EOPNOTSUPP "EOPNOTSUPP")
86  (:integer EPERM "EPERM")
87  (:integer EPROTONOSUPPORT "EPROTONOSUPPORT")
88  (:integer ERANGE "ERANGE")
89  (:integer ESOCKTNOSUPPORT "ESOCKTNOSUPPORT")
90  (:integer ENETUNREACH "ENETUNREACH")
91  (:integer ENOTCONN "ENOTCONN")
92
93  (:integer NETDB-INTERNAL #+hpux "h_NETDB_INTERNAL" #-hpux "NETDB_INTERNAL" "See errno.")
94  (:integer NETDB-SUCCESS #+hpux "h_NETDB_SUCCESS" #-hpux "NETDB_SUCCESS" "No problem.")
95  (:integer HOST-NOT-FOUND "HOST_NOT_FOUND" "Authoritative Answer Host not found.")
96  (:integer TRY-AGAIN "TRY_AGAIN" "Non-Authoritative Host not found, or SERVERFAIL.")
97  (:integer NO-RECOVERY "NO_RECOVERY" "Non recoverable errors, FORMERR, REFUSED, NOTIMP.")
98  (:integer NO-DATA "NO_DATA" "Valid name, no data record of requested type.")
99  (:integer NO-ADDRESS "NO_ADDRESS" "No address, look for MX record.")
100  #-(or hpux sunos) (:function h-strerror ("hstrerror" c-string (errno int)))
101
102  (:integer O-NONBLOCK "O_NONBLOCK")
103  (:integer f-getfl "F_GETFL")
104  (:integer f-setfl "F_SETFL")
105
106  (:integer msg-oob "MSG_OOB")
107  (:integer msg-peek "MSG_PEEK")
108  (:integer msg-trunc "MSG_TRUNC")
109  (:integer msg-waitall "MSG_WAITALL")
110  (:integer msg-eor "MSG_EOR")
111  (:integer msg-dontroute "MSG_DONTROUTE")
112  (:integer msg-dontwait "MSG_DONTWAIT")
113  #+linux (:integer msg-nosignal "MSG_NOSIGNAL")
114  #+linux (:integer msg-confirm "MSG_CONFIRM")
115  #+linux (:integer msg-more "MSG_MORE")
116
117  ;; for socket-receive
118  (:type socklen-t "socklen_t")
119  (:type size-t "size_t")
120  (:type ssize-t "ssize_t")
121
122                                         #|
123  ;;; stat is nothing to do with sockets, but I keep it around for testing
124  ;;; the ffi glue
125  (:structure stat ("struct stat"
126  (t dev "dev_t" "st_dev")
127  ((alien:integer 32) atime "time_t" "st_atime")))
128  (:function stat ("stat" (integer 32)
129  (file-name (* t))
130  (buf (* t))))
131  |#
132  (:structure protoent ("struct protoent"
133                        (c-string-pointer name "char *" "p_name")
134                        ((* (* t)) aliases "char **" "p_aliases")
135                        (integer proto "int" "p_proto")))
136  (:function getprotobyname ("getprotobyname" (* protoent)
137                                              (name c-string)))
138
139 ;; getprotobyname_r is a thread-safe reentrant version of getprotobyname
140  #+os-provides-getprotoby-r
141  (:function getprotobyname-r ("getprotobyname_r" int
142                                                  (name c-string)
143                                                  (result_buf (* protoent))
144                                                  (buffer (* char))
145                                                  (buffer-len size-t)
146                                                  #-solaris
147                                                  (result (* (* protoent)))))
148
149
150  (:function getprotobynumber ("getprotobynumber" (* protoent)
151                                                  (proto int)))
152  ;;ditto, save for the getprotobynumber part
153  #+os-provides-getprotoby-r
154  (:function getprotobynumber-r ("getprotobynumber_r" int
155                                                  (proto int)
156                                                  (result_buf (* protoent))
157                                                  (buffer (* char))
158                                                  (buffer-len size-t)
159                                                  #-solaris
160                                                  (result (* (* protoent)))))
161
162  (:integer inaddr-any "INADDR_ANY")
163  (:structure in-addr ("struct in_addr"
164                       ((array (unsigned 8)) addr "u_int32_t" "s_addr")))
165  (:structure sockaddr-in ("struct sockaddr_in"
166                           #+darwin ((unsigned 8) len "__uint8_t" "sin_len")
167                           (integer family "sa_family_t" "sin_family")
168                           ;; These two could be in-port-t and
169                           ;; in-addr-t, but then we'd throw away the
170                           ;; convenience (and byte-order agnosticism)
171                           ;; of the old sb-grovel scheme.
172                           ((array (unsigned 8)) port "u_int16_t" "sin_port")
173                           ((array (unsigned 8)) addr "struct in_addr" "sin_addr")))
174  (:structure sockaddr-un ("struct sockaddr_un"
175                           (integer family "sa_family_t" "sun_family")
176                           (c-string path "char" "sun_path")))
177  (:structure sockaddr-un-abstract ("struct sockaddr_un"
178                               (integer family "sa_family_t" "sun_family")
179                               ((array (unsigned 8)) path "char" "sun_path")))
180  (:structure hostent ("struct hostent"
181                       (c-string-pointer name "char *" "h_name")
182                       ((* c-string) aliases "char **" "h_aliases")
183                       (integer type "int" "h_addrtype")
184                       (integer length "int" "h_length")
185                       ((* (* (unsigned 8))) addresses "char **" "h_addr_list")))
186  (:structure msghdr ("struct msghdr"
187                       (c-string-pointer name "void *" "msg_name")
188                       (integer namelen "socklen_t" "msg_namelen")
189                       ((* t) iov "struct iovec" "msg_iov")
190                       (integer iovlen "size_t" "msg_iovlen")
191                       ((* t) control "void *" "msg_control")
192                       (integer controllen "socklen_t" "msg_controllen")
193                       (integer flags "int" "msg_flags")))
194  (:function socket (#-netbsd "socket" #+netbsd "_socket" int
195                     (domain int)
196                     (type int)
197                     (protocol int)))
198  (:function bind ("bind" int
199                   (sockfd int)
200                   (my-addr (* t))  ; KLUDGE: sockaddr-in or sockaddr-un?
201                   (addrlen socklen-t)))
202  (:function listen ("listen" int
203                     (socket int)
204                     (backlog int)))
205  (:function accept ("accept" int
206                     (socket int)
207                     (my-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
208                     (addrlen socklen-t :in-out)))
209  (:function getpeername ("getpeername" int
210                          (socket int)
211                          (her-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
212                          (addrlen socklen-t :in-out)))
213  (:function getsockname ("getsockname" int
214                          (socket int)
215                          (my-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
216                          (addrlen socklen-t :in-out)))
217  (:function connect ("connect" int
218                     (socket int)
219                     (his-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
220                     (addrlen socklen-t)))
221  (:function close ("close" int
222                    (fd int)))
223  (:function shutdown ("shutdown" int
224                       (fd int) (how int)))
225  (:function recvfrom ("recvfrom" ssize-t
226                                  (socket int)
227                                  (buf (* t))
228                                  (len integer)
229                                  (flags int)
230                                  (sockaddr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
231                                  (socklen (* socklen-t))))
232  (:function recvmsg ("recvmsg" ssize-t
233                                (socket int)
234                                (msg (* msghdr))
235                                (flags int)))
236  (:function send ("send" ssize-t
237                          (socket int)
238                          (buf (* t))
239                          (len size-t)
240                          (flags int)))
241  (:function sendto ("sendto" int
242                              (socket int)
243                              (buf (* t))
244                              (len size-t)
245                              (flags int)
246                              (sockaddr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
247                              (socklen socklen-t)))
248  (:function sendmsg ("sendmsg" int
249                                (socket int)
250                                (msg (* msghdr))
251                                (flags int)))
252  (:function gethostbyname ("gethostbyname" (* hostent) (name c-string)))
253  #+darwin
254  (:function gethostbyname2 ("gethostbyname2" (* hostent)
255                                              (name c-string)
256                                              (af int)))
257  (:function gethostbyaddr ("gethostbyaddr" (* hostent)
258                                            (addr (* t))
259                                            (len int)
260                                            (af int)))
261
262  ;; Re-entrant gethostbyname
263
264  #+linux
265  (:function gethostbyname-r ("gethostbyname_r"
266                              int
267                              (name c-string)
268                              (ret (* hostent))
269                              (buf (* char))
270                              (buflen long)
271                              (result (* (* hostent)))
272                              (h-errnop (* int))))
273  ;; getaddrinfo / getnameinfo
274
275  #+sb-bsd-sockets-addrinfo
276  (:structure addrinfo ("struct addrinfo"
277                        (integer flags "int" "ai_flags")
278                        (integer family "int" "ai_family")
279                        (integer socktype "int" "ai_socktype")
280                        (integer protocol "int" "ai_protocol")
281                        ;; CLH 20070306 FIXME: ai_addrlen should really
282                        ;; be a socklen_t, but I'm not sure if this the
283                        ;; case on other platforms. I'm setting this to
284                        ;; socklen_t on darwin and hoping that other
285                        ;; platform maintainers will do the right thing
286                        ;; here.
287                        #+darwin (integer addrlen "socklen_t" "ai_addrlen")
288                        #-darwin (integer addrlen "size_t" "ai_addrlen")
289                        ((* sockaddr-in) addr "struct sockaddr*" "ai_addr")
290                        (c-string-pointer canonname "char *" "ai_canonname")
291                        ((* t) next "struct addrinfo*" "ai_next")))
292
293  #+sb-bsd-sockets-addrinfo
294  (:function getaddrinfo ("getaddrinfo"
295                          int
296                          (node c-string)
297                          (service c-string)
298                          (hints (* addrinfo))
299                          (res (* (* addrinfo)))))
300
301  #+sb-bsd-sockets-addrinfo
302  (:function freeaddrinfo ("freeaddrinfo"
303                           void
304                           (res (* addrinfo))))
305
306  #+sb-bsd-sockets-addrinfo
307  (:function gai-strerror ("gai_strerror"
308                          c-string
309                          (error-code int)))
310
311  #+sb-bsd-sockets-addrinfo
312  (:function getnameinfo ("getnameinfo"
313                          int
314                          (address (* sockaddr-in))
315                          (address-length size-t)
316                          (host (* char))
317                          (host-len size-t)
318                          (service (* char))
319                          (service-len size-t)
320                          (flags int)))
321
322  (:integer EAI-FAMILY "EAI_FAMILY")
323  (:integer EAI-SOCKTYPE "EAI_SOCKTYPE")
324  (:integer EAI-BADFLAGS "EAI_BADFLAGS")
325  (:integer EAI-NONAME "EAI_NONAME")
326  (:integer EAI-SERVICE "EAI_SERVICE")
327  #-freebsd
328  (:integer EAI-ADDRFAMILY "EAI_ADDRFAMILY")
329  (:integer EAI-MEMORY "EAI_MEMORY")
330  (:integer EAI-FAIL "EAI_FAIL")
331  (:integer EAI-AGAIN "EAI_AGAIN")
332  (:integer EAI-SYSTEM "EAI_SYSTEM")
333
334  (:integer NI-NAMEREQD "NI_NAMEREQD")
335
336  ;; Socket options
337
338  (:function setsockopt ("setsockopt" int
339                         (socket int)
340                         (level int)
341                         (optname int)
342                         (optval (* t))
343                         (optlen int))) ;;; should be socklen-t!
344  (:function fcntl ("fcntl" int
345                    (fd int)
346                    (cmd int)
347                    (arg long)))
348  (:function getsockopt ("getsockopt" int
349                         (socket int)
350                         (level int)
351                         (optname int)
352                         (optval (* t))
353                         (optlen (* int)))) ;;; should be socklen-t!
354  )