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)
Service Program Name: QSOSRV1IP6
Default Public Authority: *USE
Threadsafe: Yes
UNIX 98 Compatible Syntax
#define _XOPEN_SOURCE 520 #include <netinet/in.h> int16_t inet6_is_srcaddr(struct sockaddr_in6 *source_address, uint32_t flags)
Service Program Name: QSOSRV1IP6
Default Public Authority: *USE
Threadsafe: Yes
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.
Parameters
- source_address
- (Input) A pointer to a buffer of type struct sockaddr_in6 that contains the source address to determine if it satisfies the address selection preference flags. The structure sockaddr_in6 is defined in <netinet/in.h>.
- flags
- (Input) The source address selection preference flags to be satisfied.
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 */
Authorities
- No authorization is required.
Return Value
inet6_is_srcaddr() returns an integer. Possible values are:
- -1 (Indicates an invalid or non-local address, or invalid preference flags)
- 0 (Indicates a valid local address that does not satisfy the specified preference flags)
- 1 (Indicates a valid local address that satisfies the specified preference flags)
Error Conditions
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:
|
Error Messages
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. |
Usage Notes
- This API is only valid for an address family of AF_INET6.
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.
- When you develop in C-based languages and an application is compiled with the _XOPEN_SOURCE macro defined to the value 520 or greater, the inet6_is_srcaddr() API is mapped to qso_inet6_is_srcaddr98().
Related Information
- _XOPEN_SOURCE--Using _XOPEN_SOURCE for the UNIX 98
compatible interface
- bind2addrsel()--Set Local Address for Socket with Address Selection Preferences
API introduced: IBM® i 7.1