poser
A C framework for POsix SERvices
|
An IPv4 or IPv6 address or network. More...
#include <poser/core/ipaddr.h>
Public Member Functions | |
PSC_IpAddr * | PSC_IpAddr_create (const char *str) |
PSC_IpAddr default constructor. | |
PSC_IpAddr * | PSC_IpAddr_clone (const PSC_IpAddr *other) |
PSC_IpAddr copy constructor. | |
PSC_IpAddr * | PSC_IpAddr_tov4 (const PSC_IpAddr *self, const PSC_IpAddr **prefixes) |
Create IPv4 equivalent of a given IPv6 address. | |
PSC_IpAddr * | PSC_IpAddr_tov6 (const PSC_IpAddr *self, const PSC_IpAddr *prefix) |
Create IPv6 equivalent of a given IPv4 address. | |
PSC_Proto | PSC_IpAddr_proto (const PSC_IpAddr *self) |
The protocol of the address. | |
unsigned | PSC_IpAddr_prefixlen (const PSC_IpAddr *self) |
The prefix length of the address. | |
const char * | PSC_IpAddr_string (const PSC_IpAddr *self) |
The canonical string representation of the address. | |
int | PSC_IpAddr_equals (const PSC_IpAddr *self, const PSC_IpAddr *other) |
Compare two addresses for equality. | |
int | PSC_IpAddr_matches (const PSC_IpAddr *self, const PSC_IpAddr *prefix) |
Check whether an address is part of a network. | |
void | PSC_IpAddr_destroy (PSC_IpAddr *self) |
PSC_IpAddr destructor. | |
An IPv4 or IPv6 address or network.
This class holds data for an IP address or network with a prefix length and offers functions to parse a string representation, create a string in the canonical formats, convert between IPv4 and IPv6 and match networks.
PSC_IpAddr * PSC_IpAddr_clone | ( | const PSC_IpAddr * | other | ) |
PSC_IpAddr copy constructor.
Creates a clone of a PSC_IpAddr.
other | the PSC_IpAddr to copy |
PSC_IpAddr * PSC_IpAddr_create | ( | const char * | str | ) |
PSC_IpAddr default constructor.
Creates a new PSC_IpAddr from a given string.
str | the address as a string |
void PSC_IpAddr_destroy | ( | PSC_IpAddr * | self | ) |
PSC_IpAddr destructor.
self | the PSC_IpAddr |
int PSC_IpAddr_equals | ( | const PSC_IpAddr * | self, |
const PSC_IpAddr * | other | ||
) |
Compare two addresses for equality.
self | the PSC_IpAddr |
other | another PSC_IpAddr |
int PSC_IpAddr_matches | ( | const PSC_IpAddr * | self, |
const PSC_IpAddr * | prefix | ||
) |
Check whether an address is part of a network.
self | the PSC_IpAddr |
prefix | a PSC_IpAddr describing a network |
unsigned PSC_IpAddr_prefixlen | ( | const PSC_IpAddr * | self | ) |
The prefix length of the address.
self | the PSC_IpAddr |
PSC_Proto PSC_IpAddr_proto | ( | const PSC_IpAddr * | self | ) |
const char * PSC_IpAddr_string | ( | const PSC_IpAddr * | self | ) |
The canonical string representation of the address.
Returns the canonical string representation of the address. If the prefix length is less than the full length in bits (32 for IPv4, 128 for IPv6), it is appended after a slash ('/').
self | the PSC_IpAddr |
PSC_IpAddr * PSC_IpAddr_tov4 | ( | const PSC_IpAddr * | self, |
const PSC_IpAddr ** | prefixes | ||
) |
Create IPv4 equivalent of a given IPv6 address.
The given address must be an IPv6 address with a prefix length of at least 96, which is then matched against a given list of prefixes. These prefixes must be IPv6 addresses with a prefix length of exactly 96.
If one of them matches, a new IPv4 address is created from only the last 4 bytes and with 96 subtracted from the original prefix length.
This can be used to map back IPv6 addresses obtained from NAT64.
self | the PSC_IpAddr |
prefixes | an array of prefixes, must contain at least one entry and must be terminated with NULL |
PSC_IpAddr * PSC_IpAddr_tov6 | ( | const PSC_IpAddr * | self, |
const PSC_IpAddr * | prefix | ||
) |
Create IPv6 equivalent of a given IPv4 address.
The given address must be an IPv4 address, the prefix must be an IPv6 address with a prefix length of exactly 96. Then, a new Ipv6 address is returned, constructed from the first 12 bytes of the prefix, followed by the original 4 bytes of the IPv4 address, and 96 added to the original prefix length.
This can be used to map IPv4 addresses for NAT64.
self | the PSC_IpAddr |
prefix | the prefix to use for the mapping to IPv6 |