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

Technical Reference: Communications, Volume 2

inet_pton Subroutine

Purpose

Converts an address in its standard text form into its numeric binary form

Library

Library (libc.a)

Syntax

int inet_pton (af, src, dst) 
int af;
const char *src;
void *dst;

Description

This function converts an address in its standard text format into its numeric binary form. The af parameter specifies the family of the address.

Note
Only the AF_INET and AF_INET6 address families are supported.

The src parameter points to the string being passed in. The dst parameter points to a buffer where the function stores the numeric address. The address is returned in network byte order.

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.

Return Values

If successful, one is returned. If unsuccessful, zero is returned if the input is not a valid IPv4 dotted-decimal string or a valid IPv6 address string; or a negative one with the errno global variable set to EAFNOSUPPORT if the af parameter is unknown. The calling application must ensure that the buffer referred to by the dst parameter is large enough to hold the numeric address (4 bytes for AF_INET or 16 bytes for AF_INET6).

If the af parameter is AF_INET, the function accepts a string in the standard IPv4 dotted-decimal form.

ddd.ddd.ddd.ddd

Where ddd is a one to three digit decimal number between 0 and 255.

Note
Many implementations of the existing inet_addr and inet_aton functions accept nonstandard input such as octal numbers, hexadecimal numbers, and fewer than four numbers. inet_pton does not accept these formats.

If the af parameter is AF_INET6, then the function accepts a string in one of the standard IPv6 text forms defined in the addressing architecture specification.

Related Information

inet_net_ntop Subroutine, inet_net_pton Subroutine, and inet_ntop 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 ]