Versions Compared

Key

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

...

The first function aids the developer by converting a string format IPv4 address such as “192.168.1.2” to its hexadecimal equivalent. The second function is used to configure an interface with the specified IPv4, network mask and gateway addresses. An example is shown in listing Listing - IPv4 Address Configuration Example.

Anchor
Listing - IPv4 Address Configuration Example
Listing - IPv4 Address Configuration Example

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.  

...

The first function aids the developer by converting a string format IPv6 address such as “fe80::1111:1111” to its network equivalent. The second function is used to configure an interface with the specified IPv6 address. An example is shown in listing Listing - IPv6 Address Configuration Example.

Anchor
Listing - IPv6 Address Configuration Example
Listing - IPv6 Address Configuration Example

Code Block
languagecpp
themeConfluence
firstline1
titleIPv6 Address Configuration Example
linenumberstrue
CPU_BOOLEAN    cfg_success;
NET_IPv6_ADDR  ipv6_addr;
NET_FLAGS      ipv6_flags;
NET_ERR        err;
           
           
(void)NetASCII_Str_to_IP((CPU_CHAR *)"fe80::1111:1111", 	/* See Note #1 */
                                     &ipv6_addr, 
                                      NET_IPv6_ADDR_SIZE, 
                                     &err);
 
ipv6_flags = 0;                                             
DEF_BIT_SET(ipv6_flags, NET_IPv6_FLAG_BLOCK_EN);            /* See Note #2 */
DEF_BIT_SET(ipv6_flags, NET_IPv6_FLAG_DAD_EN);              /* See Note #3 */
 
cfg_success = NetIPv6_CfgAddrAdd(if_nbr,         			/* See Note #4 */
                                &ipv6_addr,      			/* See Note #5 */
                                 64,             			/* See Note #6 */
                                 ipv6_flags,                /* See Note #7 */  
                                &err);           			/* See Note #8 */


Panel
bgColor#f0f0f0
  1. See NetASCII_Str_to_IP for more details.
  2. Set Address Configuration as blocking.

  3. Enable DAD with Address Configuration.

  4. 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().
  5. The second argument is the pointer to the NET_IPv6_ADDR value representing the IPv6 address to be configured.
  6. The third argument is the IPv6 prefix length of the address to be configured.
  7. The fourth argument is a set of network flags holding options specific to the address configuration process.
  8. 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_IPv6_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.


As shown in  Listing - IPv6 Address Configuration Example, the NetIPv6_CfgAddrAdd() function can take as argument a set of network flags. The following options are available :

...

If the function is made none blocking, it is possible to set a hook function to advertise the application when the address configuration process has finished. The API function NetIPv6_CfgAddrHookSet can be used to set the hook function. Refer to section IPv6 Static Address Configuration Hook Function for all the details on the hook function format and usage. Listing - Non-Blocking IPv6 Address Configuration Example shows an example of a non-blocking IPv6 static address configuration.

Anchor
Listing - Non-Blocking IPv6 Address Configuration Example
Listing - Non-Blocking IPv6 Address Configuration Example

Code Block
languagecpp
themeConfluence
firstline1
titleListing - Non-Blocking IPv6 Address Configuration Example
linenumberstrue
CPU_BOOLEAN    cfg_success;
NET_IPv6_ADDR  ipv6_addr;
NET_FLAGS      ipv6_flags;
NET_ERR        err;
           
           
(void)NetASCII_Str_to_IP((CPU_CHAR *)"fe80::1111:1111", 	/* Convert IPv6 string address to 128 bit address.      */
                                     &ipv6_addr, 
                                      NET_IPv6_ADDR_SIZE, 
                                     &err);

NetIPv6_AddrAutoCfgHookSet(if_nbr,                          /* Set hook function to received addr cfg result.       */
                          &App_AddrCfgResult,				/* TODO update pointer to hook fnct implemented in App. */
                          &err);  
 
ipv6_flags = 0;                                             
DEF_BIT_CLR(ipv6_flags, NET_IPv6_FLAG_BLOCK_EN);            /* Set Address Configuration as non-blocking.           */
DEF_BIT_SET(ipv6_flags, NET_IPv6_FLAG_DAD_EN);              /* Enable DAD with Address Configuration.               */
 
cfg_success = NetIPv6_CfgAddrAdd(if_nbr,         			/* Add a statically-configured IPv6 host address to ... */
                                &ipv6_addr,      			/* ... the interface.                                   */
                                 64,             			
                                 ipv6_flags,               
                                &err);      


Stateless Address Auto-Configuration

...