inet_ntoa IPv4

Convert an IPv4 address in host-order into an IPv4 dotted-decimal notation ASCII string. See function NetASCII_IPv4_to_Str for more information.

Files

net_bsd.h/net_bsd.c

Prototype

char  *inet_ntoa (struct  in_addr addr);

Arguments

in_addr

IPv4 address (in host-order).

Returned Value

Pointer to ASCII string of converted IPv4 address (see Notes / Warnings), if no errors.

Pointer to NULL, 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

Since the returned ASCII string is stored in a single, global ASCII string array, this function is not reentrant or thread-safe. Therefore, the returned string should be copied as soon as possible before other calls to inet_ntoa() are needed.