inet_ntop()--Convert IPv4 and IPv6 Addresses Between Binary and Text Form


  Syntax
  #include  <sys/socket.h>
  #include  <arpa/inet.h>

  const char *inet_ntop(int af, const void *src,
                        char *dst, socklen_t size);

  Service Program Name: QSOSRV2

  Default Public Authority: *USE

  Threadsafe: Yes

The inet_ntop() function converts a numeric address into a text string suitable for presentation.


Parameters

af
(Input) Specifies the family of the address to be converted. Currently the AF_INET and AF_INET6 address families are supported.

src
(Input) The pointer to a buffer that contains the numeric form of an IPv4 address if the af parameter is AF_INET, or the numeric form of an IPv6 address if the af parameter is AF_INET6.

dst
(Output) The pointer to a a buffer into which the function stores the resulting null-terminated text string.

size
(Input) The size of the buffer pointed at by dst. The calling application must ensure that the buffer referred to by dst is large enough to hold the resulting text string. For IPv4 addresses, the buffer must be at least 16 bytes. For IPv6 addresses, the buffer must be at least 46 bytes. In order to allow applications to easily declare buffers of the proper size to store IPv4 and IPv6 addresses in string form, the following two constants are defined in <netinet/in.h>:
   #define INET_ADDRSTRLEN    16
   #define INET6_ADDRSTRLEN   46


Authorities

No authorization is required.


Return Value

inet_ntop() returns a pointer. Possible values are:

If successful, inet_ntop() returns a pointer to the buffer containing the text string.


Error Conditions

When inet_ntop() fails, errno will be set to one of the following:

[EAFNOSUPPORT]

The address family is not supported.

[ENOSPC]

The size of the result buffer is inadequate.

[EINVAL]

Parameter is not valid.

[EFAULT]

The system detected an address which was not valid while attempting to access the src or dst parameter.


Usage Notes

  1. The resulting string will be in the standard IPv4 dotted-decimal format for IPv4 or one of the preferred forms for IPv6. See the Usage Notes for inet_pton() for a more detailed description.

  2. A job has a coded character set identifier (CCSID). The job CCSID will be used to convert the characters stored at dst (to allow the hexadecimal values to be shown in lower case).

Related Information



API introduced: V5R2
Top | UNIX-Type APIs | APIs by category