poser
A C framework for POsix SERvices
Loading...
Searching...
No Matches
PSC_IpAddr Class Reference

An IPv4 or IPv6 address or network. More...

#include <poser/core/ipaddr.h>

Public Member Functions

PSC_IpAddrPSC_IpAddr_create (const char *str)
 PSC_IpAddr default constructor.
 
PSC_IpAddrPSC_IpAddr_clone (const PSC_IpAddr *other)
 PSC_IpAddr copy constructor.
 
PSC_IpAddrPSC_IpAddr_tov4 (const PSC_IpAddr *self, const PSC_IpAddr **prefixes)
 Create IPv4 equivalent of a given IPv6 address.
 
PSC_IpAddrPSC_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.
 

Detailed Description

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.

Member Function Documentation

◆ PSC_IpAddr_clone()

PSC_IpAddr * PSC_IpAddr_clone ( const PSC_IpAddr other)

PSC_IpAddr copy constructor.

Creates a clone of a PSC_IpAddr.

Parameters
otherthe PSC_IpAddr to copy
Returns
a newly created PSC_IpAddr

◆ PSC_IpAddr_create()

PSC_IpAddr * PSC_IpAddr_create ( const char *  str)

PSC_IpAddr default constructor.

Creates a new PSC_IpAddr from a given string.

Parameters
strthe address as a string
Returns
a newly created PSC_IpAddr, or NULL if the string did not contain a valid address.

◆ PSC_IpAddr_destroy()

void PSC_IpAddr_destroy ( PSC_IpAddr self)

PSC_IpAddr destructor.

Parameters
selfthe PSC_IpAddr

◆ PSC_IpAddr_equals()

int PSC_IpAddr_equals ( const PSC_IpAddr self,
const PSC_IpAddr other 
)

Compare two addresses for equality.

Parameters
selfthe PSC_IpAddr
otheranother PSC_IpAddr
Returns
1 if both addresses are equal (protocol, prefix length and data), 0 otherwise.

◆ PSC_IpAddr_matches()

int PSC_IpAddr_matches ( const PSC_IpAddr self,
const PSC_IpAddr prefix 
)

Check whether an address is part of a network.

Parameters
selfthe PSC_IpAddr
prefixa PSC_IpAddr describing a network
Returns
1 if the address is part of the given network (the prefix length is at most the same and for the network's prefix length, the bits of the address are the same), 0 otherwise

◆ PSC_IpAddr_prefixlen()

unsigned PSC_IpAddr_prefixlen ( const PSC_IpAddr self)

The prefix length of the address.

Parameters
selfthe PSC_IpAddr
Returns
the prefix length of the address

◆ PSC_IpAddr_proto()

PSC_Proto PSC_IpAddr_proto ( const PSC_IpAddr self)

The protocol of the address.

Parameters
selfthe PSC_IpAddr
Returns
the protocol of the address

◆ PSC_IpAddr_string()

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 ('/').

Parameters
selfthe PSC_IpAddr
Returns
the string representation of the address

◆ PSC_IpAddr_tov4()

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.

Parameters
selfthe PSC_IpAddr
prefixesan array of prefixes, must contain at least one entry and must be terminated with NULL
Returns
a newly created PSC_IpAddr holding the Ipv4 equivalent, or NULL

◆ PSC_IpAddr_tov6()

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.

Parameters
selfthe PSC_IpAddr
prefixthe prefix to use for the mapping to IPv6
Returns
a newly created PSC_IpAddr holding the IPv6 equivalent, or NULL

The documentation for this class was generated from the following file: