diff --git a/cffi-socket.lisp b/cffi-socket.lisp
index ebdfd39..1ccc769 100644
--- a/cffi-socket.lisp
+++ b/cffi-socket.lisp
@@ -71,15 +71,6 @@
;; IP
-(defcstruct sockaddr-in
- (sin-family sa-family-t)
- (sin-port in-port-t)
- (sin-addr uint32-t)
- (sin-zero :unsigned-char :count #.(- (foreign-type-size '(:struct sockaddr))
- (foreign-type-size 'sa-family-t)
- (foreign-type-size 'in-port-t)
- (foreign-type-size 'uint32-t))))
-
(defun inet-addr-from-string (x &key (start 0) (end (length x)))
(ignore-errors
(let ((addr 0))
@@ -157,11 +148,13 @@
(unless addr-var
(setq addr-var (gensym)))
`(multiple-value-bind (,fd-var ,addr-var) (accept ,listening-fd)
- (declare (ignorable ,addr-var))
(unless (eq :non-blocking ,fd-var)
- (unwind-protect (progn ,@body)
+ (unwind-protect (let ((,fd-var ,fd-var)
+ (,addr-var ,addr-var))
+ (declare (ignorable ,addr-var))
+ ,@body)
(shutdown ,fd-var t t)
- (unistd:close ,fd-var)))))
+ (unistd:c-close ,fd-var)))))
(defcfun ("recv" c-recv) ssize-t
(sockfd :int)
diff --git a/grovel-socket.lisp b/grovel-socket.lisp
index 3e131ad..82bc2f1 100644
--- a/grovel-socket.lisp
+++ b/grovel-socket.lisp
@@ -60,3 +60,28 @@
(ctype sa-family-t "sa_family_t")
(ctype in-port-t "in_port_t")
+
+#+linux
+(cstruct sockaddr-in "struct sockaddr_in"
+ (sin-family "sin_family" sa-family-t)
+ (sin-port "sin_port" in-port-t)
+ (sin-addr "sin_addr" uint32-t)
+ (sin-zero "sin_zero" :unsigned-char
+ :count #.(- (foreign-type-size '(:struct sockaddr))
+ (foreign-type-size 'sa-family-t)
+ (foreign-type-size 'in-port-t)
+ (foreign-type-size 'uint32-t))))
+
+#+openbsd
+(ctype u-int-8 "u_int8_t")
+
+#+openbsd
+(ctype in-addr-t "in_addr_t")
+
+#+openbsd
+(cstruct sockaddr-in "struct sockaddr_in"
+ (sin-len "sin_len" :type u-int-8)
+ (sin-family "sin_family" :type sa-family-t)
+ (sin-port "sin_port" :type in-port-t)
+ (sin-addr "sin_addr" :type in-addr-t)
+ (sin-zero "sin_zero" :type :unsigned-char :count 8))