void initialize_networking(_ip_address ip, _ip_address mask, _ip_address gateway, _ip_address dns, uint_32 pcbs, uint_32 msgs,
uint_32 sockets, boolean dhcp)
{
int_32 error;
IPCFG_IP_ADDRESS_DATA ip_data;
_enet_address serverAddress =
{ 0x00, 0xcf, 0x52, 0x53, 0x54, 0xcc };
/* runtime RTCS configuration */
_RTCSPCB_init = pcbs;
_RTCS_msgpool_init = msgs;
_RTCS_socket_part_init = sockets;
error = RTCS_create();
if (error == RTCS_OK)
{
error = ipcfg_init_device(BSP_DEFAULT_ENET_DEVICE, serverAddress);
#if RTCSCFG_ENABLE_LWDNS
LWDNS_server_ipaddr = dns;
ipcfg_add_dns_ip(BSP_DEFAULT_ENET_DEVICE, LWDNS_server_ipaddr);
#endif
// check link status
printf("\nWaiting for ethernet cable plug in ... ");
while (!ipcfg_get_link_active(BSP_DEFAULT_ENET_DEVICE))
{
};
printf("Cable connected\n");
/* If DHCP Enabled, get IP address from DHCP server */
if (dhcp)
{
printf("\nDHCP bind ... ");
error = ipcfg_bind_dhcp_wait(BSP_DEFAULT_ENET_DEVICE, 1, &ip_data);
if (error != IPCFG_ERROR_OK)
{
printf("Error %08x!\n", error);
}
else
{
printf("Successful!\n");
}
}
else
{
ip_data.ip = ip;
ip_data.mask = mask;
ip_data.gateway = gateway;
/* Else bind with static IP */
printf("\nStatic IP bind ... ");
error = ipcfg_bind_staticip(BSP_DEFAULT_ENET_DEVICE, &ip_data);
if (error != IPCFG_ERROR_OK)
{
printf("Error %08x!\n", error);
}
else
{
printf("Successful!\n");
}
}
if (error == IPCFG_ERROR_OK)
{
ipcfg_get_ip(BSP_DEFAULT_ENET_DEVICE, &ip_data);
printf("\nIP Address : %d.%d.%d.%d\n", IPBYTES(ip_data.ip));
printf("\nIP Address HEX : %x", ip_data.ip);
printf("\nSubnet Address : %d.%d.%d.%d\n", IPBYTES(ip_data.mask));
printf("\nGateway Address : %d.%d.%d.%d\n", IPBYTES(ip_data.gateway));
printf("\nDNS Address : %d.%d.%d.%d\n", IPBYTES(ipcfg_get_dns_ip(BSP_DEFAULT_ENET_DEVICE,0)));
}
}
else
{
printf("\nRTCS_Create failed !\n");
_task_block();
}
}
Hope this will be useful to you.