96d11a16156b9f5f8120e331aedd1dc7221269b0
[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) "AF_UNIX"
16            #-(or sunos solaris) "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  (:integer so-no-check "SO_NO_CHECK")
51  #+linux (:integer so-priority "SO_PRIORITY")
52  (:integer so-linger "SO_LINGER"
53            "For reliable streams, pause a while on closing when unsent messages are queued")
54  #+linux (:integer so-bsdcompat "SO_BSDCOMPAT")
55  (:integer so-sndlowat "SO_SNDLOWAT")
56  (:integer so-rcvlowat "SO_RCVLOWAT")
57  (:integer so-sndtimeo "SO_SNDTIMEO")
58  (:integer so-rcvtimeo "SO_RCVTIMEO")
59
60  (:integer tcp-nodelay "TCP_NODELAY")
61  #+linux (:integer so-bindtodevice "SO_BINDTODEVICE")
62  (:integer ifnamsiz "IFNAMSIZ")
63
64  (:integer EADDRINUSE "EADDRINUSE")
65  (:integer EAGAIN "EAGAIN")
66  (:integer EBADF "EBADF")
67  (:integer ECONNREFUSED "ECONNREFUSED")
68  (:integer ETIMEDOUT "ETIMEDOUT")
69  (:integer EINTR "EINTR")
70  (:integer EINVAL "EINVAL")
71  (:integer ENOBUFS "ENOBUFS")
72  (:integer ENOMEM "ENOMEM")
73  (:integer EOPNOTSUPP "EOPNOTSUPP")
74  (:integer EPERM "EPERM")
75  (:integer EPROTONOSUPPORT "EPROTONOSUPPORT")
76  (:integer ESOCKTNOSUPPORT "ESOCKTNOSUPPORT")
77  (:integer ENETUNREACH "ENETUNREACH")
78  (:integer ENOTCONN "ENOTCONN")
79
80  (:integer NETDB-INTERNAL "NETDB_INTERNAL" "See errno.")
81  (:integer NETDB-SUCCESS "NETDB_SUCCESS" "No problem.")
82  (:integer HOST-NOT-FOUND "HOST_NOT_FOUND" "Authoritative Answer Host not found.")
83  (:integer TRY-AGAIN "TRY_AGAIN" "Non-Authoritative Host not found, or SERVERFAIL.")
84  (:integer NO-RECOVERY "NO_RECOVERY" "Non recoverable errors, FORMERR, REFUSED, NOTIMP.")
85  (:integer NO-DATA "NO_DATA" "Valid name, no data record of requested type.")
86  (:integer NO-ADDRESS "NO_ADDRESS" "No address, look for MX record.")
87  (:function h-strerror ("hstrerror" c-string (errno int)))
88
89  (:integer O-NONBLOCK "O_NONBLOCK")
90  (:integer f-getfl "F_GETFL")
91  (:integer f-setfl "F_SETFL")
92
93  #+linux (:integer msg-nosignal "MSG_NOSIGNAL")
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  (: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                           (integer family "sa_family_t" "sin_family")
133                           ;; These two could be in-port-t and
134                           ;; in-addr-t, but then we'd throw away the
135                           ;; convenience (and byte-order agnosticism)
136                           ;; of the old sb-grovel scheme.
137                           ((array (unsigned 8)) port "u_int16_t" "sin_port")
138                           ((array (unsigned 8)) addr "struct in_addr" "sin_addr")))
139  (:structure sockaddr-un ("struct sockaddr_un"
140                           (integer family "sa_family_t" "sun_family")
141                           (c-string path "char" "sun_path")))
142  (:structure hostent ("struct hostent"
143                       (c-string-pointer name "char *" "h_name")
144                       ((* c-string) aliases "char **" "h_aliases")
145                       (integer type "int" "h_addrtype")
146                       (integer length "int" "h_length")
147                       ((* (* (unsigned 8))) addresses "char **" "h_addr_list")))
148  (:structure msghdr ("struct msghdr"
149                       (c-string-pointer name "void *" "msg_name")
150                       (integer namelen "socklen_t" "msg_namelen")
151                       ((* t) iov "struct iovec" "msg_iov")
152                       (integer iovlen "size_t" "msg_iovlen")
153                       ((* t) control "void *" "msg_control")
154                       (integer controllen "socklen_t" "msg_controllen")
155                       (integer flags "int" "msg_flags")))
156  (:function socket (#-netbsd "socket" #+netbsd "_socket" int
157                     (domain int)
158                     (type int)
159                     (protocol int)))
160  (:function bind ("bind" int
161                   (sockfd int)
162                   (my-addr (* t))  ; KLUDGE: sockaddr-in or sockaddr-un?
163                   (addrlen socklen-t)))
164  (:function listen ("listen" int
165                     (socket int)
166                     (backlog int)))
167  (:function accept ("accept" int
168                     (socket int)
169                     (my-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
170                     (addrlen socklen-t :in-out)))
171  (:function getpeername ("getpeername" int
172                          (socket int)
173                          (her-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
174                          (addrlen socklen-t :in-out)))
175  (:function getsockname ("getsockname" int
176                          (socket int)
177                          (my-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
178                          (addrlen socklen-t :in-out)))
179  (:function connect ("connect" int
180                     (socket int)
181                     (his-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
182                     (addrlen socklen-t)))
183  (:function close ("close" int
184                    (fd int)))
185  (:function recvfrom ("recvfrom" ssize-t
186                                  (socket int)
187                                  (buf (* t))
188                                  (len integer)
189                                  (flags int)
190                                  (sockaddr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
191                                  (socklen (* socklen-t))))
192  (:function recvmsg ("recvmsg" ssize-t
193                                (socket int)
194                                (msg (* msghdr))
195                                (flags int)))
196  (:function send ("send" ssize-t
197                          (socket int)
198                          (buf (* t))
199                          (len size-t)
200                          (flags int)))
201  (:function sendto ("sendto" int
202                              (socket int)
203                              (buf (* t))
204                              (len size-t)
205                              (flags int)
206                              (sockaddr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
207                              (socklen socklen-t)))
208  (:function sendmsg ("sendmsg" int
209                                (socket int)
210                                (msg (* msghdr))
211                                (flags int)))
212  (:function gethostbyname ("gethostbyname" (* hostent) (name c-string)))
213  (:function gethostbyaddr ("gethostbyaddr" (* hostent)
214                                            (addr (* t))
215                                            (len int)
216                                            (af int)))
217
218  ;; Re-entrant gethostbyname
219
220  #+linux
221  (:function gethostbyname-r ("gethostbyname_r"
222                              int
223                              (name c-string)
224                              (ret (* hostent))
225                              (buf (* char))
226                              (buflen long)
227                              (result (* (* hostent)))
228                              (h-errnop (* int))))
229  ;; getaddrinfo / getnameinfo
230
231  #+sb-bsd-sockets-addrinfo
232  (:structure addrinfo ("struct addrinfo"
233                        (integer flags "int" "ai_flags")
234                        (integer family "int" "ai_family")
235                        (integer socktype "int" "ai_socktype")
236                        (integer protocol "int" "ai_protocol")
237                        (integer addrlen "size_t""ai_addrlen")
238                        ((* sockaddr-in) addr "struct sockaddr*" "ai_addr")
239                        (c-string canonname "char *" "ai_canonname")
240                        ((* t) next "struct addrinfo*" "ai_next")))
241
242  #+sb-bsd-sockets-addrinfo
243  (:function getaddrinfo ("getaddrinfo"
244                          int
245                          (node c-string)
246                          (service c-string)
247                          (hints (* addrinfo))
248                          (res (* (* addrinfo)))))
249
250  #+sb-bsd-sockets-addrinfo
251  (:function freeaddrinfo ("freeaddrinfo"
252                           void
253                           (res (* addrinfo))))
254
255  #+sb-bsd-sockets-addrinfo
256  (:function gai-strerror ("gai_strerror"
257                          c-string
258                          (error-code int)))
259
260  #+sb-bsd-sockets-addrinfo
261  (:function getnameinfo ("getnameinfo"
262                          int
263                          (address (* sockaddr-in))
264                          (address-length size-t)
265                          (host (* char))
266                          (host-len size-t)
267                          (service (* char))
268                          (service-len size-t)
269                          (flags int)))
270
271  (:integer EAI-FAMILY "EAI_FAMILY")
272  (:integer EAI-SOCKTYPE "EAI_SOCKTYPE")
273  (:integer EAI-BADFLAGS "EAI_BADFLAGS")
274  (:integer EAI-NONAME "EAI_NONAME")
275  (:integer EAI-SERVICE "EAI_SERVICE")
276  (:integer EAI-ADDRFAMILY "EAI_ADDRFAMILY")
277  (:integer EAI-NODATA "EAI_NODATA")
278  (:integer EAI-MEMORY "EAI_MEMORY")
279  (:integer EAI-FAIL "EAI_FAIL")
280  (:integer EAI-AGAIN "EAI_AGAIN")
281  (:integer EAI-SYSTEM "EAI_SYSTEM")
282
283  (:integer NI-NAMEREQD "NI_NAMEREQD")
284
285  ;; Socket options
286
287  (:function setsockopt ("setsockopt" int
288                         (socket int)
289                         (level int)
290                         (optname int)
291                         (optval (* t))
292                         (optlen int))) ;;; should be socklen-t!
293  (:function fcntl ("fcntl" int
294                    (fd int)
295                    (cmd int)
296                    (arg long)))
297  (:function getsockopt ("getsockopt" int
298                         (socket int)
299                         (level int)
300                         (optname int)
301                         (optval (* t))
302                         (optlen (* int))))) ;;; should be socklen-t!
303 )