Hi Sam,
I have solved the problem by fixing the code of the network_utilities.c file of lwip_webserver example. The updated code listing of functions get_ip_addr and dhcp_timeout_task are listed below. Updated parts of the file are between "/********************/" -rows.
The bug was that if static ip was used there wasn't any eth adapter working as default eth-interface.
http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/ohmy.gif
Regards,
CoolMan
----------------------UPDATED CODE START-------------------------------
int get_ip_addr(alt_lwip_dev* lwip_dev, struct ip_addr* ipaddr,
struct ip_addr* netmask, struct ip_addr* gw,
int* use_dhcp)
{
int ret_code = 0;
if (!strcmp(lwip_dev->name, "/dev/" LWIP_DEFAULT_IF))
{# if LWIP_DHCP == 1
*use_dhcp = 1;
/*
* If we are telling LWIP to attempt DHCP, all that is needed is to save
* the the LWIP device in question to a the global netif "adapter"; the
* DHCP timeout task will then querry this device to see whether an IP
* address has been set.
*
* If we are not attempting DHCP, static network settings are assigned here
* and we go on our merry way.
*/
adapter = lwip_dev->netif;
# ifdef LCD_DISPLAY_NAME
/* Clear the LCD screen */
fprintf(lcdDevice, "\x1b");
fprintf(lcdDevice, "[2J");
fprintf(lcdDevice, "Using DHCP to\nfind IP Addr");# endif /* LCD_DISPLAY_NAME */
printf("Using DHCP to find an IP Address\n");
# else
/***********************************************************/
//TOP 7.2.2007
adapter = lwip_dev->netif;
/***********************************************************/
IP4_ADDR(ipaddr, IPADDR0,IPADDR1,IPADDR2,IPADDR3);
IP4_ADDR(gw, GWADDR0,GWADDR1,GWADDR2,GWADDR3);
IP4_ADDR(netmask, MSKADDR0,MSKADDR1,MSKADDR2,MSKADDR3);
*use_dhcp = 0;
printf("Static IP Address is %d.%d.%d.%d\n",
ip4_addr1(ipaddr),
ip4_addr2(ipaddr),
ip4_addr3(ipaddr),
ip4_addr4(ipaddr));
/***********************************************************/
//TOP 7.2.2007
netif_set_default(adapter);
//TOP 7.2.2007
netif_set_up(adapter);
/***********************************************************/
# ifdef LCD_DISPLAY_NAME
/* Clear the LCD screen */
fprintf(lcdDevice, "\x1b");
fprintf(lcdDevice, "[2J");
fprintf(lcdDevice, "Static IP Addr\n %d.%d.%d.%d",
ip4_addr1(ipaddr),
ip4_addr2(ipaddr),
ip4_addr3(ipaddr),
ip4_addr4(ipaddr));# endif /* LCD_DISPLAY_NAME */
# endif /* LWIP_DHCP */
ret_code = 1;
}
return ret_code;
}
/*
* dhcp_timeout_task()
*
* This LWIP-called routine is responsible for checking to see whether DHCP
* was sucessful. Here we check to see whether a timeout (120 seconds in this
* case) has elapsed. If so, display an error, assign a static address, and
* bail out. If not, continue checking for DHCP success and bail out once
* a DHCP address assignment is complete.
*
* This routine also displays the assigned IP address to the user (via STDOUT
* and, if equipped, LCD screen.
*
* Note: LCD_DISPLAY_NAME is defined in user.h to be the LCD interface for
* the "standard" example design.
*/# if LWIP_DHCP == 1
void dhcp_timeout_task()
{
static int have_address = 0, timeout_dhcp = 0;
struct ip_addr ipaddr, netmask, gw;
if (!have_address)
{
/*
* For demo purposes we need to use DHCP to allocate an IP Address
* and LWIP had no mechanism to tell us one is allocated. Wait two
* minutes if we don't have one we use a static IP address
*/
if(timeout_dhcp < 120)
{
timeout_dhcp++;
if (!ip_addr_isany(&adapter->ip_addr))
{
have_address = 1;
printf("Assigned IP Address is %d.%d.%d.%d\n\n",
ip4_addr1(&adapter->ip_addr),
ip4_addr2(&adapter->ip_addr),
ip4_addr3(&adapter->ip_addr),
ip4_addr4(&adapter->ip_addr));
# ifdef LCD_DISPLAY_NAME
lcdDevice = fopen(LCD_DISPLAY_NAME, "w");
/* Clear screen */
fprintf(lcdDevice, "\x1b");
fprintf(lcdDevice, "[2J");
fprintf(lcdDevice, "DHCP IP Addr is \n %d.%d.%d.%d",
ip4_addr1(&adapter->ip_addr),
ip4_addr2(&adapter->ip_addr),
ip4_addr3(&adapter->ip_addr),
ip4_addr4(&adapter->ip_addr));
fclose(lcdDevice);# endif /* LCD_DISPLAY_NAME */
}
}
/*
* You're in a bit of trouble if this happens, you could assign a static
* IP address but how do we choose it?
*/
else
{
dhcp_stop(adapter);
IP4_ADDR(&ipaddr, IPADDR0,IPADDR1,IPADDR2,IPADDR3);
IP4_ADDR(&gw, GWADDR0,GWADDR1,GWADDR2,GWADDR3);
IP4_ADDR(&netmask, MSKADDR0,MSKADDR1,MSKADDR2,MSKADDR3);
netif_set_addr( adapter,&ipaddr, &netmask, &gw);
have_address = 1;
printf("DHCP Failed to assign an IP Address\n");
printf("Using static address: %d.%d.%d.%d\n\n",
ip4_addr1(&adapter->ip_addr),
ip4_addr2(&adapter->ip_addr),
ip4_addr3(&adapter->ip_addr),
ip4_addr4(&adapter->ip_addr));
/***********************************************************/
//TOP 7.2.2007
netif_set_default(adapter);
//TOP 7.2.2007
netif_set_up(adapter);
/***********************************************************/
# ifdef LCD_DISPLAY_NAME
lcdDevice = fopen(LCD_DISPLAY_NAME, "w");
/* Clear the LCD screen */
fprintf(lcdDevice, "\x1b");
fprintf(lcdDevice, "[2J");
fprintf(lcdDevice, "DHCP Failed using\n %d.%d.%d.%d",
ip4_addr1(&adapter->ip_addr),
ip4_addr2(&adapter->ip_addr),
ip4_addr3(&adapter->ip_addr),
ip4_addr4(&adapter->ip_addr));
fclose(lcdDevice);# endif /* LCD_DISPLAY_NAME */
}
}
}# endif /* LWIP_DHCP */
----------------------UPDATED CODE END------------------------------
--- Quote Start ---
originally posted by samlittle@Jan 19 2007, 04:26 AM
hi,
i have the same situation. if i turn on dhcp that will be fine, except getting failure from dhcp server. so, i use static ip and trun off dhcp but it doesn't work. i also use microtronix ethernet-usb expansion board and mircotronix lwip.
does anyone can help me to solve this?
best regards,
sam
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=20711)
--- quote end ---
--- Quote End ---