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