inet6_is_srcaddr() - Socket address verification

Standards

Standards / Extensions C or C++ Dependencies
RFC 5014 both  

Format

#define _OPEN_SYS_SOCK_IPV6
#include <netinet/in.h>

short inet6_is_srcaddr(struct sockaddr_in6 *srcaddr, uint32_t flags);        

General description

The inet6_is_srcaddr() function validates source address selection preference flags against the given socket address.

Argument
Description
srcaddr
A non-NULL pointer to a sockaddr_in6 structure initialized as follows:
  • Clear the entire structure for sizeof(struct sockaddr_in6).
  • sin6_family must be set to AF_INET6.
  • Set sin6_len to the correct length for AF_INET6.
  • Set sin6_addr to a 128-bit IPv6 source address to validate against the flags.
  • The sin6_scope_id must be set if the address is link-local.
flags
The source preference flags which can be set to any of the following:
  • IPV6_PREFER_SRC_HOME - prefer home address as source
  • IPV6_PREFER_SRC_COA - prefer care-of address as source
  • IPV6_PREFER_SRC_TMP - prefer temporary address as source
  • IPV6_PREFER_SRC_PUBLIC - prefer public address as source
  • IPV6_PREFER_SRC_CGA - prefer CGA address as source
  • IPV6_PREFER_SRC_NONCGA - prefer a non-CGA address as source

These flags can be combined into a flag set to express complex address preferences, but some can result in a contradictory flag set.

For example, the following flags are mutually exclusive:

  • IPV6_PREFER_SRC_HOME and IPV6_PREFER_SRC_COA
  • IPV6_PREFER_SRC_TMP and IPV6_PREFER_SRC_PUBLIC
  • IPV6_PREFER_SRC_CGA and IPV6_PREFER_SRC_NONCGA

Returned value

When the IPv6 address corresponds to a valid address in the node and satisfies the given preference flags, inet6_is_srcaddr() returns 1.

If the input address matches an address in the node, but does not satisfy the preference flags indicated, the function returns 0.

If unsuccessful, inet6_is_srcaddr() returns -1 and sets errno to the following:

Error Code
Description
EADDRNOTAVAIL
The address provided does not match a home address in the node.
EAFNOSUPPORT
The address provided does not have a family of AF_INET6.
EAGAIN
A TCP/IP stack is not active to process the request.
EINVAL
Undefined flags were used, or a link-local IPv6 address was used with a zero scopeid, or a global address was used with a non-zero scopeid.

Related information