NetASCII_Str_to_IPv4

Convert a string of an IPv4 address in dotted-decimal notation to an IPv4 address in host-order.

Files

net_ascii.h/net_ascii.c

Prototype

          NET_IPv4_ADDR NetASCII_Str_to_IPv4(CPU_CHAR  *p_addr_ip_ascii,
                                             NET_ERR   *p_err);

Arguments

p_addr_ip_ascii

Pointer to an ASCII string that contains a dotted-decimal IPv4 address. Each decimal byte of the IPv4 address string must be separated by a dot, or period, character (‘.’). Note that the first ASCII character in the string is the most significant nibble of the IP address’s most significant byte and that the last character in the string is the least significant nibble of the IP address’s least significant byte.

Example: “10.10.1.65” = 0x0A0A0141

p_err

Pointer to variable that will receive the return error code from this function:

NET_ASCII_ERR_NONE
NET_ERR_FAULT_NULL_PTR
NET_ASCII_ERR_INVALID_STR_LEN
NET_ASCII_ERR_INVALID_CHAR
NET_ASCII_ERR_INVALID_CHAR_LEN
NET_ASCII_ERR_INVALID_CHAR_VAL
NET_ASCII_ERR_INVALID_CHAR_SEQ

Returned Value

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

NET_IPv4_ADDR_NONE, otherwise.

Required Configuration

Available only if IPv4 is enabled, see IPv4 Layer Configuration

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.10x7F000001
192.168.1.640xC0A80140
255.255.255.00xFFFFFF00

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.