[En-Nut-Discussion] NutNetIfConfig problem

Daniel Fiedler (Ethernut) ethernut at fitus.de
Fri Apr 27 16:49:03 CEST 2012


Hello,

 

i have a problem using NutNetIfConfig on the EVK1100 the function return the
error value -1 but the ip adr and the network mask are set correctly by the
function. Send ping packets will work fine, also the http connection works
fine. 

 

Here a piece of my code:

 

       printf ( "Configure %s\n", DEV_ETHER_NAME );

       printf ( "Load config from non-volatile memory....." );

       

       if ( NutNetLoadConfig( DEV_ETHER_NAME ) ) {

             // Load Config from non volatile memory failed

             puts ( "failed" );

             

             uint8_t mac[] = MY_MAC;

             

             #ifdef USE_DHCP     

             

                    puts ( "Try DHCP configuration" );

             

                    printf ( "DHCP configuration...." );

                    

                    if ( NutDhcpIfConfig( DEV_ETHER_NAME, mac, 60000 ) ) {

                           puts ( "failed" );

             #endif       

                           uint32_t ip_addr = inet_addr(MY_IPADDR);

                           uint32_t ip_mask = inet_addr(MY_IPMASK);

                           uint32_t ip_gate = inet_addr(MY_IPGATE);

                           

                           puts ( "Use hard coded values" );

                           

                           if ( NutNetIfConfig( DEV_ETHER_NAME, mac,
ip_addr, ip_mask ) == 0 ) {

                                  // Set Gateway

                                  printf ( "Set Gateway....." );

                                  if ( NutIpRouteAdd(0, 0, ip_gate,
&DEV_ETHER ) ) {

                                        puts ( "failed" );

                                  }

                                  else {

                                        puts ( "ok" );

                                  }

                                  

                                  puts ( "Network config finished" );

                           }

                           else {

                                  puts ( "Error" );

                           }

             #ifdef USE_DHCP

                    }

                    else {

                           puts ( "ok");

                    }

             #endif

       }

       else {

             // Config loaded form non volatile memory

             puts ( "ok" );

       }

       

       printf ( "IP-Adr: %s\n", inet_ntoa( confnet.cdn_ip_addr ) );

       printf ( "IP-Maks: %s\n", inet_ntoa( confnet.cdn_ip_mask ) ); //
Anzeige bei DHCP trotz ntoa verdeht

       printf ( "Gateway: %s\n", inet_ntoa ( confnet.cdn_gateway ) ); //
Anzeige bei DHCP trotz ntoa verdeht

 

 

       

This code produces the following output on the serial port:

 

Registering ethernet device.....ok<\r><\n>

Configure eth0<\r><\n>

Load config from non-volatile memory.....failed<\r><\n>

Use hard coded values<\r><\n>

Error<\r><\n>

IP-Adr: 10.0.0.199<\r><\n>

IP-Maks: 255.255.255.0<\r><\n>

Gateway: 0.0.0.0<\r><\n>

 

This makes it impossible to set the gateway.

 

Best regards

Daniel

 




More information about the En-Nut-Discussion mailing list