Abstract Address
[Utilities]


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)));
 nl_addr_put(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)));
 nl_addr_put(a);


Address Family Transformations

char * nl_af2str (char family, char *buf, size_t size)
 Convert address family to character string.
char nl_str2af (const char *name)
 Convert character string to address family.

Creating Abstract Addresses

nl_addr * nl_addr_alloc (size_t maxsize)
 Allocate new abstract address object.
nl_addr * nl_addr_build (int family, void *buf, size_t size)
 Allocate new abstract address object based on a binary address.
nl_addr * nl_addr_parse (const char *addrstr, int hint)
 Allocate abstract address object based on a character string.
nl_addr * nl_addr_clone (struct nl_addr *addr)
 Clone existing abstract address object.

Destroying Abstract Addresses

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

Managing Usage References

nl_addr * nl_addr_get (struct nl_addr *addr)
 Request undestroyable reference of abstract address object.
void nl_addr_put (struct nl_addr *addr)
 Give back reference of abstract address object.
int nl_addr_shared (struct nl_addr *addr)
 Check whether an abstract address object is shared.

Miscellaneous

int nl_addr_cmp (struct nl_addr *a, struct nl_addr *b)
 Compares two abstract address objects.
int nl_addr_valid (char *addr, int family)
 Check if an address matches a certain family.
int nl_addr_guess_family (struct nl_addr *addr)
 Guess address family of an abstract address object based on address size.
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.

Getting Information About Addresses

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

Attribute Access

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

Translations to Strings

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


Function Documentation

struct nl_addr* nl_addr_alloc ( size_t  maxsize  ) 

Allocate new abstract address object.

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

Definition at line 164 of file addr.c.

Referenced by nl_addr_build(), and nl_addr_parse().

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

Allocate new abstract address object based on a binary address.

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

Definition at line 187 of file addr.c.

References nl_addr_alloc().

Referenced by nl_addr_clone(), and nla_get_addr().

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

Allocate abstract address object based on a character string.

Parameters:
addrstr Address represented as character string.
hint Address family hint or AF_UNSPEC.
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:

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

Returns:
Newly allocated abstract address object or NULL.

Definition at line 231 of file addr.c.

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

struct nl_addr* nl_addr_clone ( struct nl_addr *  addr  ) 

Clone existing abstract address object.

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

Definition at line 406 of file addr.c.

References nl_addr_build().

void nl_addr_destroy ( struct nl_addr *  addr  ) 

Destroy abstract address object.

Parameters:
addr Abstract address object.

Definition at line 428 of file addr.c.

Referenced by nl_addr_parse(), and nl_addr_put().

struct nl_addr* nl_addr_get ( struct nl_addr *  addr  ) 

Request undestroyable reference of abstract address object.

Parameters:
addr Abstract address object.
Returns:
Abstract address object of which the reference was given.

Definition at line 451 of file addr.c.

Referenced by flnl_request_set_addr(), rtnl_route_nh_set_gateway(), rtnl_route_set_dst(), rtnl_route_set_gateway(), rtnl_route_set_pref_src(), and rtnl_route_set_src().

void nl_addr_put ( struct nl_addr *  addr  ) 

Give back reference of abstract address object.

Parameters:
addr Abstract address object.
Decrements the reference counter and destroys the object if the last reference was given back.

Definition at line 465 of file addr.c.

References nl_addr_destroy().

Referenced by flnl_request_set_addr(), rtnl_route_nh_free(), rtnl_route_nh_set_gateway(), rtnl_route_set_dst(), rtnl_route_set_gateway(), rtnl_route_set_pref_src(), and rtnl_route_set_src().

int nl_addr_shared ( struct nl_addr *  addr  ) 

Check whether an abstract address object is shared.

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

Definition at line 481 of file addr.c.

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

Compares two abstract address objects.

Parameters:
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.

Definition at line 501 of file addr.c.

Referenced by flnl_request_cmp(), and rtnl_neigh_get().

int nl_addr_valid ( char *  addr,
int  family 
)

Check if an address matches a certain family.

Parameters:
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.

Definition at line 523 of file addr.c.

int nl_addr_guess_family ( struct nl_addr *  addr  ) 

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

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

Definition at line 556 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:
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 583 of file addr.c.

Referenced by nl_addr_resolve().

struct addrinfo* nl_addr_info ( struct nl_addr *  addr  ) 

Call getaddrinfo() for an abstract address object.

Parameters:
addr Abstract address object.
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:
A linked list of addrinfo handles or NULL with an error message associated.

Definition at line 639 of file addr.c.

References nl_addr2str().

int nl_addr_resolve ( 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 673 of file addr.c.

References nl_addr_fill_sockaddr().

void nl_addr_set_family ( struct nl_addr *  addr,
int  family 
)

Set address family of abstract address object.

Parameters:
addr Abstract address object.
family New address family.

Definition at line 699 of file addr.c.

Referenced by nl_addr_parse().

int nl_addr_get_family ( struct nl_addr *  addr  ) 

Get address family of abstract address object.

Parameters:
addr Abstract address object.

Definition at line 708 of file addr.c.

int nl_addr_set_binary_addr ( struct nl_addr *  addr,
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.

Definition at line 719 of file addr.c.

Referenced by nl_addr_parse().

void* nl_addr_get_binary_addr ( struct nl_addr *  addr  ) 

Get binary address of abstract address object.

Parameters:
addr Abstract address object.

Definition at line 734 of file addr.c.

Referenced by flnl_lookup_build_request(), and nla_put_addr().

unsigned int nl_addr_get_len ( struct nl_addr *  addr  ) 

Get length of binary address of abstract address object.

Parameters:
addr Abstract address object.

Definition at line 743 of file addr.c.

Referenced by nla_put_addr().

void nl_addr_set_prefixlen ( struct nl_addr *  addr,
int  prefixlen 
)

Set prefix length of abstract address object.

Parameters:
addr Abstract address object.
prefixlen New prefix length.

Definition at line 753 of file addr.c.

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

unsigned int nl_addr_get_prefixlen ( struct nl_addr *  addr  ) 

Get prefix length of abstract address object.

Parameters:
addr Abstract address object.

Definition at line 762 of file addr.c.

Referenced by rtnl_addr_set_local(), and rtnl_addr_set_peer().

char* nl_addr2str ( 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 785 of file addr.c.

Referenced by nl_addr_info().

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

Convert address family to character string.

Parameters:
family Address family.
buf Destination buffer.
size Size of destination buffer.
Converts an address family to a character string and stores it in the provided buffer.

Returns:
The destination buffer or the type encoded in hexidecimal form if no match was found.

Definition at line 880 of file addr.c.

char nl_str2af ( const char *  name  ) 

Convert character string to address family.

Parameters:
name Name of address family.
Converts the provided character string specifying an address family to the corresponding numeric value.

Returns:
Address family as number or AF_UNSPEC.

Definition at line 894 of file addr.c.


Generated on Fri Apr 27 14:14:07 2007 for libnl by  doxygen 1.5.1