IP Addresses Functions
Typical IPv4 manipulation usage within a mapping:
// convert and assign IPv4 string into unsigned integer out->ipv4_uint = str_to_ipv4(in->ipv4_string); // or the other way out->ipv4_string = ipv4_to_str(in->ipv4_uint);
Typical IPv6 manipulation usage within a mapping:
// suppose in->ipv6_string = "4567::123" out->ipv6_normalized = ipv6_normalize(in->ipv6_string); // return "4567:0000:0000:0000:0000:0000:0000:0123" // suppose in->ipv6_string = "0000:0000:0000:0004:5678:9098:0000:0654" out->ipv6_compressed = ipv6_compress(in->ipv6_string); // return "::4:5678:9098:0000:654"
Or one can distinguish both IP versions:
if ( is_valid_ipv4(in->ip_string) ) { // act on IPv4 } else if ( is_valid_ipv6(in->ip_string) ) { // act on IPv6 } else { // act when neither is valid }
There are these two rules in all IP manipulation functions described in this section:
- When the first argument is a pointer, the function returns also a pointer.
- When the first argument is ‘nullptr’, the function returns ‘nullptr’ as well.
IPv4 Functions
(since EVL 2.4)
IPv6 Functions
(since EVL 2.4)
- ‘str_to_ipv6()’ ¶
convert string to uint128,
- ‘ipv6_to_str()’ ¶
convert uint128 to ipv6 string,
- ‘is_valid_ipv6()’ ¶
to check whether the string is valid IPv6,
- ‘ipv6_normalize()’ ¶
convert string to normalized IPv6 string,
- ‘ipv6_compress()’ ¶
convert string to compressed IPv6 string,
Examples
To get normalized and compressed IPv6:
// suppose in->ipv6_string = "0000:0000:22::0003:4" out->ipv6_normalized = ipv6_normalize(in->ipv6_string); // "0000:0000:0022:0000:0000:0000:0003:0004" out->ipv6_compressed = ipv6_compress(in->ipv6_string); // "0:0:22::3:4"