aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan (janneke) Nieuwenhuizen <janneke@gnu.org>2020-05-09 08:43:39 +0200
committerJan Nieuwenhuizen <janneke@gnu.org>2020-05-15 10:08:56 +0200
commit0d371c633f7308cfde2432d6119d386a5c63198c (patch)
tree030971d843f1d137ec2859f426998d98735d64a5
parentdff31d41d945bf4b25ad3014dac32561bfbb33a0 (diff)
downloadpatches-0d371c633f7308cfde2432d6119d386a5c63198c.tar
patches-0d371c633f7308cfde2432d6119d386a5c63198c.tar.gz
syscalls: Adjust 'sockaddr-in', 'sockaddr-in6' structs for the Hurd.
* guix/build/syscalls.scm (sockaddr-in,sockaddr-in6): Rename to ... (sockaddr-in/linux, sockaddr-in6/linux): ... this. Rename introduced bindings as well. (write-socket-address!/linux,read-socket-address/linux): Rename from (write-socket-address!, read-socket-address): ... new switches between those and ... (write-socket-address!/hurd, read-socket-address/hurd): ... these new function.
-rw-r--r--guix/build/syscalls.scm113
1 files changed, 91 insertions, 22 deletions
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index ff008c5b78..8070c5546f 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -1315,62 +1315,131 @@ bytes."
40
32))
-(define-c-struct sockaddr-in ;<linux/in.h>
- sizeof-sockaddrin
+(define-c-struct sockaddr-in/linux ;<linux/in.h>
+ sizeof-sockaddr-in/linux
(lambda (family port address)
(make-socket-address family address port))
- read-sockaddr-in
- write-sockaddr-in!
+ read-sockaddr-in/linux
+ write-sockaddr-in!/linux
(family unsigned-short)
(port (int16 ~ big))
(address (int32 ~ big)))
-(define-c-struct sockaddr-in6 ;<linux/in6.h>
- sizeof-sockaddr-in6
+(define-c-struct sockaddr-in/hurd ;<netinet/in.h>
+ sizeof-sockaddr-in/hurd
+ (lambda (len family port address zero)
+ (make-socket-address family address port))
+ read-sockaddr-in/hurd
+ write-sockaddr-in!/hurd
+ (len uint8)
+ (family uint8)
+ (port (int16 ~ big))
+ (address (int32 ~ big))
+ (zero (array uint8 8)))
+
+(define-c-struct sockaddr-in6/linux ;<linux/in6.h>
+ sizeof-sockaddr-in6/linux
(lambda (family port flowinfo address scopeid)
(make-socket-address family address port flowinfo scopeid))
- read-sockaddr-in6
- write-sockaddr-in6!
+ read-sockaddr-in6/linux
+ write-sockaddr-in6!/linux
(family unsigned-short)
(port (int16 ~ big))
(flowinfo (int32 ~ big))
(address (int128 ~ big))
(scopeid int32))
-(define (write-socket-address! sockaddr bv index)
+(define-c-struct sockaddr-in6/hurd ;<netinet/in.h>
+ sizeof-sockaddr-in6/hurd
+ (lambda (len family port flowinfo address scopeid)
+ (make-socket-address family address port flowinfo scopeid))
+ read-sockaddr-in6/hurd
+ write-sockaddr-in6!/hurd
+ (len uint8)
+ (family uint8)
+ (port (int16 ~ big))
+ (flowinfo (int32 ~ big))
+ (address (int128 ~ big))
+ (scopeid int32))
+
+(define (write-socket-address!/linux sockaddr bv index)
+ "Write SOCKADDR, a socket address as returned by 'make-socket-address', to
+bytevector BV at INDEX."
+ (let ((family (sockaddr:fam sockaddr)))
+ (cond ((= family AF_INET)
+ (write-sockaddr-in!/linux bv index
+ family
+ (sockaddr:port sockaddr)
+ (sockaddr:addr sockaddr)))
+ ((= family AF_INET6)
+ (write-sockaddr-in6!/linux bv index
+ family
+ (sockaddr:port sockaddr)
+ (sockaddr:flowinfo sockaddr)
+ (sockaddr:addr sockaddr)
+ (sockaddr:scopeid sockaddr)))
+ (else
+ (error "unsupported socket address" sockaddr)))))
+
+(define (write-socket-address!/hurd sockaddr bv index)
"Write SOCKADDR, a socket address as returned by 'make-socket-address', to
bytevector BV at INDEX."
(let ((family (sockaddr:fam sockaddr)))
(cond ((= family AF_INET)
- (write-sockaddr-in! bv index
- family
- (sockaddr:port sockaddr)
- (sockaddr:addr sockaddr)))
+ (write-sockaddr-in!/hurd bv index
+ sizeof-sockaddr-in/hurd
+ family
+ (sockaddr:port sockaddr)
+ (sockaddr:addr sockaddr)
+ '(0 0 0 0 0 0 0 0)))
((= family AF_INET6)
- (write-sockaddr-in6! bv index
- family
- (sockaddr:port sockaddr)
- (sockaddr:flowinfo sockaddr)
- (sockaddr:addr sockaddr)
- (sockaddr:scopeid sockaddr)))
+ (write-sockaddr-in6!/hurd bv index
+ sizeof-sockaddr-in6/hurd
+ family
+ (sockaddr:port sockaddr)
+ (sockaddr:flowinfo sockaddr)
+ (sockaddr:addr sockaddr)
+ (sockaddr:scopeid sockaddr)))
(else
(error "unsupported socket address" sockaddr)))))
+(define write-socket-address!
+ (if (string-suffix? "linux-gnu" %host-type)
+ write-socket-address!/linux
+ write-socket-address!/hurd))
+
(define PF_PACKET 17) ;<bits/socket.h>
(define AF_PACKET PF_PACKET)
-(define* (read-socket-address bv #:optional (index 0))
+(define* (read-socket-address/linux bv #:optional (index 0))
+ "Read a socket address from bytevector BV at INDEX."
+ (let ((family (bytevector-u16-native-ref bv index)))
+ (cond ((= family AF_INET)
+ (read-sockaddr-in/linux bv index))
+ ((= family AF_INET6)
+ (read-sockaddr-in6/linux bv index))
+ (else
+ ;; XXX: Unsupported address family, such as AF_PACKET. Return a
+ ;; vector such that the vector can at least call 'sockaddr:fam'.
+ (vector family)))))
+
+(define* (read-socket-address/hurd bv #:optional (index 0))
"Read a socket address from bytevector BV at INDEX."
(let ((family (bytevector-u16-native-ref bv index)))
(cond ((= family AF_INET)
- (read-sockaddr-in bv index))
+ (read-sockaddr-in/hurd bv index))
((= family AF_INET6)
- (read-sockaddr-in6 bv index))
+ (read-sockaddr-in6/hurd bv index))
(else
;; XXX: Unsupported address family, such as AF_PACKET. Return a
;; vector such that the vector can at least call 'sockaddr:fam'.
(vector family)))))
+(define read-socket-address
+ (if (string-suffix? "linux-gnu" %host-type)
+ read-socket-address/linux
+ read-socket-address/hurd))
+
(define %ioctl
;; The most terrible interface, live from Scheme.
(syscall->procedure int "ioctl" (list int unsigned-long '*)))