libnl  3.2.24-rc1
Network Address

Abstract data type representing any kind of network address. More...

Creating Abstract Network Addresses

struct nl_addr * nl_addr_alloc (size_t maxsize)
 Allocate empty abstract address. More...
 
struct nl_addr * nl_addr_build (int family, void *buf, size_t size)
 Allocate abstract address based on a binary address. More...
 
struct nl_addr * nl_addr_alloc_attr (struct nlattr *nla, int family)
 Allocate abstract address based on Netlink attribute. More...
 
int nl_addr_parse (const char *addrstr, int hint, struct nl_addr **result)
 Allocate abstract address based on character string. More...
 
struct nl_addr * nl_addr_clone (struct nl_addr *addr)
 Clone existing abstract address object. More...
 

Managing Usage References

struct nl_addr * nl_addr_get (struct nl_addr *addr)
 Increase the reference counter of an abstract address. More...
 
void nl_addr_put (struct nl_addr *addr)
 Decrease the reference counter of an abstract address. More...
 
int nl_addr_shared (struct nl_addr *addr)
 Check whether an abstract address is shared. More...
 

Miscellaneous

int nl_addr_cmp (struct nl_addr *a, struct nl_addr *b)
 Compare abstract addresses. More...
 
int nl_addr_cmp_prefix (struct nl_addr *a, struct nl_addr *b)
 Compare the prefix of two abstract addresses. More...
 
int nl_addr_iszero (struct nl_addr *addr)
 Returns true if the address consists of all zeros. More...
 
int nl_addr_valid (char *addr, int family)
 Check if address string is parseable for a specific address family. More...
 
int nl_addr_guess_family (struct nl_addr *addr)
 Guess address family of abstract address based on address size. More...
 
int nl_addr_fill_sockaddr (struct nl_addr *addr, struct sockaddr *sa, socklen_t *salen)
 Fill out sockaddr structure with values from abstract address object. More...
 

Getting Information About Addresses

int nl_addr_info (struct nl_addr *addr, struct addrinfo **result)
 Call getaddrinfo() for an abstract address object. More...
 
int nl_addr_resolve (struct nl_addr *addr, char *host, size_t hostlen)
 Resolve abstract address object to a name using getnameinfo(). More...
 

Attributes

void nl_addr_set_family (struct nl_addr *addr, int family)
 Set address family. More...
 
int nl_addr_get_family (struct nl_addr *addr)
 Return address family. More...
 
int nl_addr_set_binary_addr (struct nl_addr *addr, void *buf, size_t len)
 Set binary address of abstract address object. More...
 
void * nl_addr_get_binary_addr (struct nl_addr *addr)
 Get binary address of abstract address object. More...
 
unsigned int nl_addr_get_len (struct nl_addr *addr)
 Get length of binary address of abstract address object. More...
 
void nl_addr_set_prefixlen (struct nl_addr *addr, int prefixlen)
 Set the prefix length of an abstract address. More...
 
unsigned int nl_addr_get_prefixlen (struct nl_addr *addr)
 Return prefix length of abstract address object. More...
 

Translations to Strings

char * nl_addr2str (struct nl_addr *addr, char *buf, size_t size)
 Convert abstract address object to character string. More...
 

Address Family Transformations

char * nl_af2str (int family, char *buf, size_t size)
 
int nl_str2af (const char *name)
 

Detailed Description

Abstract data type representing any kind of network address.

Related sections in the development guide:

Header

#include <netlink/addr.h>

Function Documentation

struct nl_addr* nl_addr_alloc ( size_t  maxsize)
read

Allocate empty abstract address.

Parameters
maxsizeUpper limit of the binary address to be stored

The new address object will be empty with a prefix length of 0 and will be capable of holding binary addresses up to the specified limit.

See Also
nl_addr_build()
nl_addr_parse()
nl_addr_put()
Returns
Allocated address object or NULL upon failure.

Definition at line 185 of file addr.c.

Referenced by nl_addr_build(), and nl_addr_parse().

+ Here is the caller graph for this function:

struct nl_addr* nl_addr_build ( int  family,
void *  buf,
size_t  size 
)
read

Allocate abstract address based on a binary address.

Parameters
familyAddress family
bufBinary address
sizeLength of binary address

This function will allocate an abstract address capable of holding the binary address specified. The prefix length will be set to the full length of the binary address provided.

See Also
nl_addr_alloc()
nl_addr_alloc_attr()
nl_addr_parse()
nl_addr_put()
Returns
Allocated address object or NULL upon failure.

Definition at line 216 of file addr.c.

References nl_addr_alloc().

Referenced by nl_addr_alloc_attr(), nl_addr_clone(), rtnl_link_vxlan_get_group(), and rtnl_link_vxlan_get_local().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

struct nl_addr* nl_addr_alloc_attr ( struct nlattr *  nla,
int  family 
)
read

Allocate abstract address based on Netlink attribute.

Parameters
nlaNetlink attribute
familyAddress family.

Allocates an abstract address based on the specified Netlink attribute by interpreting the payload of the Netlink attribute as the binary address.

This function is identical to:

nl_addr_build(family, nla_data(nla), nla_len(nla));
See Also
nl_addr_alloc()
nl_addr_build()
nl_addr_parse()
nl_addr_put()
Returns
Allocated address object or NULL upon failure.

Definition at line 255 of file addr.c.

References nl_addr_build(), nla_data(), and nla_len().

+ Here is the call graph for this function:

int nl_addr_parse ( const char *  addrstr,
int  hint,
struct nl_addr **  result 
)

Allocate abstract address based on character string.

Parameters
addrstrAddress represented as character string.
hintAddress family hint or AF_UNSPEC.
resultPointer to store resulting address.

Regognizes the following address formats:

Format Len Family
----------------------------------------------------------------
IPv6 address format 16 AF_INET6
ddd.ddd.ddd.ddd 4 AF_INET
HH:HH:HH:HH:HH:HH 6 AF_LLC
AA{.|,}NNNN 2 AF_DECnet
HH:HH:HH:... variable AF_UNSPEC

Special values:

  • none: All bits and length set to 0.
  • {default|all|any}: All bits set to 0, length based on hint or AF_INET if no hint is given.

The prefix length may be appened at the end prefixed with a slash, e.g. 10.0.0.0/8.

See Also
nl_addr_alloc()
nl_addr_build()
nl_addr_put()
Returns
0 on success or a negative error code.

Definition at line 291 of file addr.c.

References nl_addr_alloc(), nl_addr_set_binary_addr(), nl_addr_set_family(), and nl_addr_set_prefixlen().

+ Here is the call graph for this function:

struct nl_addr* nl_addr_clone ( struct nl_addr *  addr)
read

Clone existing abstract address object.

Parameters
addrAbstract address object

Allocates new abstract address representing an identical clone of an existing address.

See Also
nl_addr_alloc()
nl_addr_put()
Returns
Allocated abstract address or NULL upon failure.

Definition at line 471 of file addr.c.

References nl_addr_build().

+ Here is the call graph for this function:

struct nl_addr* nl_addr_get ( struct nl_addr *  addr)
read

Increase the reference counter of an abstract address.

Parameters
addrAbstract address

Increases the reference counter of the address and thus prevents the release of the memory resources until the reference is given back using the function nl_addr_put().

See Also
nl_addr_put()
Returns
Pointer to the existing abstract address

Definition at line 501 of file addr.c.

void nl_addr_put ( struct nl_addr *  addr)

Decrease the reference counter of an abstract address.

Parameters
addrAbstract addr
Note
The resources of the abstract address will be freed after the last reference to the address has been returned.
See Also
nl_addr_get()

Definition at line 517 of file addr.c.

int nl_addr_shared ( struct nl_addr *  addr)

Check whether an abstract address is shared.

Parameters
addrAbstract address object.
Returns
Non-zero if the abstract address is shared, otherwise 0.

Definition at line 534 of file addr.c.

int nl_addr_cmp ( struct nl_addr *  a,
struct nl_addr *  b 
)

Compare abstract addresses.

Parameters
aAn abstract address
bAnother abstract address

Verifies whether the address family, address length, prefix length, and binary addresses of two abstract addresses matches.

Note
This function will not respect the prefix length in the sense that only the actual prefix will be compared. Please refer to the nl_addr_cmp_prefix() function if you require this functionality.
See Also
nl_addr_cmp_prefix()
Returns
Integer less than, equal to or greather than zero if the two addresses match.

Definition at line 563 of file addr.c.

Referenced by rtnl_addr_get(), and rtnl_neigh_get().

+ Here is the caller graph for this function:

int nl_addr_cmp_prefix ( struct nl_addr *  a,
struct nl_addr *  b 
)

Compare the prefix of two abstract addresses.

Parameters
aAn abstract address
bAnother abstract address

Verifies whether the address family and the binary address covered by the smaller prefix length of the two abstract addresses matches.

See Also
nl_addr_cmp()
Returns
Integer less than, equal to or greather than zero if the two addresses match.

Definition at line 594 of file addr.c.

int nl_addr_iszero ( struct nl_addr *  addr)

Returns true if the address consists of all zeros.

Parameters
addrAbstract address
Returns
1 if the binary address consists of all zeros, 0 otherwise.

Definition at line 620 of file addr.c.

int nl_addr_valid ( char *  addr,
int  family 
)

Check if address string is parseable for a specific address family.

Parameters
addrAddress represented as character string.
familyDesired address family.
Returns
1 if the address is parseable assuming the specified address family, otherwise 0 is returned.

Definition at line 639 of file addr.c.

int nl_addr_guess_family ( struct nl_addr *  addr)

Guess address family of abstract address based on address size.

Parameters
addrAbstract address object.
Returns
Numeric address family or AF_UNSPEC

Definition at line 673 of file addr.c.

int nl_addr_fill_sockaddr ( struct nl_addr *  addr,
struct sockaddr *  sa,
socklen_t *  salen 
)

Fill out sockaddr structure with values from abstract address object.

Parameters
addrAbstract address object.
saDestination sockaddr structure buffer.
salenLength of sockaddr structure buffer.

Fills out the specified sockaddr structure with the data found in the specified abstract address. The salen argument needs to be set to the size of sa but will be modified to the actual size used during before the function exits.

Returns
0 on success or a negative error code

Definition at line 700 of file addr.c.

Referenced by nl_addr_resolve().

+ Here is the caller graph for this function:

int nl_addr_info ( struct nl_addr *  addr,
struct addrinfo **  result 
)

Call getaddrinfo() for an abstract address object.

Parameters
addrAbstract address object.
resultPointer to store resulting address list.

Calls getaddrinfo() for the specified abstract address in AI_NUMERICHOST mode.

Note
The caller is responsible for freeing the linked list using the interface provided by getaddrinfo(3).
Returns
0 on success or a negative error code.

Definition at line 756 of file addr.c.

References nl_addr2str().

+ Here is the call graph for this function:

int nl_addr_resolve ( struct nl_addr *  addr,
char *  host,
size_t  hostlen 
)

Resolve abstract address object to a name using getnameinfo().

Parameters
addrAbstract address object.
hostDestination buffer for host name.
hostlenLength of destination buffer.

Resolves the abstract address to a name and writes the looked up result into the host buffer. getnameinfo() is used to perform the lookup and is put into NI_NAMEREQD mode so the function will fail if the lookup couldn't be performed.

Returns
0 on success or a negative error code.

Definition at line 800 of file addr.c.

References nl_addr_fill_sockaddr().

+ Here is the call graph for this function:

void nl_addr_set_family ( struct nl_addr *  addr,
int  family 
)

Set address family.

Parameters
addrAbstract address object
familyAddress family
See Also
nl_addr_get_family()

Definition at line 832 of file addr.c.

Referenced by nl_addr_parse().

+ Here is the caller graph for this function:

int nl_addr_get_family ( struct nl_addr *  addr)

Return address family.

Parameters
addrAbstract address object
See Also
nl_addr_set_family()
Returns
The numeric address family or AF_UNSPEC

Definition at line 845 of file addr.c.

Referenced by rtnl_link_vxlan_set_group(), and rtnl_link_vxlan_set_local().

+ Here is the caller graph for this function:

int nl_addr_set_binary_addr ( struct nl_addr *  addr,
void *  buf,
size_t  len 
)

Set binary address of abstract address object.

Parameters
addrAbstract address object.
bufBuffer containing binary address.
lenLength of buffer containing binary address.

Modifies the binary address portion of the abstract address. The abstract address must be capable of holding the required amount or this function will fail.

Note
This function will not modify the prefix length. It is within the responsibility of the caller to set the prefix length to the desirable length.
See Also
nl_addr_alloc()
nl_addr_get_binary_addr()
nl_addr_get_len()
Returns
0 on success or a negative error code.

Definition at line 870 of file addr.c.

Referenced by nl_addr_parse().

+ Here is the caller graph for this function:

void* nl_addr_get_binary_addr ( struct nl_addr *  addr)

Get binary address of abstract address object.

Parameters
addrAbstract address object.
See Also
nl_addr_set_binary_addr()
nl_addr_get_len()
Returns
Pointer to binary address of length nl_addr_get_len()

Definition at line 893 of file addr.c.

Referenced by flnl_lookup_build_request(), nla_put_addr(), rtnl_link_vxlan_set_group(), and rtnl_link_vxlan_set_local().

+ Here is the caller graph for this function:

unsigned int nl_addr_get_len ( struct nl_addr *  addr)

Get length of binary address of abstract address object.

Parameters
addrAbstract address object.
See Also
nl_addr_get_binary_addr()
nl_addr_set_binary_addr()

Definition at line 905 of file addr.c.

Referenced by nla_put_addr(), rtnl_link_vxlan_set_group(), and rtnl_link_vxlan_set_local().

+ Here is the caller graph for this function:

void nl_addr_set_prefixlen ( struct nl_addr *  addr,
int  prefixlen 
)

Set the prefix length of an abstract address.

Parameters
addrAbstract address object
prefixlenNew prefix length
See Also
nl_addr_get_prefixlen()

Definition at line 917 of file addr.c.

Referenced by nl_addr_parse(), and rtnl_addr_set_prefixlen().

+ Here is the caller graph for this function:

unsigned int nl_addr_get_prefixlen ( struct nl_addr *  addr)

Return prefix length of abstract address object.

Parameters
addrAbstract address object
See Also
nl_addr_set_prefixlen()

Definition at line 928 of file addr.c.

char* nl_addr2str ( struct nl_addr *  addr,
char *  buf,
size_t  size 
)

Convert abstract address object to character string.

Parameters
addrAbstract address object.
bufDestination buffer.
sizeSize of destination buffer.

Converts an abstract address to a character string and stores the result in the specified destination buffer.

Returns
Address represented in ASCII stored in destination buffer.

Definition at line 951 of file addr.c.

Referenced by nl_addr_info().

+ Here is the caller graph for this function: