Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20702 Discussions

problem changing static IP in socket server application

Altera_Forum
Honored Contributor II
1,242 Views

I'm trying to test simple sockect server example in Cyclone III NIOS II eval kit using NIOS IDE 8.0.  

 

I checked this example in my old version 7.2 of Quartus and it worked fine!!! 

 

I tried to change static IP in simple_socket_server.h using  

 

# define IPADDR0 192 

# define IPADDR1 168 

# define IPADDR2 10 

# define IPADDR3 11 

 

and settind *use_dhcp=0 

 

by making those changes my simple socket server application worked in 7.2. but in this 8.0 version the static IP never changes from the adress 0.10.10.11. 

 

I've debugged the code and I think htonl instruction doesn't work properly. 

 

 

# define IP4_ADDR(ipaddr, a,b,c,d) ipaddr =  

htonl(((alt_u32)(a & 0xff) << 24) | ((alt_u32)(b & 0xff) << 16) |  

((alt_u32)(c & 0xff) << 8) | (alt_u32)(d & 0xff)) 

 

 

any suggestion??
0 Kudos
6 Replies
Altera_Forum
Honored Contributor II
462 Views

What about with the endianess? 

 

try whit this code: 

 

unsigned int htonl (unsigned int x) {  

# if BYTE_ORDER == LITTLE_ENDIAN  

unsigned char *s = (unsigned char *) &x;  

return (unsigned int) (s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]);  

# else return x;# endif }
0 Kudos
Altera_Forum
Honored Contributor II
462 Views

The project now works as in EDS 7.2. Thank you for giving me this solution. 

 

Could you explain to me why I didn't have to use this instruction in EDS 7.2??? 

 

Do you know another difference in EDS 8.0 ??
0 Kudos
Altera_Forum
Honored Contributor II
462 Views

This function , simply reorders the bytes according to the processor endianess. 

 

The only reason I see for which it didtn't work is due to your processor endianess.
0 Kudos
Altera_Forum
Honored Contributor II
462 Views

then following your comments the difference between my 7.2 and 8.0 could be the NIOS endian configuration

0 Kudos
Altera_Forum
Honored Contributor II
462 Views

There is a bug in the 8.0 IP4_ADDR() macro. See this fix: 

 

http://www.altera.com/support/kdb/solutions/rd06062008_934.html
0 Kudos
Altera_Forum
Honored Contributor II
462 Views

I've modified simple socket server to be UDP instead TCP server. 

 

I've tried to set the destination IP addres by using 

 

UDP_sender.sin_family = AF_INET; UDP_sender.sin_port = htons(30); inet_atom ("192.168.10.10", UDP_sender.sin_addr); 

 

or using  

 

UDP_sender.sin_family = AF_INET; UDP_sender.sin_port = htons(30); IP4_ADDR (UDP_sender.sin_addr.s_addr,192,168,10,10); 

 

both possibilities were working in EDS 7.2 but doesn't in EDS 8.0 

 

When running both attempts, compiler is failing because 'IP4_ADDR' or 'inet_atom' are undefined references.
0 Kudos
Reply