netfilter
firewalling, NAT, and packet mangling for linux
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Abstract Address
Collaboration diagram for Abstract Address:

Creating Abstract Addresses

struct nl_addrnl_addr_alloc (size_t maxsize)
 Allocate new abstract address object. More...
 
struct nl_addrnl_addr_build (int family, void *buf, size_t size)
 Allocate new abstract address object based on a binary address. More...
 
struct nl_addrnl_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 object based on a character string. More...
 
struct nl_addrnl_addr_clone (struct nl_addr *addr)
 Clone existing abstract address object. More...
 

Destroying Abstract Addresses

void nl_addr_destroy (struct nl_addr *addr)
 Destroy abstract address object. More...
 

Managing Usage References

struct nl_addrnl_addr_get (struct nl_addr *addr)
 
void nl_addr_put (struct nl_addr *addr)
 
int nl_addr_shared (struct nl_addr *addr)
 Check whether an abstract address object is shared. More...
 

Miscellaneous

int nl_addr_cmp (struct nl_addr *a, struct nl_addr *b)
 Compares two abstract address objects. More...
 
int nl_addr_cmp_prefix (struct nl_addr *a, struct nl_addr *b)
 Compares the prefix of two abstract address objects. 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 an address matches a certain family. More...
 
int nl_addr_guess_family (struct nl_addr *addr)
 Guess address family of an abstract address object 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)
 
int nl_addr_get_family (struct nl_addr *addr)
 
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)
 
unsigned int nl_addr_get_prefixlen (struct nl_addr *addr)
 Get 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

1) Transform character string to abstract address
struct nl_addr *a = nl_addr_parse("::1", AF_UNSPEC);
printf("Address family: %s\n", nl_af2str(nl_addr_get_family(a)));
a = nl_addr_parse("11:22:33:44:55:66", AF_UNSPEC);
printf("Address family: %s\n", nl_af2str(nl_addr_get_family(a)));

Function Documentation

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

Convert abstract address object to character string.

  • 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.

References nl_addr::a_addr, nl_addr::a_family, nl_addr::a_len, nl_addr::a_prefixlen, AF_LLC, and buf.

Referenced by nl_addr_info().

Here is the caller graph for this function:

struct nl_addr* nl_addr_alloc ( size_t  maxsize)

Allocate new abstract address object.

  • maxsize Maximum size of the binary address.
    Returns
    Newly allocated address object or NULL

References nl_addr::a_maxsize, nl_addr::a_refcnt, and NULL.

Referenced by nl_addr_build(), nl_addr_parse(), and rtnl_route_parse().

Here is the caller graph for this function:

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

Allocate abstract address based on netlink attribute.

  • nla Netlink attribute of unspecific type.
  • family Address family.

Considers the netlink attribute payload a address of the specified family and allocates a new abstract address based on it.

Returns
Newly allocated address handle or NULL.

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

Referenced by rtnl_route_parse().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Allocate new abstract address object based on a binary address.

  • family Address family.
  • buf Buffer containing the binary address.
  • size Length of binary address buffer.
    Returns
    Newly allocated address handle or NULL

References nl_addr::a_addr, nl_addr::a_family, nl_addr::a_len, nl_addr::a_prefixlen, nl_addr_alloc(), NULL, and size.

Referenced by nl_addr_alloc_attr(), and nl_addr_clone().

Here is the call graph for this function:

Here is the caller graph for this function:

struct nl_addr* nl_addr_clone ( struct nl_addr addr)

Clone existing abstract address object.

  • addr Abstract address object.
    Returns
    Newly allocated abstract address object being a duplicate of the specified address object or NULL if a failure occured.

References nl_addr::a_addr, nl_addr::a_family, nl_addr::a_len, nl_addr::a_prefixlen, and nl_addr_build().

Referenced by rtnl_route_nh_clone().

Here is the call graph for this function:

Here is the caller graph for this function:

int nl_addr_cmp ( struct nl_addr a,
struct nl_addr b 
)

Compares two abstract address objects.

  • a A abstract address object.
  • b Another abstract address object.
Returns
Integer less than, equal to or greather than zero if is found, respectively to be less than, to, or be greater than b.

References nl_addr::a_addr, nl_addr::a_family, and nl_addr::a_len.

Referenced by rtnl_neigh_get(), and rtnl_route_nh_compare().

Here is the caller graph for this function:

int nl_addr_cmp_prefix ( struct nl_addr a,
struct nl_addr b 
)

Compares the prefix of two abstract address objects.

  • a A abstract address object.
  • b Another abstract address object.
Returns
Integer less than, equal to or greather than zero if is found, respectively to be less than, to, or be greater than b.

References nl_addr::a_addr, nl_addr::a_family, nl_addr::a_prefixlen, bytes, mask, and min.

void nl_addr_destroy ( struct nl_addr addr)

Destroy abstract address object.

  • addr Abstract address object.

References nl_addr::a_refcnt, and BUG.

Referenced by nl_addr_parse(), and nl_addr_put().

Here is the caller graph for this function:

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.

  • 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

References nl_addr::a_addr, nl_addr::a_family, and NLE_INVAL.

Referenced by nl_addr_resolve().

Here is the caller graph for this function:

struct nl_addr* nl_addr_get ( struct nl_addr addr)
void* nl_addr_get_binary_addr ( struct nl_addr addr)

Get binary address of abstract address object.

  • addr Abstract address object.

References nl_addr::a_addr.

Referenced by flnl_lookup_build_request(), and nla_put_addr().

Here is the caller graph for this function:

int nl_addr_get_family ( struct nl_addr addr)

References nl_addr::a_family.

Referenced by main().

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.

  • addr Abstract address object.

References nl_addr::a_len.

Referenced by nla_put_addr().

Here is the caller graph for this function:

unsigned int nl_addr_get_prefixlen ( struct nl_addr addr)

Get prefix length of abstract address object.

  • addr Abstract address object.

References nl_addr::a_prefixlen.

Referenced by main(), rtnl_addr_set_local(), rtnl_addr_set_peer(), and rtnl_route_build_msg().

Here is the caller graph for this function:

int nl_addr_guess_family ( struct nl_addr addr)

Guess address family of an abstract address object based on address size.

  • addr Abstract address object.
    Returns
    Address family or AF_UNSPEC if guessing wasn't successful.

References nl_addr::a_len, and AF_LLC.

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

Call getaddrinfo() for an abstract address object.

  • 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.

References nl_addr::a_family, buf, nl_addr2str(), NLE_AF_NOSUPPORT, NLE_AGAIN, NLE_BAD_SOCK, NLE_FAILURE, NLE_INVAL, NLE_NOADDR, NLE_NOMEM, NLE_OBJ_NOTFOUND, NLE_OPNOTSUPP, and NULL.

Here is the call graph for this function:

int nl_addr_iszero ( struct nl_addr addr)

Returns true if the address consists of all zeros.

  • addr Address to look at.

References nl_addr::a_addr, and nl_addr::a_len.

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

Allocate abstract address object based on a character string.

  • addrstr Address represented as character string.
  • hint Address family hint or AF_UNSPEC.
  • result Pointer to store resulting address.

Regognizes the following address formats:

1 Format Len Family
2 ----------------------------------------------------------------
3 IPv6 address format 16 AF_INET6
4 ddd.ddd.ddd.ddd 4 AF_INET
5 HH:HH:HH:HH:HH:HH 6 AF_LLC
6 AA{.|,}NNNN 2 AF_DECnet
7 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.

Returns
0 on success or a negative error code.

References AF_LLC, buf, nl_addr_alloc(), nl_addr_destroy(), nl_addr_set_binary_addr(), nl_addr_set_family(), nl_addr_set_prefixlen(), NLE_AF_NOSUPPORT, NLE_INVAL, NLE_NOADDR, NLE_NOMEM, NULL, and s.

Referenced by main(), and nl_cli_addr_parse().

Here is the call graph for this function:

Here is the caller 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().

  • 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.

References buf, nl_addr_fill_sockaddr(), nl_syserr2nlerr(), and NULL.

Referenced by main().

Here is the call graph for this function:

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.

  • addr Abstract address object.
  • buf Buffer containing binary address.
  • len Length of buffer containing binary address.

References nl_addr::a_addr, nl_addr::a_len, nl_addr::a_maxsize, len, and NLE_RANGE.

Referenced by nl_addr_parse().

Here is the caller graph for this function:

void nl_addr_set_family ( struct nl_addr addr,
int  family 
)

References nl_addr::a_family.

Referenced by nl_addr_parse(), and rtnl_route_parse().

Here is the caller graph for this function:

void nl_addr_set_prefixlen ( struct nl_addr addr,
int  prefixlen 
)

References nl_addr::a_prefixlen.

Referenced by nl_addr_parse(), rtnl_route_parse(), rtnl_rule_set_dst_len(), and rtnl_rule_set_src_len().

Here is the caller graph for this function:

int nl_addr_shared ( struct nl_addr addr)

Check whether an abstract address object is shared.

  • addr Abstract address object.
    Returns
    Non-zero if the abstract address object is shared, otherwise 0.

References nl_addr::a_refcnt.

int nl_addr_valid ( char *  addr,
int  family 
)

Check if an address matches a certain family.

  • addr Address represented as character string.
  • family Desired address family.
Returns
1 if the address is of the desired address family, otherwise 0 is returned.

References AF_LLC, and buf.

char* nl_af2str ( int  family,
char *  buf,
size_t  size 
)

References __type2str(), and ARRAY_SIZE.

Here is the call graph for this function:

int nl_str2af ( const char *  name)

References __str2type(), and ARRAY_SIZE.

Referenced by main(), nl_cli_addr_parse_family(), nl_cli_ct_parse_family(), nl_cli_link_parse_family(), nl_cli_neigh_parse_family(), nl_cli_route_parse_family(), and nl_cli_rule_parse_family().

Here is the call graph for this function:

Here is the caller graph for this function: