...
Code Block |
---|
language | cpp |
---|
theme | Confluence |
---|
firstline | 1 |
---|
title | IPv4 Address Configuration Example |
---|
linenumbers | true |
---|
|
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 |
---|
|
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.- 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() . - The second argument is the
NET_IPv4_ADDR value representing the IPv4 address to be configured. - The third argument is the
NET_IPv4_ADDR value representing the subnet mask address that is to be configured. - The fourth argument is the
NET_IPv4_ADDR value representing the default gateway IPv4 address that is to be configured. - 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.
...