1 ;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp -*-
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4 ; Copyright (C) 2006 by Stelian Ionescu ;
6 ; This program is free software; you can redistribute it and/or modify ;
7 ; it under the terms of the GNU General Public License as published by ;
8 ; the Free Software Foundation; either version 2 of the License, or ;
9 ; (at your option) any later version. ;
11 ; This program is distributed in the hope that it will be useful, ;
12 ; but WITHOUT ANY WARRANTY; without even the implied warranty of ;
13 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;
14 ; GNU General Public License for more details. ;
16 ; You should have received a copy of the GNU General Public License ;
17 ; along with this program; if not, write to the ;
18 ; Free Software Foundation, Inc., ;
19 ; 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ;
20 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22 (declaim (optimize (speed 0) (safety 3) (space 0) (debug 2)))
23 ;; (declaim (optimize (speed 3) (safety 0) (space 0) (debug 0)))
25 (in-package #:iolib-alien
)
30 (defmacro grovel-enum-members
(enum)
31 (let ((deflist (gensym)))
33 (loop for
(member . value
)
34 in
(slot-value (slot-value (slot-value (make-alien ,enum
)
38 do
(push (list 'defconstant
(intern (symbol-name member
)) value
)
40 (eval (cons 'progn
,deflist
)))))
49 (define-alien-routine "sysconf" long
52 (define-alien-routine "pread" ssize-t
58 (define-alien-routine "pwrite" ssize-t
71 (define-alien-routine "readv" ssize-t
73 (iov (* (struct iovec
)))
76 (define-alien-routine "writev" ssize-t
78 (iov (* (array (struct iovec
) 0)))
88 (define-alien-routine "accept" int
91 (addrlen (* socklen-t
)))
93 (define-alien-routine "bind" int
98 (define-alien-routine "connect" int
103 (define-alien-routine "getpeername" int
106 (addrlen (* socklen-t
)))
108 (define-alien-routine "getsockname" int
111 (addrlen (* socklen-t
)))
113 (define-alien-routine "getsockopt" int
118 (optlen (* socklen-t
)))
120 (define-alien-routine "listen" int
124 (define-alien-routine "recv" ssize-t
130 (define-alien-routine "recvfrom" ssize-t
136 (addrlen (* socklen-t
)))
138 (define-alien-routine "recvmsg" ssize-t
140 (message (* (struct msghdr
)))
143 (define-alien-routine "send" ssize-t
149 (define-alien-routine "sendmsg" ssize-t
151 (message (* (struct msghdr
)))
154 (define-alien-routine "sendto" ssize-t
162 (define-alien-routine "setsockopt" int
169 (define-alien-routine "shutdown" int
173 (define-alien-routine "socket" int
178 (define-alien-routine "sockatmark" int
181 (define-alien-routine "socketpair" int
185 (socket-vector (* (array int
2))))
194 (defconstant unix-path-max
#+linux
108
204 (define-alien-variable "in6addr_any" (struct in6-addr
))
205 (define-alien-variable "in6addr_loopback" (struct in6-addr
))
206 (define-alien-variable "ipv6mr_multiaddr" (struct in6-addr
))
207 (define-alien-variable "ipv6mr_interface" unsigned
)
210 ;;;;;;;;;;;;;;;;;;;;;
212 ;;; netinet/tcp.h ;;;
214 ;;;;;;;;;;;;;;;;;;;;;
217 (grovel-enum-members connstates
)
225 (define-alien-routine "freeaddrinfo" void
226 (ai (* (struct addrinfo
))))
228 (define-alien-routine "getaddrinfo" int
231 (hints (* (struct addrinfo
)))
232 (result (* (* (struct addrinfo
)))))
234 (define-alien-routine "getnameinfo" int
237 (node (* (array char
0)))
239 (service (* (array char
0)))
240 (servicelen socklen-t
)
243 (define-alien-routine "gai_strerror" c-string
246 (define-alien-routine "endprotoent" void
)
248 (define-alien-routine "getprotobyname" (* (struct protoent
))
251 (define-alien-routine "getprotobynumber" (* (struct protoent
))
254 (define-alien-routine "getprotoent" (* (struct protoent
)))
256 (define-alien-routine "setprotoent" void
266 (define-alien-routine "if_nametoindex" unsigned
269 (define-alien-routine "if_indextoname" c-string
271 (ifname (* (array char
))))
273 (define-alien-routine "if_nameindex" (* (array (struct if-nameindex
) 0)))
275 (define-alien-routine "if_freenameindex" void
276 (pointer (* (array (struct if-nameindex
) 0))))
285 (define-alien-routine "inet_ntop" c-string
288 (dest (* (array char
0)))
291 (define-alien-routine "inet_pton" int
302 (define-alien-routine "memset" (* t
)