Forum Discussion
Altera_Forum
Honored Contributor
19 years agoRetrieve the IP address (DHCP)
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 Martin2 Replies
- Altera_Forum
Honored Contributor
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:
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:/* 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;
NOTE: You could also do the same thing with nets, I believe, though I've not tried that. Cheers, - slackerprintf("\nIP Address\n%d.%d.%d.%d\n", ip4_addr1(*ipaddr), ip4_addr2(*ipaddr), ip4_addr3(*ipaddr), ip4_addr4(*ipaddr)); - Altera_Forum
Honored Contributor
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