[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]
Base Operating System and Extensions Technical Reference, Volume 1

inet_ntop Subroutine

Purpose

Converts between binary and text address formats.

Library

Library (libc.a)

Syntax

char *inet_ntop
int af;
const void *src;
char *dst;
size_t size;

Description

This function converts from an address in binary format (as specified by src) to standard text format, and places the result in dst (if size, which specifies the space available in dst, is sufficient). The argument af specifies the family of the address. This can be AF_INET or AF_INET6.

The argument, src, points to a buffer holding an IPv4 address if the af argument is AF_INET, or an IPv6 address if the af argument is AF_INET6. The argument dst points to a buffer where the function will store the resulting text string. The size argument specifies the size of this buffer. The application must specify a non-NULL dst argument. For IPv6 addresses, the buffer must be at least 46-octets. For IPv4 addresses, the buffer must be at least 16-octets.

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

Return Values

If successful, a pointer to the buffer containing the converted address is returned. If unsuccessful, NULL is returned. Upon failure, errno is set to EAFNOSUPPORT if the specified address family (af) is unsupported, or to ENOSPC if the size indicates the destination buffer is too small.

Related Information

The inet_net_ntop subroutine, inet_net_pton subroutine, and inet_pton subroutine.

Subroutines Overview in AIX Version 4 General Programming Concepts: Writing and Debugging Programs.


[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]