summaryrefslogtreecommitdiff
path: root/guix/build
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2016-11-16 23:13:12 +0100
committerLudovic Courtès <ludo@gnu.org>2016-11-16 23:38:05 +0100
commit9d9d0c9c982449b820eae98d0f2cfa115b618208 (patch)
tree828405a52aba05cb6cb7e92bba4122a975f39d6c /guix/build
parentf43714e62080f8bdf1ddb02672d26527ac3819ec (diff)
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'.
Diffstat (limited to 'guix/build')
-rw-r--r--guix/build/syscalls.scm22
1 files changed, 14 insertions, 8 deletions
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index bdc9940bb3..1ad6cb4618 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -773,10 +773,13 @@ exception if it's already taken."
(define IF_NAMESIZE 16) ;maximum interface name size
-(define ifconf-struct
- ;; 'struct ifconf', from <net/if.h>.
- (list int ;int ifc_len
- '*)) ;struct ifreq *ifc_ifcu
+(define-c-struct %ifconf-struct
+ sizeof-ifconf
+ list
+ read-ifconf
+ write-ifconf!
+ (length int) ;int ifc_len
+ (request '*)) ;struct ifreq *ifc_ifcu
(define ifreq-struct-size
;; '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)))
(len (* ifreq-struct-size 10))
(reqs (make-bytevector len))
- (conf (make-c-struct ifconf-struct
- (list len (bytevector->pointer reqs)))))
+ (conf (make-bytevector sizeof-ifconf)))
+ (write-ifconf! conf 0
+ len (bytevector->pointer reqs))
+
(let-values (((ret err)
- (%ioctl (fileno sock) SIOCGIFCONF conf)))
+ (%ioctl (fileno sock) SIOCGIFCONF
+ (bytevector->pointer conf))))
(when close?
(close-port sock))
(if (zero? ret)
(bytevector->string-list reqs ifreq-struct-size
- (match (parse-c-struct conf ifconf-struct)
+ (match (read-ifconf conf)
((len . _) len)))
(throw 'system-error "network-interface-list"
"network-interface-list: ~A"