From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id 4BKlCHG0bGT/UwEASxT56A (envelope-from ) for ; Tue, 23 May 2023 14:41:21 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id 0K+0B3G0bGRBdAEAG6o9tA (envelope-from ) for ; Tue, 23 May 2023 14:41:21 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 90FF32DB68 for ; Tue, 23 May 2023 14:41:20 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q1RK8-0001hz-OR; Tue, 23 May 2023 08:41:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1RK6-0001gr-Bw for bug-guix@gnu.org; Tue, 23 May 2023 08:41:06 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q1RK5-0003W5-9q for bug-guix@gnu.org; Tue, 23 May 2023 08:41:06 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q1RK5-000367-4Y for bug-guix@gnu.org; Tue, 23 May 2023 08:41:05 -0400 X-Loop: help-debbugs@gnu.org Subject: bug#63516: [PATCH Guile-Netlink 07/11] addr: Extract 'new-address-message->address'. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Tue, 23 May 2023 12:41:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63516 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: 63516@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 63516-submit@debbugs.gnu.org id=B63516.168484563711775 (code B ref 63516); Tue, 23 May 2023 12:41:05 +0000 Received: (at 63516) by debbugs.gnu.org; 23 May 2023 12:40:37 +0000 Received: from localhost ([127.0.0.1]:38541 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q1RJc-00033k-QB for submit@debbugs.gnu.org; Tue, 23 May 2023 08:40:37 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44374) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q1RJN-000327-5u for 63516@debbugs.gnu.org; Tue, 23 May 2023 08:40:21 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1RJH-0003EH-Ub; Tue, 23 May 2023 08:40:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=/TCf++XSAlYK4R8WSq1KFzsd9FTMjmXsX0cL03mgz0A=; b=HrgXyZMsUlNCs5IZD8d2 kNlrI0GhLZKwBK2DyTefWDplSrZJxsKPqg2aHCRHHkKpPK7WpQ805tgZA8nlDpUxBR4dZHUWnpRf8 2dPyExoZzs8Xw3LihZve8wYrFUWc8e6chGkDI7xmKWWoSVLF19tQgh3gdaDZZhFO3FL5NkopxGAQm uETYpNk6Vb5Iuo9PX01OcvCG6OaOKMAgDAOOUE6uXzdm+BWqinj9h19xw4Tmqn14LczxDYxya1sZU DDRqdQVVBAeC9UAVxkmQh4NDbkeTLdSlAqJL9xQinLoD00y40qJqTPS1QMtr7YFGge+yGPrdGaV9B ORaF7zNhgksPow==; Received: from [193.50.110.247] (helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1RJG-00081G-GW; Tue, 23 May 2023 08:40:14 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Tue, 23 May 2023 14:39:47 +0200 Message-Id: <20230523123951.6225-8-ludo@gnu.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230523123951.6225-1-ludo@gnu.org> References: <871qjawqpt.fsf@gnu.org> <20230523123951.6225-1-ludo@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: bug-guix-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1684845680; a=rsa-sha256; cv=none; b=scrfvkH9o4bDy13FKpEkbEL9Y1G4NG54yIL8oV5Lo0x9Qw179uYAyvA5BuJ5rOE2IdVXK1 GtZUCr2DNDGvVLHjVwKSekC0mi7Wa+R70q7CCQgClUKHmMW66uXfAcQxs5Go6HMxDc2xuz F9fRvieEVo2xYEAAt7v/p/S7ocjFeQGaUHSl+GYw/wceMrfZt2h3+5O/in9y5mpZ2OzpLY NWsPRkfFm4tlMOs1zbkLdldVabYH39OB9RqaYwnn/9oxpMk+qeZqqYOPIdG7pDxquba26S S9xYgLVelsrsOKArLPlO1vp0jaUTS4BnKEgPKcpTN7F1dF9YAjtzGTn5vhdkcA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=HrgXyZMs; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1684845680; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=/TCf++XSAlYK4R8WSq1KFzsd9FTMjmXsX0cL03mgz0A=; b=YhIr22PWzhWdcxE90vn8ElS14qDS6D2fZ/GQvaVkEee5TTt+rUOGptHYEnDFjs5CEtDcIw oRiP+4GOwHSoVK8dRUTm/3XEAeiIOJeEPK6c0OqGGBHQoCI4NyzDdvI+CvkEKv3VjsgJ11 exxz0ZH5mzXN5vktdB13jAIzqqtoi1h4DI58AXu9FQzq8VQMhevTj/PW+u1K/f4lk9zSl2 QvSacD2Q79AiBTA7pb9B79yU88Hw7xRdYwNM8rzU0nqtt5srDR0q0KE320qw67MV20hH2R yFJpFs1Bs26Dhwc3UMDDQfXiIwIqS9mMlDt/MSAvftKH34lSqC+Rme2oO5AGuA== X-Migadu-Spam-Score: -0.31 X-Spam-Score: -0.31 X-Migadu-Queue-Id: 90FF32DB68 X-Migadu-Scanner: scn0.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=HrgXyZMs; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" X-TUID: 9/0SijQX7pNZ * 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 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