libnl 3.5.0

Network Address
Core Library (libnl) » Data Types

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, const void *buf, size_t size)
| Allocate abstract address based on a binary address. More...
struct nl_addr * | nl_addr_alloc_attr (const 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 (const 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 (const struct nl_addr *addr)
| Check whether an abstract address is shared. More...

## Miscellaneous
int | nl_addr_cmp (const struct nl_addr *a, const struct nl_addr *b)
| Compare abstract addresses. More...
int | nl_addr_cmp_prefix (const struct nl_addr *a, const struct nl_addr *b)
| Compare the prefix of two abstract addresses. More...
int | nl_addr_iszero (const struct nl_addr *addr)
| Returns true if the address consists of all zeros. More...
int | nl_addr_valid (const char *addr, int family)
| Check if address string is parseable for a specific address family. More...
int | nl_addr_guess_family (const struct nl_addr *addr)
| Guess address family of abstract address based on address size. More...
int | nl_addr_fill_sockaddr (const 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 (const struct nl_addr *addr, struct addrinfo **result)
| Call getaddrinfo() for an abstract address object. More...
int | nl_addr_resolve (const 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 (const struct nl_addr *addr)
| Return address family. More...
int | nl_addr_set_binary_addr (struct nl_addr *addr, const void *buf, size_t len)
| Set binary address of abstract address object. More...
void * | nl_addr_get_binary_addr (const struct nl_addr *addr)
| Get binary address of abstract address object. More...
unsigned int | nl_addr_get_len (const 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 (const struct nl_addr *addr)
| Return prefix length of abstract address object. More...

## Translations to Strings
char * | nl_addr2str (const 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:

- Network Addresses (Netlink Core Library Development Guide)

## Header

#include <netlink/addr.h>

## Function Documentation

## ◆ nl_addr_alloc()

struct nl_addr* nl_addr_alloc | ( | size_t | maxsize | ) |

Allocate empty abstract address.

Parameters

  maxsize | Upper 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 187 of file addr.c.

Referenced by nl_addr_build().

Here is the caller graph for this function:

## ◆ nl_addr_build()

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

Allocate abstract address based on a binary address.

Parameters

  family | Address family
  buf | Binary address
  size | Length 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 218 of file addr.c.

References nl_addr_alloc().

Referenced by nl_addr_alloc_attr(), nl_addr_clone(), rtnl_link_geneve_get_remote(), 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:

## ◆ nl_addr_alloc_attr()

struct nl_addr* nl_addr_alloc_attr | ( | const struct nlattr * | nla,
|  | int | family
| ) |  |

Allocate abstract address based on Netlink attribute.

Parameters

  nla | Netlink attribute
  family | Address 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 263 of file addr.c.

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

Here is the call graph for this function:

## ◆ nl_addr_parse()

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

Allocate abstract address based on character string.

Parameters

  addrstr | Address represented as character string.
  hint | Address family hint or AF_UNSPEC.
  result | Pointer 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 299 of file addr.c.

## ◆ nl_addr_clone()

struct nl_addr* nl_addr_clone | ( | const struct nl_addr * | addr | ) |

Clone existing abstract address object.

Parameters

  addr | Abstract 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 494 of file addr.c.

References nl_addr_build().

Referenced by rtnl_link_macvlan_add_macaddr(), xfrmnl_sel_clone(), and xfrmnl_user_tmpl_clone().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ nl_addr_get()

struct nl_addr* nl_addr_get | ( | struct nl_addr * | addr | ) |

Increase the reference counter of an abstract address.

Parameters

  addr | Abstract 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 524 of file addr.c.

Referenced by rtnl_link_macvlan_del_macaddr(), and rtnl_link_vf_set_addr().

Here is the caller graph for this function:

## ◆ nl_addr_put()

void nl_addr_put | ( | struct nl_addr * | addr | ) |

Decrease the reference counter of an abstract address.

Parameters

  addr | Abstract 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 540 of file addr.c.

Referenced by rtnl_link_macvlan_del_macaddr(), rtnl_link_macvlan_set_mode(), rtnl_link_vf_free(), and rtnl_link_vf_set_addr().

Here is the caller graph for this function:

## ◆ nl_addr_shared()

int nl_addr_shared | ( | const struct nl_addr * | addr | ) |

Check whether an abstract address is shared.

Parameters

  addr | Abstract address object.

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

Definition at line 557 of file addr.c.

## ◆ nl_addr_cmp()

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

Compare abstract addresses.

Parameters

  a | An abstract address
  b | Another 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 586 of file addr.c.

Referenced by rtnl_link_macvlan_del_macaddr(), rtnl_neigh_get(), and rtnl_neigh_get_by_vlan().

Here is the caller graph for this function:

## ◆ nl_addr_cmp_prefix()

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

Compare the prefix of two abstract addresses.

Parameters

  a | An abstract address
  b | Another 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 625 of file addr.c.

Referenced by xfrmnl_sel_cmp(), and xfrmnl_user_tmpl_cmp().

Here is the caller graph for this function:

## ◆ nl_addr_iszero()

int nl_addr_iszero | ( | const struct nl_addr * | addr | ) |

Returns true if the address consists of all zeros.

Parameters

  addr | Abstract address

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

Definition at line 651 of file addr.c.

## ◆ nl_addr_valid()

int nl_addr_valid | ( | const char * | addr,
|  | int | family
| ) |  |

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

Parameters

  addr | Address represented as character string.
  family | Desired address family.

Returns
  1 if the address is parseable assuming the specified address family, otherwise 0 is returned.

Definition at line 670 of file addr.c.

## ◆ nl_addr_guess_family()

int nl_addr_guess_family | ( | const struct nl_addr * | addr | ) |

Guess address family of abstract address based on address size.

Parameters

  addr | Abstract address object.

Returns
  Numeric address family or AF_UNSPEC

Definition at line 710 of file addr.c.

## ◆ nl_addr_fill_sockaddr()

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

Fill out sockaddr structure with values from abstract address object.

Parameters

  addr | Abstract address object.
  sa | Destination sockaddr structure buffer.
  salen | Length 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 737 of file addr.c.

Referenced by nl_addr_resolve().

Here is the caller graph for this function:

## ◆ nl_addr_info()

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

Call getaddrinfo() for an abstract address object.

Parameters

  addr | Abstract address object.
  result | Pointer 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 805 of file addr.c.

References nl_addr2str().

Here is the call graph for this function:

## ◆ nl_addr_resolve()

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

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

Parameters

  addr | Abstract address object.
  host | Destination buffer for host name.
  hostlen | Length 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 849 of file addr.c.

References nl_addr_fill_sockaddr().

Here is the call graph for this function:

## ◆ nl_addr_set_family()

void nl_addr_set_family | ( | struct nl_addr * | addr,
|  | int | family
| ) |  |

Set address family.

Parameters

  addr | Abstract address object
  family | Address family

See also
  nl_addr_get_family()

Definition at line 881 of file addr.c.

## ◆ nl_addr_get_family()

int nl_addr_get_family | ( | const struct nl_addr * | addr | ) |

Return address family.

Parameters

  addr | Abstract address object

See also
  nl_addr_set_family()

Returns
  The numeric address family or `AF_UNSPEC`

Definition at line 894 of file addr.c.

Referenced by rtnl_link_geneve_set_remote(), rtnl_link_macvlan_add_macaddr(), rtnl_link_macvlan_del_macaddr(), rtnl_link_vxlan_set_group(), and rtnl_link_vxlan_set_local().

Here is the caller graph for this function:

## ◆ nl_addr_set_binary_addr()

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

Set binary address of abstract address object.

Parameters

  addr | Abstract address object.
  buf | Buffer containing binary address.
  len | Length 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 919 of file addr.c.

## ◆ nl_addr_get_binary_addr()

void* nl_addr_get_binary_addr | ( | const struct nl_addr * | addr | ) |

Get binary address of abstract address object.

Parameters

  addr | Abstract 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 942 of file addr.c.

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

Here is the caller graph for this function:

## ◆ nl_addr_get_len()

unsigned int nl_addr_get_len | ( | const struct nl_addr * | addr | ) |

Get length of binary address of abstract address object.

Parameters

  addr | Abstract address object.

See also
  nl_addr_get_binary_addr()
  nl_addr_set_binary_addr()

Definition at line 954 of file addr.c.

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

Here is the caller graph for this function:

## ◆ nl_addr_set_prefixlen()

void nl_addr_set_prefixlen | ( | struct nl_addr * | addr,
|  | int | prefixlen
| ) |  |

Set the prefix length of an abstract address.

Parameters

  addr | Abstract address object
  prefixlen | New prefix length

See also
  nl_addr_get_prefixlen()

Definition at line 966 of file addr.c.

Referenced by rtnl_addr_set_prefixlen().

Here is the caller graph for this function:

## ◆ nl_addr_get_prefixlen()

unsigned int nl_addr_get_prefixlen | ( | const struct nl_addr * | addr | ) |

Return prefix length of abstract address object.

Parameters

  addr | Abstract address object

See also
  nl_addr_set_prefixlen()

Definition at line 977 of file addr.c.

## ◆ nl_addr2str()

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

Convert abstract address object to character string.

Parameters

  addr | Abstract address object.
  buf | Destination buffer.
  size | Size 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 1000 of file addr.c.

Referenced by nl_addr_info().

Here is the caller graph for this function: