inet_addr IPv4

Convert a string of an IPv4 address in dotted-decimal notation to an IPv4 address in host-order. See function NetASCII_Str_to_IPv4 for more information.

Files

net_bsd.h/net_bsd.c

Prototype

in_addr_t  inet_addr (char  *p_addr);

Arguments

p_addr

Pointer to an ASCII string that contains a dotted-decimal IPv4 address.

Returned Value

Returns the IPv4 address represented by ASCII string in host-order, if no errors.

-1 (i.e., 0xFFFFFFFF), otherwise.

Required Configuration

None.

Notes / Warnings

RFC 1983 states that “dotted decimal notation… refers [to] IPv4 addresses of the form A.B.C.D; where each letter represents, in decimal, one byte of a four byte IPv4 address”. In other words, the dotted-decimal notation separates four decimal byte values by the dot, or period, character (‘.’). Each decimal value represents one byte of the IPv4 address starting with the most significant byte in network order.

IPv4 Address Examples

DOTTED DECIMAL NOTATION

HEXADECIMAL EQUIVALENT

127.0.0.1

0x7F000001

192.168.1.64

0xC0A80140

255.255.255.0

0xFFFFFF00

MSB ….…… LSB

MSB …. LSB

MSB

Most Significant Byte in Dotted-Decimal IPv4 Address

LSB

Least Significant Byte in Dotted-Decimal IPv4 Address

The IPv4 dotted-decimal ASCII string must include only decimal values and the dot, or period, character (‘.’); all other characters are trapped as invalid, including any leading or trailing characters. The ASCII string must include exactly four decimal values separated by exactly three dot characters. Each decimal value must not exceed the maximum byte value (i.e., 255), or exceed the maximum number of digits for each byte (i.e., 3) including any leading zeros.