From 6e18e8d89ff5a05a890d6f960f4e5361ab31a586 Mon Sep 17 00:00:00 2001 From: dmiller Date: Wed, 10 Jun 2026 21:39:37 +0000 Subject: [PATCH] deduplicate some macros --- TargetGroup.cc | 12 ------------ nbase/nbase.h | 12 ++++++++++++ nbase/nbase_addrset.c | 12 ------------ 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/TargetGroup.cc b/TargetGroup.cc index 926c13244..d556e6aa5 100644 --- a/TargetGroup.cc +++ b/TargetGroup.cc @@ -78,18 +78,6 @@ #include #include #include -#include // CHAR_BIT - -/* We use bit vectors to represent what values are allowed in an IPv4 octet. - Each vector is built up of an array of bitvector_t (any convenient integer - type). */ -typedef unsigned long bitvector_t; -/* A 256-element bit vector, representing legal values for one octet. */ -typedef bitvector_t octet_bitvector[(256 - 1) / (sizeof(unsigned long) * CHAR_BIT) + 1]; - -#define BITVECTOR_BITS (sizeof(bitvector_t) * CHAR_BIT) -#define BIT_SET(v, n) ((v)[(n) / BITVECTOR_BITS] |= 1UL << ((n) % BITVECTOR_BITS)) -#define BIT_IS_SET(v, n) (((v)[(n) / BITVECTOR_BITS] & 1UL << ((n) % BITVECTOR_BITS)) != 0) extern NmapOps o; diff --git a/nbase/nbase.h b/nbase/nbase.h index f9691aa0d..998da1303 100644 --- a/nbase/nbase.h +++ b/nbase/nbase.h @@ -144,6 +144,7 @@ #endif #include +#include /* CHAR_BIT */ #ifndef MAXHOSTNAMELEN #define MAXHOSTNAMELEN 64 @@ -508,6 +509,17 @@ extern int addrset_add_spec(struct addrset *set, const char *spec, int af, int d extern int addrset_add_file(struct addrset *set, FILE *fd, int af, int dns); extern int addrset_contains(const struct addrset *set, const struct sockaddr *sa); +/* We use bit vectors to represent what values are allowed in an IPv4 octet. + Each vector is built up of an array of bitvector_t (any convenient integer + type). */ +typedef unsigned long bitvector_t; +/* A 256-element bit vector, representing legal values for one octet. */ +typedef bitvector_t octet_bitvector[(256 - 1) / (sizeof(unsigned long) * CHAR_BIT) + 1]; + +#define BITVECTOR_BITS (sizeof(bitvector_t) * CHAR_BIT) +#define BIT_SET(v, n) ((v)[(n) / BITVECTOR_BITS] |= 1UL << ((n) % BITVECTOR_BITS)) +#define BIT_IS_SET(v, n) (((v)[(n) / BITVECTOR_BITS] & 1UL << ((n) % BITVECTOR_BITS)) != 0) + #ifndef STDIN_FILENO #define STDIN_FILENO 0 #endif diff --git a/nbase/nbase_addrset.c b/nbase/nbase_addrset.c index d1fecf94a..7fe80db7b 100644 --- a/nbase/nbase_addrset.c +++ b/nbase/nbase_addrset.c @@ -62,7 +62,6 @@ program after making any big changes. Also, please add tests for any new features. */ -#include /* CHAR_BIT */ #include #include @@ -104,13 +103,6 @@ struct trie_node { struct trie_node *next_bit_zero; }; -/* We use bit vectors to represent what values are allowed in an IPv4 octet. - Each vector is built up of an array of bitvector_t (any convenient integer - type). */ -typedef unsigned long bitvector_t; -/* A 256-element bit vector, representing legal values for one octet. */ -typedef bitvector_t octet_bitvector[(256 - 1) / (sizeof(unsigned long) * CHAR_BIT) + 1]; - /* A chain of tests for set inclusion. If one test is passed, the address is in the set. */ struct addrset_elem { @@ -586,10 +578,6 @@ static void in_addr_to_octets(const struct in_addr *ia, uint8_t octets[4]) octets[3] = (uint8_t) (hbo & 0xFFU); } -#define BITVECTOR_BITS (sizeof(bitvector_t) * CHAR_BIT) -#define BIT_SET(v, n) ((v)[(n) / BITVECTOR_BITS] |= 1UL << ((n) % BITVECTOR_BITS)) -#define BIT_IS_SET(v, n) (((v)[(n) / BITVECTOR_BITS] & 1UL << ((n) % BITVECTOR_BITS)) != 0) - static int parse_ipv4_ranges(struct addrset_elem *elem, const char *spec); static void apply_ipv4_netmask_bits(struct addrset_elem *elem, int bits);