summaryrefslogtreecommitdiff
path: root/tests/syscalls.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2015-07-25 13:06:01 +0200
committerLudovic Courtès <ludo@gnu.org>2015-07-25 14:43:45 +0200
commite7f5691d4540e2cbcbc9f22f8b593f15890057b3 (patch)
tree8428f0d6c6d255c684cc99ca8f26d7876f6f98f8 /tests/syscalls.scm
parent573b4c1ff3409fb4417ec676091f6bbc09219f19 (diff)
downloadgnu-guix-e7f5691d4540e2cbcbc9f22f8b593f15890057b3.tar
gnu-guix-e7f5691d4540e2cbcbc9f22f8b593f15890057b3.tar.gz
syscalls: Add 'network-interfaces', which wraps libc's 'getifaddrs'.
Based on discussions with Rohan Prinja <rohan.prinja@gmail.com>. * guix/build/syscalls.scm (<interface>): New record type. (write-interface, values->interface, unfold-interface-list, network-interfaces, free-ifaddrs): New procedures. (ifaddrs): New C struct. (%struct-ifaddrs-type, %sizeof-ifaddrs): New macros. * tests/syscalls.scm ("network-interfaces returns one or more interfaces", "network-interfaces returns \"lo\""): New tests.
Diffstat (limited to 'tests/syscalls.scm')
-rw-r--r--tests/syscalls.scm23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/syscalls.scm b/tests/syscalls.scm
index 3b71cd7b1c..090e1e7858 100644
--- a/tests/syscalls.scm
+++ b/tests/syscalls.scm
@@ -211,6 +211,29 @@
;; We get EPERM with Linux 3.18ish and EACCES with 2.6.32.
(memv (system-error-errno args) (list EPERM EACCES))))))
+(test-equal "network-interfaces returns one or more interfaces"
+ '(#t #t #t)
+ (match (network-interfaces)
+ ((interfaces ..1)
+ (list (every interface? interfaces)
+ (every string? (map interface-name interfaces))
+ (every vector? (map interface-address interfaces))))))
+
+(test-equal "network-interfaces returns \"lo\""
+ (list #t (make-socket-address AF_INET (inet-pton AF_INET "127.0.0.1") 0))
+ (match (filter (lambda (interface)
+ (string=? "lo" (interface-name interface)))
+ (network-interfaces))
+ ((loopbacks ..1)
+ (list (every (lambda (lo)
+ (not (zero? (logand IFF_LOOPBACK (interface-flags lo)))))
+ loopbacks)
+ (match (find (lambda (lo)
+ (= AF_INET (sockaddr:fam (interface-address lo))))
+ loopbacks)
+ (#f #f)
+ (lo (interface-address lo)))))))
+
(test-end)