4 /* This file should eventually incorporate all the functionality of
7 bool_t
subnet_match(struct subnet
*s
, uint32_t address
)
9 return (s
->prefix
==(address
&s
->mask
));
12 bool_t
subnet_matches_list(struct subnet_list
*list
, uint32_t address
)
15 for (i
=0; i
<list
->entries
; i
++) {
16 if (list
->list
[i
].prefix
== (address
&list
->list
[i
].mask
)) return True
;
21 bool_t
subnets_intersect(struct subnet a
, struct subnet b
)
23 uint32_t mask
=a
.mask
&b
.mask
;
24 return ((a
.prefix
&mask
)==(b
.prefix
&mask
));
27 bool_t
subnet_intersects_with_list(struct subnet a
, struct subnet_list
*b
)
31 for (i
=0; i
<b
->entries
; i
++) {
32 if (subnets_intersect(a
,b
->list
[i
])) return True
;
37 bool_t
subnet_lists_intersect(struct subnet_list
*a
, struct subnet_list
*b
)
40 for (i
=0; i
<a
->entries
; i
++) {
41 if (subnet_intersects_with_list(a
->list
[i
],b
)) return True
;
46 /* The string buffer must be at least 16 bytes long */
47 string_t
ipaddr_to_string(uint32_t addr
)
52 s
=safe_malloc(16,"ipaddr_to_string");
57 snprintf(s
, 16, "%d.%d.%d.%d", a
, b
, c
, d
);
61 string_t
subnet_to_string(struct subnet
*sn
)
63 uint32_t mask
=sn
->mask
, addr
=sn
->prefix
;
68 s
=safe_malloc(19,"subnet_to_string");
73 for (i
=0; mask
; i
++) {
77 fatal("subnet_to_string: invalid subnet structure "
78 "(i=%d sn->len=%d mask=0x%08x)!\n",i
,sn
->len
,sn
->mask
);
80 snprintf(s
, 19, "%d.%d.%d.%d/%d", a
, b
, c
, d
, sn
->len
);