[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#63516: [PATCH Guile-Netlink 07/11] addr: Extract 'new-address-messag
From: |
Ludovic Courtès |
Subject: |
bug#63516: [PATCH Guile-Netlink 07/11] addr: Extract 'new-address-message->address'. |
Date: |
Tue, 23 May 2023 14:39:47 +0200 |
* ip/addr.scm (new-address-message->address): New procedure.
(get-addrs): Use it, and use 'filter-map' instead of 'filter' followed
by 'map'.
---
ip/addr.scm | 40 +++++++++++++++++++---------------------
1 file changed, 19 insertions(+), 21 deletions(-)
diff --git a/ip/addr.scm b/ip/addr.scm
index fcb286f..f82d733 100644
--- a/ip/addr.scm
+++ b/ip/addr.scm
@@ -183,6 +183,24 @@
(close-port sock)
(answer-ok? (last answer)))))
+(define (new-address-message->address msg)
+ "If MSG has type 'RTM_NEWADDR', return the corresponding <addr> object.
+Otherwise return #f."
+ (and (eqv? (message-kind msg) RTM_NEWADDR)
+ (let* ((data (message-data msg))
+ (attrs (addr-message-attrs data)))
+ (make-addr (addr-message-family data)
+ (addr-message-prefix-len data)
+ (map int->ifa-flag
+ (split-flags (logior (addr-message-flags data)
+ (get-attr attrs IFA_FLAGS))))
+ (addr-message-scope data)
+ (addr-message-index data)
+ (get-attr attrs IFA_LABEL)
+ (get-attr attrs IFA_ADDRESS)
+ (get-attr attrs IFA_BROADCAST)
+ (get-attr attrs IFA_CACHEINFO)))))
+
(define (get-addrs)
(define request-num (random 65535))
(define message
@@ -195,27 +213,7 @@
(let ((sock (connect-route)))
(send-msg message sock)
(let* ((answer (receive-and-decode-msg sock %default-route-decoder))
- (addrs (filter
- (lambda (msg) (equal? (message-kind msg) RTM_NEWADDR))
- answer))
- (addrs (map
- (lambda (msg)
- (let* ((data (message-data msg))
- (attrs (addr-message-attrs data)))
- (make-addr
- (addr-message-family data)
- (addr-message-prefix-len data)
- (map
- int->ifa-flag
- (split-flags (logior (addr-message-flags data)
- (get-attr attrs IFA_FLAGS))))
- (addr-message-scope data)
- (addr-message-index data)
- (get-attr attrs IFA_LABEL)
- (get-attr attrs IFA_ADDRESS)
- (get-attr attrs IFA_BROADCAST)
- (get-attr attrs IFA_CACHEINFO))))
- addrs)))
+ (addrs (filter-map new-address-message->address answer)))
(close-port sock)
addrs)))
--
2.40.1
- bug#63516: Static networking should wait for interfaces to be up, Ludovic Courtès, 2023/05/15
- bug#63516: Static networking should wait for interfaces to be up, Ludovic Courtès, 2023/05/20
- bug#63516: [PATCH Guile-Netlink 00/11] Add 'wait-for-link' and related code, Ludovic Courtès, 2023/05/23
- bug#63516: [PATCH Guile-Netlink 07/11] addr: Extract 'new-address-message->address'.,
Ludovic Courtès <=
- bug#63516: [PATCH Guile-Netlink 04/11] connection: Add support for suspendable sockets., Ludovic Courtès, 2023/05/23
- bug#63516: [PATCH Guile-Netlink 02/11] connection: Use Guile's 'socket' procedure to open a socket., Ludovic Courtès, 2023/05/23
- bug#63516: [PATCH Guile-Netlink 01/11] connection: Remove unused procedure., Ludovic Courtès, 2023/05/23
- bug#63516: [PATCH Guile-Netlink 03/11] connection: Throw upon errors in FFI bindings., Ludovic Courtès, 2023/05/23
- bug#63516: [PATCH Guile-Netlink 08/11] connection: Add 'add-socket-membership'., Ludovic Courtès, 2023/05/23
- bug#63516: [PATCH Guile-Netlink 10/11] doc: Add indexes., Ludovic Courtès, 2023/05/23
- bug#63516: [PATCH Guile-Netlink 09/11] error: Add 'sub-type' field to '&netlink-decoder-error' and use it., Ludovic Courtès, 2023/05/23
- bug#63516: [PATCH Guile-Netlink 11/11] link: Add 'wait-for-link'., Ludovic Courtès, 2023/05/23
- bug#63516: [PATCH Guile-Netlink 06/11] link: Extract 'new-link-message->link'., Ludovic Courtès, 2023/05/23
- bug#63516: [PATCH Guile-Netlink 05/11] connection: Allow users to pass extra SOCK_ flags to 'socket'., Ludovic Courtès, 2023/05/23