1.0.42.30: missing docstring for GET-PROTOCOL-BY-NAME
[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  #+linux
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  #-(or hpux sunos) (: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  #+linux (: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  #+os-provides-getprotoby-r
130  (:function getprotobyname-r ("getprotobyname_r" int
131                                                  (name c-string)
132                                                  (result_buf (* protoent))
133                                                  (buffer (* char))
134                                                  (buffer-len size-t)
135                                                  #-solaris
136                                                  (result (* (* protoent)))))
137
138
139  (:function getprotobynumber ("getprotobynumber" (* protoent)
140                                                  (proto int)))
141  ;;ditto, save for the getprotobynumber part
142  #+os-provides-getprotoby-r
143  (:function getprotobynumber-r ("getprotobynumber_r" int
144                                                  (proto int)
145                                                  (result_buf (* protoent))
146                                                  (buffer (* char))
147                                                  (buffer-len size-t)
148                                                  #-solaris
149                                                  (result (* (* protoent)))))
150
151  (:integer inaddr-any "INADDR_ANY")
152  (:structure in-addr ("struct in_addr"
153                       ((array (unsigned 8)) addr "u_int32_t" "s_addr")))
154  (:structure sockaddr-in ("struct sockaddr_in"
155                           #+darwin ((unsigned 8) len "__uint8_t" "sin_len")
156                           (integer family "sa_family_t" "sin_family")
157                           ;; These two could be in-port-t and
158                           ;; in-addr-t, but then we'd throw away the
159                           ;; convenience (and byte-order agnosticism)
160                           ;; of the old sb-grovel scheme.
161                           ((array (unsigned 8)) port "u_int16_t" "sin_port")
162                           ((array (unsigned 8)) addr "struct in_addr" "sin_addr")))
163  (:structure sockaddr-un ("struct sockaddr_un"
164                           (integer family "sa_family_t" "sun_family")
165                           (c-string path "char" "sun_path")))
166  (:structure sockaddr-un-abstract ("struct sockaddr_un"
167                               (integer family "sa_family_t" "sun_family")
168                               ((array (unsigned 8)) path "char" "sun_path")))
169  (:structure hostent ("struct hostent"
170                       (c-string-pointer name "char *" "h_name")
171                       ((* c-string) aliases "char **" "h_aliases")
172                       (integer type "int" "h_addrtype")
173                       (integer length "int" "h_length")
174                       ((* (* (unsigned 8))) addresses "char **" "h_addr_list")))
175  (:structure msghdr ("struct msghdr"
176                       (c-string-pointer name "void *" "msg_name")
177                       (integer namelen "socklen_t" "msg_namelen")
178                       ((* t) iov "struct iovec" "msg_iov")
179                       (integer iovlen "size_t" "msg_iovlen")
180                       ((* t) control "void *" "msg_control")
181                       (integer controllen "socklen_t" "msg_controllen")
182                       (integer flags "int" "msg_flags")))
183  (:function socket (#-netbsd "socket" #+netbsd "_socket" int
184                     (domain int)
185                     (type int)
186                     (protocol int)))
187  (:function bind ("bind" int
188                   (sockfd int)
189                   (my-addr (* t))  ; KLUDGE: sockaddr-in or sockaddr-un?
190                   (addrlen socklen-t)))
191  (:function listen ("listen" int
192                     (socket int)
193                     (backlog int)))
194  (:function accept ("accept" int
195                     (socket int)
196                     (my-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
197                     (addrlen socklen-t :in-out)))
198  (:function getpeername ("getpeername" int
199                          (socket int)
200                          (her-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
201                          (addrlen socklen-t :in-out)))
202  (:function getsockname ("getsockname" int
203                          (socket int)
204                          (my-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
205                          (addrlen socklen-t :in-out)))
206  (:function connect ("connect" int
207                     (socket int)
208                     (his-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
209                     (addrlen socklen-t)))
210  (:function close ("close" int
211                    (fd int)))
212  (:function recvfrom ("recvfrom" ssize-t
213                                  (socket int)
214                                  (buf (* t))
215                                  (len integer)
216                                  (flags int)
217                                  (sockaddr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
218                                  (socklen (* socklen-t))))
219  (:function recvmsg ("recvmsg" ssize-t
220                                (socket int)
221                                (msg (* msghdr))
222                                (flags int)))
223  (:function send ("send" ssize-t
224                          (socket int)
225                          (buf (* t))
226                          (len size-t)
227                          (flags int)))
228  (:function sendto ("sendto" int
229                              (socket int)
230                              (buf (* t))
231                              (len size-t)
232                              (flags int)
233                              (sockaddr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
234                              (socklen socklen-t)))
235  (:function sendmsg ("sendmsg" int
236                                (socket int)
237                                (msg (* msghdr))
238                                (flags int)))
239  (:function gethostbyname ("gethostbyname" (* hostent) (name c-string)))
240  #+darwin
241  (:function gethostbyname2 ("gethostbyname2" (* hostent)
242                                              (name c-string)
243                                              (af int)))
244  (:function gethostbyaddr ("gethostbyaddr" (* hostent)
245                                            (addr (* t))
246                                            (len int)
247                                            (af int)))
248
249  ;; Re-entrant gethostbyname
250
251  #+linux
252  (:function gethostbyname-r ("gethostbyname_r"
253                              int
254                              (name c-string)
255                              (ret (* hostent))
256                              (buf (* char))
257                              (buflen long)
258                              (result (* (* hostent)))
259                              (h-errnop (* int))))
260  ;; getaddrinfo / getnameinfo
261
262  #+sb-bsd-sockets-addrinfo
263  (:structure addrinfo ("struct addrinfo"
264                        (integer flags "int" "ai_flags")
265                        (integer family "int" "ai_family")
266                        (integer socktype "int" "ai_socktype")
267                        (integer protocol "int" "ai_protocol")
268                        ;; CLH 20070306 FIXME: ai_addrlen should really
269                        ;; be a socklen_t, but I'm not sure if this the
270                        ;; case on other platforms. I'm setting this to
271                        ;; socklen_t on darwin and hoping that other
272                        ;; platform maintainers will do the right thing
273                        ;; here.
274                        #+darwin (integer addrlen "socklen_t" "ai_addrlen")
275                        #-darwin (integer addrlen "size_t" "ai_addrlen")
276                        ((* sockaddr-in) addr "struct sockaddr*" "ai_addr")
277                        (c-string canonname "char *" "ai_canonname")
278                        ((* t) next "struct addrinfo*" "ai_next")))
279
280  #+sb-bsd-sockets-addrinfo
281  (:function getaddrinfo ("getaddrinfo"
282                          int
283                          (node c-string)
284                          (service c-string)
285                          (hints (* addrinfo))
286                          (res (* (* addrinfo)))))
287
288  #+sb-bsd-sockets-addrinfo
289  (:function freeaddrinfo ("freeaddrinfo"
290                           void
291                           (res (* addrinfo))))
292
293  #+sb-bsd-sockets-addrinfo
294  (:function gai-strerror ("gai_strerror"
295                          c-string
296                          (error-code int)))
297
298  #+sb-bsd-sockets-addrinfo
299  (:function getnameinfo ("getnameinfo"
300                          int
301                          (address (* sockaddr-in))
302                          (address-length size-t)
303                          (host (* char))
304                          (host-len size-t)
305                          (service (* char))
306                          (service-len size-t)
307                          (flags int)))
308
309  (:integer EAI-FAMILY "EAI_FAMILY")
310  (:integer EAI-SOCKTYPE "EAI_SOCKTYPE")
311  (:integer EAI-BADFLAGS "EAI_BADFLAGS")
312  (:integer EAI-NONAME "EAI_NONAME")
313  (:integer EAI-SERVICE "EAI_SERVICE")
314  #-freebsd
315  (:integer EAI-ADDRFAMILY "EAI_ADDRFAMILY")
316  (:integer EAI-MEMORY "EAI_MEMORY")
317  (:integer EAI-FAIL "EAI_FAIL")
318  (:integer EAI-AGAIN "EAI_AGAIN")
319  (:integer EAI-SYSTEM "EAI_SYSTEM")
320
321  (:integer NI-NAMEREQD "NI_NAMEREQD")
322
323  ;; Socket options
324
325  (:function setsockopt ("setsockopt" int
326                         (socket int)
327                         (level int)
328                         (optname int)
329                         (optval (* t))
330                         (optlen int))) ;;; should be socklen-t!
331  (:function fcntl ("fcntl" int
332                    (fd int)
333                    (cmd int)
334                    (arg long)))
335  (:function getsockopt ("getsockopt" int
336                         (socket int)
337                         (level int)
338                         (optname int)
339                         (optval (* t))
340                         (optlen (* int)))) ;;; should be socklen-t!
341  )