From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 5ED945A0282 for ; Wed, 28 Feb 2024 12:25:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1709119522; bh=cPTpcjGIOCiRjdd0+cJ1sJJCJraJ5IcB9jzrJG1s838=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S3X0/H/I5xjNtX015a10LVev2q2dhnzObjZDXHig9LBZYqMOaLcp1DpXUSPGBVpt7 WmeM+RrkHf3eBLlf9tfx7ds6jcqlRqhcmykOmd6BRdj7DOki7zguGVwYOrz/qu5DFQ 49JmGIER0NGXmjSdrzpdT0K663MXr8jZdx2tNwmrMRMEpSRu5rQ5ytQxOadaUQ8zdp 97XC3Bvmiepeb73BG6kcQLIt919La30/f14mMngKMzHTyO6kANsSv/ChF2gvzwPp0q mRLe9/ir1srsOqBR1u64SeIOpDvZS4amzrFNcEENWqON1t/eMmfctVFsCEee+NeGCQ OhHZnakKXSsYQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4TlBq64yjBz4wxt; Wed, 28 Feb 2024 22:25:22 +1100 (AEDT) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v3 05/20] util: Allow IN4_IS_* macros to operate on untyped addresses Date: Wed, 28 Feb 2024 22:25:05 +1100 Message-ID: <20240228112520.2078220-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228112520.2078220-1-david@gibson.dropbear.id.au> References: <20240228112520.2078220-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 3NEQXYTB5SZOX5HTQWYTXM5IED74GYY3 X-Message-ID-Hash: 3NEQXYTB5SZOX5HTQWYTXM5IED74GYY3 X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The IN4_IS_*() macros expect a pointer to a struct in_addr. That makes sense, but sometimes we have an IPv4 address as a void * pointer or union type which makes these less convenient. Additionally, this doesn't match the behaviour of the standard library's IN6_IS_*() macros on which they're modelled, nor our own IN4_ARE_ADDR_EQUAL(). Signed-off-by: David Gibson --- util.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util.h b/util.h index de6816af..55513490 100644 --- a/util.h +++ b/util.h @@ -111,13 +111,13 @@ #endif #define IN4_IS_ADDR_UNSPECIFIED(a) \ - ((a)->s_addr == htonl_constant(INADDR_ANY)) + (((struct in_addr *)(a))->s_addr == htonl_constant(INADDR_ANY)) #define IN4_IS_ADDR_BROADCAST(a) \ - ((a)->s_addr == htonl_constant(INADDR_BROADCAST)) + (((struct in_addr *)(a))->s_addr == htonl_constant(INADDR_BROADCAST)) #define IN4_IS_ADDR_LOOPBACK(a) \ - (ntohl((a)->s_addr) >> IN_CLASSA_NSHIFT == IN_LOOPBACKNET) + (ntohl(((struct in_addr *)(a))->s_addr) >> IN_CLASSA_NSHIFT == IN_LOOPBACKNET) #define IN4_IS_ADDR_MULTICAST(a) \ - (IN_MULTICAST(ntohl((a)->s_addr))) + (IN_MULTICAST(ntohl(((struct in_addr *)(a))->s_addr))) #define IN4_ARE_ADDR_EQUAL(a, b) \ (((struct in_addr *)(a))->s_addr == ((struct in_addr *)b)->s_addr) #define IN4ADDR_LOOPBACK_INIT \ -- 2.43.2