deduplicate some macros

This commit is contained in:
dmiller 2026-06-10 21:39:37 +00:00
parent 2a16e04500
commit 6e18e8d89f
3 changed files with 12 additions and 24 deletions

View file

@ -78,18 +78,6 @@
#include <algorithm>
#include <typeinfo>
#include <errno.h>
#include <limits.h> // 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;

View file

@ -144,6 +144,7 @@
#endif
#include <stdio.h>
#include <limits.h> /* 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

View file

@ -62,7 +62,6 @@
program after making any big changes. Also, please add tests for any new
features. */
#include <limits.h> /* CHAR_BIT */
#include <errno.h>
#include <assert.h>
@ -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);