syscalls: Use 'define-c-struct' for 'struct ifconf'.
* guix/build/syscalls.scm (ifconf-struct): Remove. (%ifconf-struct): New C struct. (network-interface-names): Use 'make-bytevector' and 'write-ifconf!' instead of 'make-c-struct', and 'read-ifconf' instead of 'parse-c-struct'.
This commit is contained in:
parent
f43714e620
commit
9d9d0c9c98
|
@ -773,10 +773,13 @@ exception if it's already taken."
|
||||||
|
|
||||||
(define IF_NAMESIZE 16) ;maximum interface name size
|
(define IF_NAMESIZE 16) ;maximum interface name size
|
||||||
|
|
||||||
(define ifconf-struct
|
(define-c-struct %ifconf-struct
|
||||||
;; 'struct ifconf', from <net/if.h>.
|
sizeof-ifconf
|
||||||
(list int ;int ifc_len
|
list
|
||||||
'*)) ;struct ifreq *ifc_ifcu
|
read-ifconf
|
||||||
|
write-ifconf!
|
||||||
|
(length int) ;int ifc_len
|
||||||
|
(request '*)) ;struct ifreq *ifc_ifcu
|
||||||
|
|
||||||
(define ifreq-struct-size
|
(define ifreq-struct-size
|
||||||
;; 'struct ifreq' begins with an array of IF_NAMESIZE bytes containing the
|
;; 'struct ifreq' begins with an array of IF_NAMESIZE bytes containing the
|
||||||
|
@ -868,15 +871,18 @@ to interfaces that are currently up."
|
||||||
(sock (or sock (socket SOCK_STREAM AF_INET 0)))
|
(sock (or sock (socket SOCK_STREAM AF_INET 0)))
|
||||||
(len (* ifreq-struct-size 10))
|
(len (* ifreq-struct-size 10))
|
||||||
(reqs (make-bytevector len))
|
(reqs (make-bytevector len))
|
||||||
(conf (make-c-struct ifconf-struct
|
(conf (make-bytevector sizeof-ifconf)))
|
||||||
(list len (bytevector->pointer reqs)))))
|
(write-ifconf! conf 0
|
||||||
|
len (bytevector->pointer reqs))
|
||||||
|
|
||||||
(let-values (((ret err)
|
(let-values (((ret err)
|
||||||
(%ioctl (fileno sock) SIOCGIFCONF conf)))
|
(%ioctl (fileno sock) SIOCGIFCONF
|
||||||
|
(bytevector->pointer conf))))
|
||||||
(when close?
|
(when close?
|
||||||
(close-port sock))
|
(close-port sock))
|
||||||
(if (zero? ret)
|
(if (zero? ret)
|
||||||
(bytevector->string-list reqs ifreq-struct-size
|
(bytevector->string-list reqs ifreq-struct-size
|
||||||
(match (parse-c-struct conf ifconf-struct)
|
(match (read-ifconf conf)
|
||||||
((len . _) len)))
|
((len . _) len)))
|
||||||
(throw 'system-error "network-interface-list"
|
(throw 'system-error "network-interface-list"
|
||||||
"network-interface-list: ~A"
|
"network-interface-list: ~A"
|
||||||
|
|
Loading…
Reference in New Issue