[En-Nut-Discussion] NutUdpSendTo problem

Rich Wellner ethernut at objenv.com
Sun Feb 8 01:42:38 CET 2004


I wonder if you guys can spot me doing something obviously wrong here.  I call
NutUdpSendTo and always get a -1 return.  I see from the mail list archives
that there was a buffer handling problem in NutUdpSendTo in the past, but I've
checked my source and not only does this problem seem unrelated, but I have
the patch for the buffer handling issue.  If I change the dest ip to
207.252.251.233 and run ethereal on the dest node then I get 0 returns from
NutUdpSendTo and the activity light on the ethernut lights up, but the packet
is never seen at the destination.

output:
ip: 207.252.251.238
netmask: 255.255.255.248
gateway: 207.252.251.233
dest ip: 216.127.80.16
return: -1
return: -1
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\nNut/OS %s HTTP Daemon...\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");

    /*
     * LAN configuration using EEPROM values or DHCP/ARP method.
     * If it fails, use fixed values.
     */
    if (NutDhcpIfConfig("eth0", 0, 60000)) {
        u_char mac[] = { MYMAC };
        u_long ip_addr = inet_addr(MYIP);
        u_long ip_mask = inet_addr(MYMASK);

        puts("EEPROM/DHCP/ARP config failed");
        NutNetIfConfig("eth0", mac, ip_addr, ip_mask);
    }
    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