inet6_is_srcaddr()--Validate the Given Address Based on Address Selection Preferences
BSD 4.3 Syntax
#include <netinet/in.h>
int16_t inet6_is_srcaddr(struct sockaddr_in6 *source_address,
uint32_t flags)
#define _XOPEN_SOURCE 520
#include <netinet/in.h>
int16_t inet6_is_srcaddr(struct sockaddr_in6 *source_address,
uint32_t flags)
The inet6_is_srcaddr() function is used to determine if the specified address satisfies the address selection preference flags.
There are two versions of the API, as shown above. The base IBM i® API uses BSD 4.3 structures and syntax. The other uses syntax and structures compatible with the UNIX® 98 programming interface specifications. You can select the UNIX 98 compatible interface with the _XOPEN_SOURCE macro.
The valid source address selection preference flags are defined in <in.h>:
#define IPV6_PREFER_SRC_HOME 0x00000001 /* Prefer Home addr */
#define IPV6_PREFER_SRC_COA 0x00000002 /* Prefer Care-of addr */
#define IPV6_PREFER_SRC_TMP 0x00000004 /* Prefer Temp addr */
#define IPV6_PREFER_SRC_PUBLIC 0x00000008 /* Prefer Public addr */
#define IPV6_PREFER_SRC_CGA 0x00000010 /* Prefer CGA addr */
#define IPV6_PREFER_SRC_NONCGA 0x00000020 /* Prefer non-CGA addr */
inet6_is_srcaddr() returns an integer. Possible values are:
When a inet6_is_srcaddr() fails, errno can be set to one of the following:
| [EADDRNOTAVAIL] | Address not available. The IP address specified in the sockaddr_in6 structure (pointed to by source_address) is not one defined by the local interfaces. |
| [EFAULT] | Bad address.
The system detected an address which was not valid while attempting to access the source_address parameter. |
| [EINVAL] | Parameter not valid. This error code indicates
one of the following:
|
| Message ID | Error Message Text |
|---|---|
| CPE3418 E | Possible APAR condition or hardware failure. |
| CPF9872 E | Program or service program &1 in library &2 ended. Reason code &3. |
| CPFA081 E | Unable to set return value or error code. |
The BSD 4.3 structure is:
typedef unsigned short sa_family_t;
typedef unsigned short in_port_t;
struct sockaddr_in6 {
sa_family_t sin6_family;
in_port_t sin6_port;
uint32_t sin6_flowinfo;
struct in6_addr sin6_addr;
uint32_t sin6_scope_id;
};
The BSD 4.4/UNIX 98 compatible structure is:
typedef uchar sa_family_t;
typedef unsigned short in_port_t;
struct sockaddr_in6 {
uint8_t sin6_len;
sa_family_t sin6_family;
in_port_t sin6_port;
uint32_t sin6_flowinfo;
struct in6_addr sin6_addr;
uint32_t sin6_scope_id;
};
The BSD 4.4 sin6_len field is the length of the address. The sin6_family is the address family (AF_INET6 in this case), sin6_port is the port number, and sin6_addr is the internet address. The sin6_flowinfo field contains two pieces of information: the traffic class and the flow label. Note: This field is currently not supported and should be set to zero for upward compatibility. The sin6_scope_id field identifies a set of interfaces as appropriate for the scope of the address carried in the sin6_addr field. Note: This field must be set if the address is link-local.