Article ID: 000080568 Content Type: Troubleshooting Last Reviewed: 09/11/2012

Why does the NicheStack default IP address get assigned incorrectly when the DHCP server cannot be found or times out?

Environment

BUILT IN - ARTICLE INTRO SECOND COMPONENT
Description

A redefinition of the macro used to assign the default IP address changed in the Nios® II tools, version 8.0, which causes the default IP address to be assigned incorrectly.  This bug affects the example designs simple socket server and the web server.  To fix this problem in your installation of the Nios II tools, you will have to modify the template files for these projects by doing the following steps:

 

1) Locate your Nios II installation, version 8.0: Find the location where you have installed the Nios II installation.  The default path for the root directory is typically C:\altera\80\nios2eds on a Windows workstation.

2) Find the sub-folder software:  In the directory mentioned above, go into the examples\software directory.  This directory contains all of the Nios II software templates.

3) Modify the file network_utilities.c for the web_server project:  Locate the web_server directory, and open the file network_utilities.c in a text editor.  Find the IP4_ADDR macro and modify it to include an extra set of parenthesis "(" and  ")", beginning after the "htonl" function and ending at the end of the function call. 

 

The orginal version of the function looks like this:

 

#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))

 

Once the fix has been applied the function should look like this:

 

#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)))

 

Once you have done this, save and close the file.

 

4) Modify the file network_utilities.c for the simple_socket_server project: Repeat the steps listed above.

 

After you have performed these steps, the next time you re-generate either the web_server or simple_socket_server projects they include this fix and run correctly.

 

(Note: If you have already generated your software project from a template, you can just modify the local copy of network_utilities.c, which resides in your project's application folder.  Follow the instructions in step#3 (above), then rebuild your application.)

Related Products

This article applies to 1 products

Intel® Programmable Devices