92c017e370e07223b605c83a1b90785575f3bc84
[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  (:integer EADDRINUSE "EADDRINUSE")
71  (:integer EAGAIN "EAGAIN")
72  (:integer EBADF "EBADF")
73  (:integer ECONNREFUSED "ECONNREFUSED")
74  (:integer ETIMEDOUT "ETIMEDOUT")
75  (:integer EINTR "EINTR")
76  (:integer EINVAL "EINVAL")
77  (:integer ENOBUFS "ENOBUFS")
78  (:integer ENOMEM "ENOMEM")
79  (:integer EOPNOTSUPP "EOPNOTSUPP")
80  (:integer EPERM "EPERM")
81  (:integer EPROTONOSUPPORT "EPROTONOSUPPORT")
82  (:integer ERANGE "ERANGE")
83  (:integer ESOCKTNOSUPPORT "ESOCKTNOSUPPORT")
84  (:integer ENETUNREACH "ENETUNREACH")
85  (:integer ENOTCONN "ENOTCONN")
86
87  (:integer NETDB-INTERNAL #+hpux "h_NETDB_INTERNAL" #-hpux "NETDB_INTERNAL" "See errno.")
88  (:integer NETDB-SUCCESS #+hpux "h_NETDB_SUCCESS" #-hpux "NETDB_SUCCESS" "No problem.")
89  (:integer HOST-NOT-FOUND "HOST_NOT_FOUND" "Authoritative Answer Host not found.")
90  (:integer TRY-AGAIN "TRY_AGAIN" "Non-Authoritative Host not found, or SERVERFAIL.")
91  (:integer NO-RECOVERY "NO_RECOVERY" "Non recoverable errors, FORMERR, REFUSED, NOTIMP.")
92  (:integer NO-DATA "NO_DATA" "Valid name, no data record of requested type.")
93  (:integer NO-ADDRESS "NO_ADDRESS" "No address, look for MX record.")
94  #-(or hpux sunos) (:function h-strerror ("hstrerror" c-string (errno int)))
95
96  (:integer O-NONBLOCK "O_NONBLOCK")
97  (:integer f-getfl "F_GETFL")
98  (:integer f-setfl "F_SETFL")
99
100  (:integer msg-oob "MSG_OOB")
101  (:integer msg-peek "MSG_PEEK")
102  (:integer msg-trunc "MSG_TRUNC")
103  (:integer msg-waitall "MSG_WAITALL")
104  (:integer msg-eor "MSG_EOR")
105  (:integer msg-dontroute "MSG_DONTROUTE")
106  (:integer msg-dontwait "MSG_DONTWAIT")
107  #+linux (:integer msg-nosignal "MSG_NOSIGNAL")
108  #+linux (:integer msg-confirm "MSG_CONFIRM")
109  #+linux (:integer msg-more "MSG_MORE")
110
111  ;; for socket-receive
112  (:type socklen-t "socklen_t")
113  (:type size-t "size_t")
114  (:type ssize-t "ssize_t")
115
116                                         #|
117  ;;; stat is nothing to do with sockets, but I keep it around for testing
118  ;;; the ffi glue
119  (:structure stat ("struct stat"
120  (t dev "dev_t" "st_dev")
121  ((alien:integer 32) atime "time_t" "st_atime")))
122  (:function stat ("stat" (integer 32)
123  (file-name (* t))
124  (buf (* t))))
125  |#
126  (:structure protoent ("struct protoent"
127                        (c-string-pointer name "char *" "p_name")
128                        ((* (* t)) aliases "char **" "p_aliases")
129                        (integer proto "int" "p_proto")))
130  (:function getprotobyname ("getprotobyname" (* protoent)
131                                              (name c-string)))
132
133 ;; getprotobyname_r is a thread-safe reentrant version of getprotobyname
134  #+os-provides-getprotoby-r
135  (:function getprotobyname-r ("getprotobyname_r" int
136                                                  (name c-string)
137                                                  (result_buf (* protoent))
138                                                  (buffer (* char))
139                                                  (buffer-len size-t)
140                                                  #-solaris
141                                                  (result (* (* protoent)))))
142
143
144  (:function getprotobynumber ("getprotobynumber" (* protoent)
145                                                  (proto int)))
146  ;;ditto, save for the getprotobynumber part
147  #+os-provides-getprotoby-r
148  (:function getprotobynumber-r ("getprotobynumber_r" int
149                                                  (proto int)
150                                                  (result_buf (* protoent))
151                                                  (buffer (* char))
152                                                  (buffer-len size-t)
153                                                  #-solaris
154                                                  (result (* (* protoent)))))
155
156  (:integer inaddr-any "INADDR_ANY")
157  (:structure in-addr ("struct in_addr"
158                       ((array (unsigned 8)) addr "u_int32_t" "s_addr")))
159  (:structure sockaddr-in ("struct sockaddr_in"
160                           #+darwin ((unsigned 8) len "__uint8_t" "sin_len")
161                           (integer family "sa_family_t" "sin_family")
162                           ;; These two could be in-port-t and
163                           ;; in-addr-t, but then we'd throw away the
164                           ;; convenience (and byte-order agnosticism)
165                           ;; of the old sb-grovel scheme.
166                           ((array (unsigned 8)) port "u_int16_t" "sin_port")
167                           ((array (unsigned 8)) addr "struct in_addr" "sin_addr")))
168  (:structure sockaddr-un ("struct sockaddr_un"
169                           (integer family "sa_family_t" "sun_family")
170                           (c-string path "char" "sun_path")))
171  (:structure sockaddr-un-abstract ("struct sockaddr_un"
172                               (integer family "sa_family_t" "sun_family")
173                               ((array (unsigned 8)) path "char" "sun_path")))
174  (:structure hostent ("struct hostent"
175                       (c-string-pointer name "char *" "h_name")
176                       ((* c-string) aliases "char **" "h_aliases")
177                       (integer type "int" "h_addrtype")
178                       (integer length "int" "h_length")
179                       ((* (* (unsigned 8))) addresses "char **" "h_addr_list")))
180  (:structure msghdr ("struct msghdr"
181                       (c-string-pointer name "void *" "msg_name")
182                       (integer namelen "socklen_t" "msg_namelen")
183                       ((* t) iov "struct iovec" "msg_iov")
184                       (integer iovlen "size_t" "msg_iovlen")
185                       ((* t) control "void *" "msg_control")
186                       (integer controllen "socklen_t" "msg_controllen")
187                       (integer flags "int" "msg_flags")))
188  (:function socket (#-netbsd "socket" #+netbsd "_socket" int
189                     (domain int)
190                     (type int)
191                     (protocol int)))
192  (:function bind ("bind" int
193                   (sockfd int)
194                   (my-addr (* t))  ; KLUDGE: sockaddr-in or sockaddr-un?
195                   (addrlen socklen-t)))
196  (:function listen ("listen" int
197                     (socket int)
198                     (backlog int)))
199  (:function accept ("accept" int
200                     (socket int)
201                     (my-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
202                     (addrlen socklen-t :in-out)))
203  (:function getpeername ("getpeername" int
204                          (socket int)
205                          (her-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
206                          (addrlen socklen-t :in-out)))
207  (:function getsockname ("getsockname" int
208                          (socket int)
209                          (my-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
210                          (addrlen socklen-t :in-out)))
211  (:function connect ("connect" int
212                     (socket int)
213                     (his-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
214                     (addrlen socklen-t)))
215  (:function close ("close" int
216                    (fd int)))
217  (:function recvfrom ("recvfrom" ssize-t
218                                  (socket int)
219                                  (buf (* t))
220                                  (len integer)
221                                  (flags int)
222                                  (sockaddr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
223                                  (socklen (* socklen-t))))
224  (:function recvmsg ("recvmsg" ssize-t
225                                (socket int)
226                                (msg (* msghdr))
227                                (flags int)))
228  (:function send ("send" ssize-t
229                          (socket int)
230                          (buf (* t))
231                          (len size-t)
232                          (flags int)))
233  (:function sendto ("sendto" int
234                              (socket int)
235                              (buf (* t))
236                              (len size-t)
237                              (flags int)
238                              (sockaddr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
239                              (socklen socklen-t)))
240  (:function sendmsg ("sendmsg" int
241                                (socket int)
242                                (msg (* msghdr))
243                                (flags int)))
244  (:function gethostbyname ("gethostbyname" (* hostent) (name c-string)))
245  #+darwin
246  (:function gethostbyname2 ("gethostbyname2" (* hostent)
247                                              (name c-string)
248                                              (af int)))
249  (:function gethostbyaddr ("gethostbyaddr" (* hostent)
250                                            (addr (* t))
251                                            (len int)
252                                            (af int)))
253
254  ;; Re-entrant gethostbyname
255
256  #+linux
257  (:function gethostbyname-r ("gethostbyname_r"
258                              int
259                              (name c-string)
260                              (ret (* hostent))
261                              (buf (* char))
262                              (buflen long)
263                              (result (* (* hostent)))
264                              (h-errnop (* int))))
265  ;; getaddrinfo / getnameinfo
266
267  #+sb-bsd-sockets-addrinfo
268  (:structure addrinfo ("struct addrinfo"
269                        (integer flags "int" "ai_flags")
270                        (integer family "int" "ai_family")
271                        (integer socktype "int" "ai_socktype")
272                        (integer protocol "int" "ai_protocol")
273                        ;; CLH 20070306 FIXME: ai_addrlen should really
274                        ;; be a socklen_t, but I'm not sure if this the
275                        ;; case on other platforms. I'm setting this to
276                        ;; socklen_t on darwin and hoping that other
277                        ;; platform maintainers will do the right thing
278                        ;; here.
279                        #+darwin (integer addrlen "socklen_t" "ai_addrlen")
280                        #-darwin (integer addrlen "size_t" "ai_addrlen")
281                        ((* sockaddr-in) addr "struct sockaddr*" "ai_addr")
282                        (c-string-pointer canonname "char *" "ai_canonname")
283                        ((* t) next "struct addrinfo*" "ai_next")))
284
285  #+sb-bsd-sockets-addrinfo
286  (:function getaddrinfo ("getaddrinfo"
287                          int
288                          (node c-string)
289                          (service c-string)
290                          (hints (* addrinfo))
291                          (res (* (* addrinfo)))))
292
293  #+sb-bsd-sockets-addrinfo
294  (:function freeaddrinfo ("freeaddrinfo"
295                           void
296                           (res (* addrinfo))))
297
298  #+sb-bsd-sockets-addrinfo
299  (:function gai-strerror ("gai_strerror"
300                          c-string
301                          (error-code int)))
302
303  #+sb-bsd-sockets-addrinfo
304  (:function getnameinfo ("getnameinfo"
305                          int
306                          (address (* sockaddr-in))
307                          (address-length size-t)
308                          (host (* char))
309                          (host-len size-t)
310                          (service (* char))
311                          (service-len size-t)
312                          (flags int)))
313
314  (:integer EAI-FAMILY "EAI_FAMILY")
315  (:integer EAI-SOCKTYPE "EAI_SOCKTYPE")
316  (:integer EAI-BADFLAGS "EAI_BADFLAGS")
317  (:integer EAI-NONAME "EAI_NONAME")
318  (:integer EAI-SERVICE "EAI_SERVICE")
319  #-freebsd
320  (:integer EAI-ADDRFAMILY "EAI_ADDRFAMILY")
321  (:integer EAI-MEMORY "EAI_MEMORY")
322  (:integer EAI-FAIL "EAI_FAIL")
323  (:integer EAI-AGAIN "EAI_AGAIN")
324  (:integer EAI-SYSTEM "EAI_SYSTEM")
325
326  (:integer NI-NAMEREQD "NI_NAMEREQD")
327
328  ;; Socket options
329
330  (:function setsockopt ("setsockopt" int
331                         (socket int)
332                         (level int)
333                         (optname int)
334                         (optval (* t))
335                         (optlen int))) ;;; should be socklen-t!
336  (:function fcntl ("fcntl" int
337                    (fd int)
338                    (cmd int)
339                    (arg long)))
340  (:function getsockopt ("getsockopt" int
341                         (socket int)
342                         (level int)
343                         (optname int)
344                         (optval (* t))
345                         (optlen (* int)))) ;;; should be socklen-t!
346  )