[En-Nut-Discussion] NutUdpSendTo problem -- follow up (still not working)

Rich Wellner ethernut at objenv.com
Tue Feb 10 20:32:41 CET 2004


Thanks for the tips from yesterday.  I've made some changes and still cannot
send to the Internet, but can now see packets on my local network.

The only thing I have to go on right now is that the gateway may not be
getting set properly.  Output is below.  I don't understand why NutIpRouteAdd
returns success but an immediate call to NutIpRouteQuery returns a null
NUTDEVICE and ip address of 0.

Output: 

UDP Monitor Daemon, Nut/OS: 3.4.1.1
route: 0
device: 0
Queried: 0.0.0.0
ip: 207.252.251.238
netmask: 255.255.255.248
gateway: 207.252.251.233
dest ip: 216.127.80.16
return: -1

Source:

int main(void)
{
    u_long baud = 115200;
    u_char i;
    u_long dest_addr;
    UDPSOCKET *udpsock;

    /*
     * Initialize the uart device.
     */
    NutRegisterDevice(&devDebug0, 0, 0);
    freopen("uart0", "w", stdout);
    _ioctl(_fileno(stdout), UART_SETSPEED, &baud);
    NutSleep(200);
    printf("\n\nUDP Monitor Daemon, Nut/OS: %s\n", NutVersionString());

#ifdef NUTDEBUG
    NutTraceTcp(stdout, 0);
    NutTraceOs(stdout, 0);
    NutTraceHeap(stdout, 0);
    NutTracePPP(stdout, 0);
#endif

    /*
     * Register Ethernet controller.
     */
    //if(NutRegisterDevice(&devSmsc111, 0, 0)) 
    if (NutRegisterDevice(&devEth0, 0x8300, 5))
        puts("Registering device failed");

    u_char mac[] = { MYMAC };
    u_long ip_addr = inet_addr(MYIP);
    u_long ip_mask = inet_addr(MYMASK);
    
    NutNetIfConfig("eth0", 
                   mac, 
                   ip_addr, 
                   ip_mask);

    printf("route: %d\n", NutIpRouteAdd(0, 0, inet_addr("207.252.251.233"), &devEth0));
    printf("device: %d\n", NutIpRouteQuery(inet_addr("216.127.80.16"), &ip_addr));
    printf("Queried: %s\n", inet_ntoa(ip_addr));

    printf("ip: %s\n", inet_ntoa(confnet.cdn_ip_addr));
    printf("netmask: %s\n", inet_ntoa(confnet.cdn_ip_mask));
    printf("gateway: %s\n", inet_ntoa(confnet.cdn_gateway));
 
    udpsock = NutUdpCreateSocket(0);

    dest_addr = inet_addr("216.127.80.16");
    printf("dest ip: %s\n", inet_ntoa(dest_addr));

    /*
     * We could do something useful here, like serving a watchdog.
     */
    NutThreadSetPriority(254);
    for (;;) {
        printf("return: %d\n", NutUdpSendTo(udpsock, dest_addr, 2526, "test", 4));
        NutSleep(1000);
        
    }
}



More information about the En-Nut-Discussion mailing list