mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-12-24 05:18:07 -05:00
syscalls: Add network-interface-running?
* guix/build/syscalls.scm (network-interface-running?): New variable. Export it. * tests/syscalls.scm: Add test. Co-authored-by: John Darrington <jmd@gnu.org>
This commit is contained in:
parent
839ee8d547
commit
0bc6fe323d
2 changed files with 19 additions and 0 deletions
|
@ -92,6 +92,7 @@ (define-module (guix build syscalls)
|
|||
all-network-interface-names
|
||||
network-interface-names
|
||||
network-interface-netmask
|
||||
network-interface-running?
|
||||
loopback-network-interface?
|
||||
network-interface-address
|
||||
set-network-interface-netmask
|
||||
|
@ -1156,6 +1157,7 @@ (define SIOCDELRT
|
|||
(define-as-needed IFF_UP #x1) ;Interface is up
|
||||
(define-as-needed IFF_BROADCAST #x2) ;Broadcast address valid.
|
||||
(define-as-needed IFF_LOOPBACK #x8) ;Is a loopback net.
|
||||
(define-as-needed IFF_RUNNING #x40) ;interface RFC2863 OPER_UP
|
||||
|
||||
(define IF_NAMESIZE 16) ;maximum interface name size
|
||||
|
||||
|
@ -1330,6 +1332,13 @@ (define (loopback-network-interface? name)
|
|||
(close-port sock)
|
||||
(not (zero? (logand flags IFF_LOOPBACK)))))
|
||||
|
||||
(define (network-interface-running? name)
|
||||
"Return true if NAME designates a running network interface."
|
||||
(let* ((sock (socket SOCK_STREAM AF_INET 0))
|
||||
(flags (network-interface-flags sock name)))
|
||||
(close-port sock)
|
||||
(not (zero? (logand flags IFF_RUNNING)))))
|
||||
|
||||
(define-as-needed (set-network-interface-flags socket name flags)
|
||||
"Set the flag of network interface NAME to FLAGS."
|
||||
(let ((req (make-bytevector ifreq-struct-size)))
|
||||
|
|
|
@ -361,6 +361,16 @@ (define perform-container-tests?
|
|||
(lambda args
|
||||
(system-error-errno args)))))
|
||||
|
||||
(test-equal "loopback-network-interface-running?"
|
||||
ENODEV
|
||||
(and (network-interface-running? "lo")
|
||||
(catch 'system-error
|
||||
(lambda ()
|
||||
(network-interface-running? "nonexistent")
|
||||
#f)
|
||||
(lambda args
|
||||
(system-error-errno args)))))
|
||||
|
||||
(test-skip (if (zero? (getuid)) 1 0))
|
||||
(test-assert "set-network-interface-flags"
|
||||
(let ((sock (socket AF_INET SOCK_STREAM 0)))
|
||||
|
|
Loading…
Reference in a new issue