NetASCII_IPv4_to_Str

Convert an IPv4 address in host-order into an IPv4 dotted-decimal notation ASCII string.

Files

net_ascii.h/net_ascii.c

Prototype

          void  NetASCII_IPv4_to_Str(NET_IPv4_ADDR   addr_ip,
                                     CPU_CHAR       *p_addr_ip_ascii,
                                     CPU_BOOLEAN     lead_zeros,
                                     NET_ERR        *p_err);

Arguments

addr_ip

IPv4 address (in host-order).

p_addr_ip_ascii

Pointer to a memory buffer of size greater than or equal to NET_ASCII_LEN_MAX_ADDR_IPv4 bytes to receive the IPv4 address string. 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

lead_zeros

Select formatting the IPv4 address string with leading zeros (‘0’) prior to the first non-zero digit in each IPv4 address byte. The number of leading zeros added is such that each byte’s total number of decimal digits is equal to the maximum number of digits for each byte (i.e., 3).

DEF_NO

Do not prepend leading zeros to each IPv4 address byte.

DEF_YES

Prepend leading zeros to each IPv4 address byte.

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_CHAR_LEN

Returned Value

None.

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.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