[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Communications, Volume 2

inet_ntop Subroutine

Purpose

Converts a binary address into a text string suitable for presentation

Library

Library (libc.a)

Syntax

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

Description

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

The src parameter points to a buffer holding an IPv4 address if the af parameter is AF_INET, or an IPv6 address if the af parameter is AF_INET6. The dst parameter points to a buffer where the function will store the resulting text string. The size parameter specifies the size of this buffer (in bytes). The application must specify a non-NULL dst parameter. For IPv6 addresses, the buffer must be at least INET6_ADDRSTRLEN bytes. For IPv4 addresses, the buffer must be at least INET_ADDRSTRLEN 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 the <netinet/in.h> library:

#define INET_ADDRSTRLEN 16
#define INET6_ADDRSTRLEN 46

Parameters

af Specifies the family of the address. This can be AF_INET or AF_INET6.
src Points to a buffer holding an IPv4 address if the af parameter is set to AF_INET, or an IPv6 address if the af parameter is set to AF_INET6.
dst Points to a buffer where the resulting text string is stored.
size Specifies the size (in bytes) of the buffer pointed to by the dst parameter.

Return Values

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

Related Information

inet_net_ntop Subroutine, inet_net_pton Subroutine, and inet_pton Subroutine.

Subroutines Overview in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]