Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
17 years ago

problem changing static IP in socket server application

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??

6 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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 }
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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 ??
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

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

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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.