Standards
Standards / Extensions |
C or C++ |
Dependencies |
RFC 5014 |
both |
|
Format
#define _OPEN_SYS_SOCK_IPV6
#include <netinet/in.h>
int bind2addrsel(int sd, const struct sockaddr *dstaddr, socklen_t dstaddrlen);
General description
The bind2addrsel()
function binds a socket to a source address and port that is appropriate
to communicate with a given destination address. The source address
is selected by the TCP stack according to either the default preference
flags or the flags previously expressed by the application by use
of the setsockopt() IPV6_ADDR_PREFERENCES call on this socket. If
the bind is successful, the application can call getsockname() to
determine the address and port selected. The application can then
call inet6_is_srcaddr() to determine if the bound local address meets
its preferences. For more information on source address selection,
see z/OS Communications Server: IPv6 Network and Application Design Guide.
- Argument
- Description
- sd
- The socket to bind to a stack-selected source address and port.
- dstaddr
- 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 destination
address with which the local node wants to communicate.
- The sin6_scope_id must be set if the
address is link-local.
- dstaddrlen
- The size of the sockaddr structure passed as argument.
Returned value
If successful, bind2addrsel()
returns 0.
If unsuccessful, bind2addrsel() returns -1 and sets
errno to one of the following values:
- Error Code
- Description
- EADDRNOTAVAIL
- The destination address is a multicast address but the socket
type is SOCK_STREAM or there are no ephemeral ports available to satisfy
the bind request.
- EAFNOSUPPORT
- The address family specified in the address structure is not supported.
- EBADF
- The socket descriptor is incorrect.
- EHOSTUNREACH
- The destination address is not reachable because there is no route.
- EINVAL
- One of the input parameters was not valid.
- EIO
- There has been a network or transport failure.
- ENOBUFS
- A buffer could not be obtained.
- ENOTSOCK
- The sd parameter does not refer to a
valid socket descriptor.
- EOPNOTSUPP
- The socket domain type is not supported.
- EPROTOTYPE
- The socket protocol is not TCP or UDP.