Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagecpp
themeConfluence
firstline1
titleIPv4 Address Configuration Example
linenumberstrue
CPU_BOOLEAN    cfg_success;
NET_IPv4_ADDR  ipv4_addr;
NET_IPv4_ADDR  ipv4_msk;
NET_IPv4_ADDR  ipv4_gateway;
NET_ERR        err;


(void)NetASCII_Str_to_IP((CPU_CHAR*)"192.168.1.2",   &ipv4_addr,    NET_IPv4_ADDR_SIZE, &err);	/* See Note #1 */
(void)NetASCII_Str_to_IP((CPU_CHAR*)"255.255.255.0", &ipv4_msk,     NET_IPv4_ADDR_SIZE, &err);
(void)NetASCII_Str_to_IP((CPU_CHAR*)"192.168.1.1",   &ipv4_gateway, NET_IPv4_ADDR_SIZE, &err);

cfg_success = NetIPv4_CfgAddrAdd(if_nbr,         												/* See Note #2 */
                                 ipv4_addr,      												/* See Note #3 */
                                 ipv4_msk,       												/* See Note #4 */
                                 ipv4_gateway,   												/* See Note #5 */
                                &err);          					 							/* See Note #6 */


Panel
bgColor#f0f0f0
  1. NetASCII_Str_to_IP() requires four arguments. The first function argument is a string representing a valid IP address. The second argument is a pointer to the IP address object that will received the conversion result. The third argument is the size of the address object and the last argument is a pointer to a NET_ERR to contain the return error code. Upon successful conversion, the return error will contain the value NET_ASCII_ERR_NONE and the function will return a variable of type NET_IP_ADDR_FAMILY containing the family type (IPv4 or IPv6) of the address converted.
  2. The first argument is the number representing the network interface that is to be configured. This value is obtained as the result of a successful call to NetIF_Add().
  3. The second argument is the NET_IPv4_ADDR value representing the IPv4 address to be configured.
  4. The third argument is the NET_IPv4_ADDR value representing the subnet mask address that is to be configured.
  5. The fourth argument is the NET_IPv4_ADDR value representing the default gateway IPv4 address that is to be configured.
  6. The fifth argument is a pointer to a NET_ERR variable containing the return error code for the function. If the interface address information is configured successfully, then the return error code will contain the value NET_IPv4_ERR_NONE. Additionally, function returns a Boolean value of DEF_OK or DEF_FAIL depending on the result. Either the return value or the NET_ERR variable may be checked for return status; however, the NET_ERR contains more detailed information and should therefore be the preferred check.


IPv6

Currently, the µC/TCP-IP stack only support manual static IPv6 address configuration and IPv6 Stateless Address Auto-Configuration. Dynamic address configuration with DHCPv6 is not yet supported.  

...