Specifications

To assign a static IP address, include the lines:
*use_dhcp = 0;
The prototype for get_ip_addr() is in the header file <iniche path>/inc/alt_iniche_dev.h.
INICHE_DEFAULT_IF, defined in system.h, identifies the network interface that you defined at system
generation time. You can control INICHE_DEFAULT_IF through the iniche_default_if BSP setting.
DHCP_CLIENT, also defined in system.h, specifies whether to use the DHCP client application to obtain an
IP address. You can set or clear this property with the altera_iniche.dhcp_client setting.
Calling the Sockets Interface
After you initialize your Ethernet device, use the sockets API in the remainder of your program to access
the IP stack.
To create a new task that talks to the IP stack using the sockets API, you must use the function
TK_NEWTASK(). The TK_NEWTASK() function is part of the NicheStack TCP/IP Stack operating system
(OS) porting layer. TK_NEWTASK() calls the MicroC/OS-II OSTaskCreate() function to create a thread,
and performs some other actions specific to the NicheStack TCP/IP Stack.
The prototype for TK_NEWTASK() is:
int TK_NEWTASK(struct inet_task_info* nettask);
Example 11-3: An Implementation of get_ip_addr()
#include <alt_iniche_dev.h>
#include "includes.h"
#include "ipport.h"
#include "tcpport.h"
int get_ip_addr(alt_iniche_dev* p_dev,
ip_addr* ipaddr,
ip_addr* netmask,
ip_addr* gw,
int* use_dhcp)
{
int ret_code = -1;
/*
* The name here is the device name defined in system.h
*/
if (!strcmp(p_dev->name, "/dev/" INICHE_DEFAULT_IF))
{
/* The following is the default IP address if DHCP
fails, or the static IP address if DHCP_CLIENT is
undefined. */
IP4_ADDR(&ipaddr, 10, 1, 1 ,3);
/* Assign the Default Gateway Address */
IP4_ADDR(&gw, 10, 1, 1, 254);
/* Assign the Netmask */
IP4_ADDR(&netmask, 255, 255, 255, 0);
#ifdef DHCP_CLIENT
*use_dhcp = 1;
#else
*use_dhcp = 0;
#endif /* DHCP_CLIENT */
ret_code = ERR_OK;
}
return ret_code;
}
NII5V2
2015.05.14
Calling the Sockets Interface
11-7
Ethernet and the NicheStack TCP/IP Stack - Nios II Edition
Altera Corporation
Send Feedback