inet_aton IPv4

Convert an IPv4 address in ASCII dotted-decimal notation to a network protocol IPv4 address in network-order. See function NetASCII_Str_to_IPv4 for more information.

Files

net_bsd.h/net_bsd.c

Prototype

int  inet_aton (        char     *p_addr_in,
                struct  in_addr  *p_addr);

Arguments

p_addr_in

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

p_addr

Pointer to an IPv4 address that will receive the converted address.

Returned Value

1, if no errors.

0, 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

Values specified using IPv4 dotted decimal notation take one of the following forms:

a.b.c.d

When a four parts address is specified, each shall be interpreted as a byte of data and assigned, from left to right, to the four bytes of an internet address.

a.b.c

When three parts address is specified, the last part shall be interpreted as a 16-bit quantity and placed in the rightmost two bytes of the network address. This makes the three part address format convenient for specifying Class B network addresses as “128.net.host”.

a.b

When two parts address is specified, the last part shall be interpreted as a 24-bit quantity and placed in the rightmost three bytes of the network address. This makes the two part address format convenient for specifying Class A network addresses as “net.host”.

a

When one part address is specified, the value shall be stored directly in the network address without any byte rearrangement.

The 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.
  • Included up to four decimal values, separated by UP to three dot characters.
  • Ensure that each decimal value does not exceed the maximum value for its form:
  • a.b.c.d - 255.255.255.255
  • a.b.c - 255.255.255.65535
  • a.b - 255.16777215
  • a - 4294967295
  • Ensure that each decimal value does not exceed leading zeros.