}
// Search where the gap could end
- gap_end = address_decrement(loc_network_get_first_address(network));
+ gap_end = *loc_network_get_first_address(network);
+ loc_address_decrement(&gap_end);
// There is a gap
if (loc_address_cmp(gap_start, &gap_end) < 0) {
}
// The gap now starts after this network
- const struct in6_addr* network_end = loc_network_get_last_address(network);
- (*gap_start) = address_increment(network_end);
+ (*gap_start) = *loc_network_get_last_address(network);
+ loc_address_increment(gap_start);
loc_network_unref(network);
}
}
-static inline struct in6_addr address_increment(const struct in6_addr* address) {
- struct in6_addr a = *address;
-
+static inline void loc_address_increment(struct in6_addr* address) {
for (int octet = 15; octet >= 0; octet--) {
- if (a.s6_addr[octet] < 255) {
- a.s6_addr[octet]++;
+ if (address->s6_addr[octet] < 255) {
+ address->s6_addr[octet]++;
break;
} else {
- a.s6_addr[octet] = 0;
+ address->s6_addr[octet] = 0;
}
}
-
- return a;
}
-static inline struct in6_addr address_decrement(const struct in6_addr* address) {
- struct in6_addr a = *address;
-
+static inline void loc_address_decrement(struct in6_addr* address) {
for (int octet = 15; octet >= 0; octet--) {
- if (a.s6_addr[octet] > 0) {
- a.s6_addr[octet]--;
+ if (address->s6_addr[octet] > 0) {
+ address->s6_addr[octet]--;
break;
}
}
-
- return a;
}
static inline int loc_address_family_bit_length(const int family) {
if (r)
return r;
- num = address_increment(&num);
+ loc_address_increment(&num);
// How many bits do we need to represent this address?
int bits2 = loc_address_bit_length(&num) - 1;
// The next network starts right after this one
start = *loc_network_get_last_address(network);
- start = address_increment(&start);
+ loc_address_increment(&start);
}
return 0;
return r;
// The next subnet starts after the first one
- struct in6_addr first_address = address_increment(&(*subnet1)->last_address);
+ struct in6_addr first_address = (*subnet1)->last_address;
+ loc_address_increment(&first_address);
// Create the second half of the network
r = loc_network_new(network->ctx, subnet2, &first_address, prefix);