Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12687 Discussions

Retrieve the IP address (DHCP)

Altera_Forum
Honored Contributor II
1,153 Views

Hi, 

 

My application is similar to the examples found with the Nios II IDE (simple_socket_server...). It is based on microC/OS-II and NicheStack. Bassically, I send/receive UDP packets to/from the Cyclone FPGA. 

 

In the network_utilitities.c file, I have the get_ip_addr routine that is called by InterNiche. When I run the application, I can see on the IDE console the IP address obtained with DHCP: 

Acquired IP address via DHCP client for interface: et1 

IP address : 192.168.68.197 

 

Is there a function that I can call in my application to get this IP address value? 

 

Thanks 

 

Martin
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
499 Views

It's available in one of two existing data structures: 

 

nets 

netstatic 

 

Just try debugging your code, and you'll see what I mean. Here's a quick sample, using netstatic: 

 

/* Declare local ipaddr variable. */ ip_addr* ipaddr; /* Assign ipaddr to the network interface's IP Address. * NOTE:  This code assumes that only a single network * interface exists */ ipaddr = &netstatic.n_ipaddr; 

 

including the header, ipport.h, then gets you the ip4_addr[1-4] convenience macros... For example, the following should print your attained IP address: 

 

printf("\nIP Address\n%d.%d.%d.%d\n",        ip4_addr1(*ipaddr),        ip4_addr2(*ipaddr),        ip4_addr3(*ipaddr),        ip4_addr4(*ipaddr)); 

 

NOTE: You could also do the same thing with nets, I believe, though I've not tried that. 

 

Cheers, 

 

- slacker
0 Kudos
Altera_Forum
Honored Contributor II
499 Views

Hi Slacker, 

 

Firstly, thanks for the fast answer. 

I had success with the nets data structure. 

# ############################# 

ip_addr my_ip_addr; 

 

my_ip_addr = nets[0]->n_ipaddr;# ############################# 

 

 

For the netstatic data structure, it was undeclared. 

 

Regards 

 

Martin
0 Kudos
Reply