renamed base-classes.lisp to base-sockets.lisp
[iolib.git] / alien-functions.lisp
blobd20c9f7bcd65d81391161c4c57bd148ba5216a78
1 ;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp -*-
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4 ; Copyright (C) 2006 by Stelian Ionescu ;
5 ; ;
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. ;
10 ; ;
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. ;
15 ; ;
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)
28 ;; very ugly hack :(
30 (defmacro grovel-enum-members (enum)
31 (let ((deflist (gensym)))
32 `(let (,deflist)
33 (loop for (member . value)
34 in (slot-value (slot-value (slot-value (make-alien ,enum)
35 'sb-alien::type)
36 'sb-alien::to)
37 'sb-alien::from)
38 do (push (list 'defconstant (intern (symbol-name member)) value)
39 ,deflist))
40 (eval (cons 'progn ,deflist)))))
43 ;;;;;;;;;;;;;;;;
44 ;;; ;;;
45 ;;; unistd.h ;;;
46 ;;; ;;;
47 ;;;;;;;;;;;;;;;;
49 (define-alien-routine "sysconf" long
50 (name int))
52 (define-alien-routine "pread" ssize-t
53 (fd int)
54 (buf (* t))
55 (count size-t)
56 (offset off-t))
58 (define-alien-routine "pwrite" ssize-t
59 (fd int)
60 (buf (* t))
61 (count size-t)
62 (offset off-t))
65 ;;;;;;;;;;;;;;;;;
66 ;;; ;;;
67 ;;; sys/uio.h ;;;
68 ;;; ;;;
69 ;;;;;;;;;;;;;;;;;
71 (define-alien-routine "readv" ssize-t
72 (fd int)
73 (iov (* (struct iovec)))
74 (count int))
76 (define-alien-routine "writev" ssize-t
77 (fd int)
78 (iov (* (array (struct iovec) 0)))
79 (count int))
82 ;;;;;;;;;;;;;;;;;;;;
83 ;;; ;;;
84 ;;; sys/socket.h ;;;
85 ;;; ;;;
86 ;;;;;;;;;;;;;;;;;;;;
88 (define-alien-routine "accept" int
89 (socket int)
90 (address (* t))
91 (addrlen (* socklen-t)))
93 (define-alien-routine "bind" int
94 (socket int)
95 (address (* t))
96 (addrlen socklen-t))
98 (define-alien-routine "connect" int
99 (socket int)
100 (address (* t))
101 (addrlen socklen-t))
103 (define-alien-routine "getpeername" int
104 (socket int)
105 (address (* t))
106 (addrlen (* socklen-t)))
108 (define-alien-routine "getsockname" int
109 (socket int)
110 (address (* t))
111 (addrlen (* socklen-t)))
113 (define-alien-routine "getsockopt" int
114 (socket int)
115 (level int)
116 (optname int)
117 (optval (* t))
118 (optlen (* socklen-t)))
120 (define-alien-routine "listen" int
121 (socket int)
122 (backlog int))
124 (define-alien-routine "recv" ssize-t
125 (socket int)
126 (buffer (* t))
127 (length size-t)
128 (flags int))
130 (define-alien-routine "recvfrom" ssize-t
131 (socket int)
132 (buffer (* t))
133 (length size-t)
134 (flags int)
135 (address (* t))
136 (addrlen (* socklen-t)))
138 (define-alien-routine "recvmsg" ssize-t
139 (socket int)
140 (message (* (struct msghdr)))
141 (flags int))
143 (define-alien-routine "send" ssize-t
144 (socket int)
145 (buffer (* t))
146 (length size-t)
147 (flags int))
149 (define-alien-routine "sendmsg" ssize-t
150 (socket int)
151 (message (* (struct msghdr)))
152 (flags int))
154 (define-alien-routine "sendto" ssize-t
155 (socket int)
156 (message (* t))
157 (length size-t)
158 (flags int)
159 (destaddr (* t))
160 (destlen socklen-t))
162 (define-alien-routine "setsockopt" int
163 (socket int)
164 (level int)
165 (optname int)
166 (optval (* t))
167 (optlen socklen-t))
169 (define-alien-routine "shutdown" int
170 (socket int)
171 (how int))
173 (define-alien-routine "socket" int
174 (domain int)
175 (type int)
176 (protocol int))
178 (define-alien-routine "sockatmark" int
179 (socket int))
181 (define-alien-routine "socketpair" int
182 (domain int)
183 (type int)
184 (protocol int)
185 (socket-vector (* (array int 2))))
188 ;;;;;;;;;;;;;;;;;;;;
189 ;;; ;;;
190 ;;; netinet/un.h ;;;
191 ;;; ;;;
192 ;;;;;;;;;;;;;;;;;;;;
194 (defconstant unix-path-max #+linux 108
195 #+freebsd 104)
198 ;;;;;;;;;;;;;;;;;;;;
199 ;;; ;;;
200 ;;; netinet/in.h ;;;
201 ;;; ;;;
202 ;;;;;;;;;;;;;;;;;;;;
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 ;;;;;;;;;;;;;;;;;;;;;
211 ;;; ;;;
212 ;;; netinet/tcp.h ;;;
213 ;;; ;;;
214 ;;;;;;;;;;;;;;;;;;;;;
216 #+linux
217 (grovel-enum-members connstates)
219 ;;;;;;;;;;;;;;;
220 ;;; ;;;
221 ;;; netdb.h ;;;
222 ;;; ;;;
223 ;;;;;;;;;;;;;;;
225 (define-alien-routine "freeaddrinfo" void
226 (ai (* (struct addrinfo))))
228 (define-alien-routine "getaddrinfo" int
229 (nodename c-string)
230 (servname c-string)
231 (hints (* (struct addrinfo)))
232 (result (* (* (struct addrinfo)))))
234 (define-alien-routine "getnameinfo" int
235 (sa (* t))
236 (salen socklen-t)
237 (node (* (array char 0)))
238 (nodelen socklen-t)
239 (service (* (array char 0)))
240 (servicelen socklen-t)
241 (flags int))
243 (define-alien-routine "gai_strerror" c-string
244 (ercode int))
246 (define-alien-routine "endprotoent" void)
248 (define-alien-routine "getprotobyname" (* (struct protoent))
249 (name c-string))
251 (define-alien-routine "getprotobynumber" (* (struct protoent))
252 (proto int))
254 (define-alien-routine "getprotoent" (* (struct protoent)))
256 (define-alien-routine "setprotoent" void
257 (stayopen int))
260 ;;;;;;;;;;;;;;;;
261 ;;; ;;;
262 ;;; net/if.h ;;;
263 ;;; ;;;
264 ;;;;;;;;;;;;;;;;
266 (define-alien-routine "if_nametoindex" unsigned
267 (ifname c-string))
269 (define-alien-routine "if_indextoname" c-string
270 (ifindex unsigned)
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))))
279 ;;;;;;;;;;;;;;;;;;;
280 ;;; ;;;
281 ;;; arpa/inet.h ;;;
282 ;;; ;;;
283 ;;;;;;;;;;;;;;;;;;;
285 (define-alien-routine "inet_ntop" c-string
286 (family int)
287 (src (* t))
288 (dest (* (array char 0)))
289 (size socklen-t))
291 (define-alien-routine "inet_pton" int
292 (family int)
293 (src c-string)
294 (dest (* t)))
296 ;;;;;;;;;;;;;;;;
297 ;;; ;;;
298 ;;; string.h ;;;
299 ;;; ;;;
300 ;;;;;;;;;;;;;;;;
302 (define-alien-routine "memset" (* t)
303 (buffer (* t))
304 (value int)
305 (length size-t))