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.master
parent
dff31d41d9
commit
0d371c633f
|
@ -1315,62 +1315,131 @@ bytes."
|
||||||
40
|
40
|
||||||
32))
|
32))
|
||||||
|
|
||||||
(define-c-struct sockaddr-in ;<linux/in.h>
|
(define-c-struct sockaddr-in/linux ;<linux/in.h>
|
||||||
sizeof-sockaddrin
|
sizeof-sockaddr-in/linux
|
||||||
(lambda (family port address)
|
(lambda (family port address)
|
||||||
(make-socket-address family address port))
|
(make-socket-address family address port))
|
||||||
read-sockaddr-in
|
read-sockaddr-in/linux
|
||||||
write-sockaddr-in!
|
write-sockaddr-in!/linux
|
||||||
(family unsigned-short)
|
(family unsigned-short)
|
||||||
(port (int16 ~ big))
|
(port (int16 ~ big))
|
||||||
(address (int32 ~ big)))
|
(address (int32 ~ big)))
|
||||||
|
|
||||||
(define-c-struct sockaddr-in6 ;<linux/in6.h>
|
(define-c-struct sockaddr-in/hurd ;<netinet/in.h>
|
||||||
sizeof-sockaddr-in6
|
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)
|
(lambda (family port flowinfo address scopeid)
|
||||||
(make-socket-address family address port flowinfo scopeid))
|
(make-socket-address family address port flowinfo scopeid))
|
||||||
read-sockaddr-in6
|
read-sockaddr-in6/linux
|
||||||
write-sockaddr-in6!
|
write-sockaddr-in6!/linux
|
||||||
(family unsigned-short)
|
(family unsigned-short)
|
||||||
(port (int16 ~ big))
|
(port (int16 ~ big))
|
||||||
(flowinfo (int32 ~ big))
|
(flowinfo (int32 ~ big))
|
||||||
(address (int128 ~ big))
|
(address (int128 ~ big))
|
||||||
(scopeid int32))
|
(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
|
"Write SOCKADDR, a socket address as returned by 'make-socket-address', to
|
||||||
bytevector BV at INDEX."
|
bytevector BV at INDEX."
|
||||||
(let ((family (sockaddr:fam sockaddr)))
|
(let ((family (sockaddr:fam sockaddr)))
|
||||||
(cond ((= family AF_INET)
|
(cond ((= family AF_INET)
|
||||||
(write-sockaddr-in! bv index
|
(write-sockaddr-in!/linux bv index
|
||||||
family
|
family
|
||||||
(sockaddr:port sockaddr)
|
(sockaddr:port sockaddr)
|
||||||
(sockaddr:addr sockaddr)))
|
(sockaddr:addr sockaddr)))
|
||||||
((= family AF_INET6)
|
((= family AF_INET6)
|
||||||
(write-sockaddr-in6! bv index
|
(write-sockaddr-in6!/linux bv index
|
||||||
family
|
family
|
||||||
(sockaddr:port sockaddr)
|
(sockaddr:port sockaddr)
|
||||||
(sockaddr:flowinfo sockaddr)
|
(sockaddr:flowinfo sockaddr)
|
||||||
(sockaddr:addr sockaddr)
|
(sockaddr:addr sockaddr)
|
||||||
(sockaddr:scopeid sockaddr)))
|
(sockaddr:scopeid sockaddr)))
|
||||||
(else
|
(else
|
||||||
(error "unsupported socket address" sockaddr)))))
|
(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!/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!/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 PF_PACKET 17) ;<bits/socket.h>
|
||||||
(define AF_PACKET PF_PACKET)
|
(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."
|
"Read a socket address from bytevector BV at INDEX."
|
||||||
(let ((family (bytevector-u16-native-ref bv index)))
|
(let ((family (bytevector-u16-native-ref bv index)))
|
||||||
(cond ((= family AF_INET)
|
(cond ((= family AF_INET)
|
||||||
(read-sockaddr-in bv index))
|
(read-sockaddr-in/linux bv index))
|
||||||
((= family AF_INET6)
|
((= family AF_INET6)
|
||||||
(read-sockaddr-in6 bv index))
|
(read-sockaddr-in6/linux bv index))
|
||||||
(else
|
(else
|
||||||
;; XXX: Unsupported address family, such as AF_PACKET. Return a
|
;; XXX: Unsupported address family, such as AF_PACKET. Return a
|
||||||
;; vector such that the vector can at least call 'sockaddr:fam'.
|
;; vector such that the vector can at least call 'sockaddr:fam'.
|
||||||
(vector family)))))
|
(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/hurd bv index))
|
||||||
|
((= family AF_INET6)
|
||||||
|
(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
|
(define %ioctl
|
||||||
;; The most terrible interface, live from Scheme.
|
;; The most terrible interface, live from Scheme.
|
||||||
(syscall->procedure int "ioctl" (list int unsigned-long '*)))
|
(syscall->procedure int "ioctl" (list int unsigned-long '*)))
|
||||||
|
|
Reference in New Issue