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