From c9bf64d6d777baf2603b5d6a52c5c5b9adf649cd Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 19 Dec 2014 14:26:11 +0100 Subject: syscalls: Add more procedures for network interfaces. * guix/build/syscalls.scm (sizeof*, type-size, write-type, write-types, read-type, read-types, define-c-struct): New macros. (SIOCSIFFLAGS, SIOCGIFADDR, SIOCSIFADDR): New variables. (sockaddr-in, sockaddr-in6): New C structs. (write-socket-address!, read-socket-address, set-network-interface-flags, set-network-interface-address, network-interface-address, configure-network-interface): New procedures. --- tests/syscalls.scm | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'tests/syscalls.scm') diff --git a/tests/syscalls.scm b/tests/syscalls.scm index d65ec82740..21d6637ff6 100644 --- a/tests/syscalls.scm +++ b/tests/syscalls.scm @@ -74,7 +74,7 @@ (lset<= string=? names (all-network-interfaces))))) (test-assert "network-interface-flags" - (let* ((sock (socket SOCK_STREAM AF_INET 0)) + (let* ((sock (socket AF_INET SOCK_STREAM 0)) (flags (network-interface-flags sock "lo"))) (close-port sock) (and (not (zero? (logand flags IFF_LOOPBACK))) @@ -90,6 +90,38 @@ (lambda args (system-error-errno args))))) +(test-skip (if (zero? (getuid)) 1 0)) +(test-equal "set-network-interface-flags" + EPERM + (let ((sock (socket AF_INET SOCK_STREAM 0))) + (catch 'system-error + (lambda () + (set-network-interface-flags sock "lo" IFF_UP)) + (lambda args + (close-port sock) + (system-error-errno args))))) + +(test-equal "network-interface-address lo" + (make-socket-address AF_INET (inet-pton AF_INET "127.0.0.1") 0) + (let* ((sock (socket AF_INET SOCK_STREAM 0)) + (addr (network-interface-address sock "lo"))) + (close-port sock) + addr)) + +(test-equal "set-network-interface-address" + EPERM + (let ((sock (socket AF_INET SOCK_STREAM 0))) + (catch 'system-error + (lambda () + (set-network-interface-address sock "nonexistent" + (make-socket-address + AF_INET + (inet-pton AF_INET "127.12.14.15") + 0))) + (lambda args + (close-port sock) + (system-error-errno args))))) + (test-end) -- cgit v1.2.3