NetASCII_Str_to_IP

Convert a string of an IPv4 or IPv6 address in their respective decimal notation to an IPv4 or IPv6 address.

Files

net_ascii.h/net_ascii.c

Prototype

          NET_IP_ADDR_FAMILY NetASCII_Str_to_IP(CPU_CHAR    *p_addr_ip_ascii,
												void        *p_addr,
												CPU_INT08U   addr_max_len,
                                                NET_ERR     *p_err);

Arguments

p_addr_ip_ascii

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

IPv4 Example: “10.10.1.65”

IPv6 Example: "fe80::1111:1111" 

p_addr

Pointer to IP address variable that will received the conversion result.

addr_max_len

Size of the address variable that will received the result:

NET_IPv4_ADDR_SIZE
NET_IPv6_ADDR_SIZE

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
NET_ASCII_ERR_IP_FAMILY_NOT_PRESENT 

Returned Value

Returns the IP family of the converted address, if no errors.

NET_IP_ADDR_FAMILY_IPv4
NET_IP_ADDR_FAMILY_IPv6

NET_IP_ADDR_FAMILY_UNKNOWN, otherwise.

Required Configuration

None.

Notes / Warnings

IPv4 Address Examples

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.

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.

IPv6 Address Examples

An IPv6 address is represented as a row of 8 consecutive groups separated by colon. Each group is represented with four hexadecimal digits and thus expressed 16 bits.

Here is an example of an IPv6 address : fe80:0db8:85a3:0000:0000:8a2e:0370:7334

Leading zeros can be omitted in the IPv6 address representation. Therefore, the example above will become : fe80:db8:85a3:0:0:8a2e:370:7334.

Finally, a compact representation also exists for IPv6 addresses where consecutive groups of zeros can be replace by a two colons (::). The example IPv6 address will become fe80:db8:85a3::8a2e:370:7334.

The function NetASCII_Str_to_IP() only accepts IPv6 colon-hexadecimal ASCII string that includes only hexadecimal values and the colon character (':').