lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] UDP send problem


From: Andrea Visinoni
Subject: [lwip-users] UDP send problem
Date: Tue, 12 Oct 2010 11:10:16 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.9.2.9) Gecko/20100915 Lightning/1.0b2 Thunderbird/3.1.4

Hi,
i just modified a HTTP client example to send an UDP packet to my NTP server. But it works only if i send my packet 3 times, the first 2 send are not working. With the HTTP original example it was working correctly since the first write.
Any hits? I'm using FreeRTOS + lwip 1.3.2 on a AT32UC3A board.

Andrea

portTASK_FUNCTION( vNTP, pvParameters )
{
        int s, ret, err, opt;
        struct sockaddr_in addr;
        struct tm tm_time;
        time_t timetest;
        unsigned long rxbuf[12];
        char            errs[255];
unsigned char msg[48] = {010, 0, 0, 0, 0, 0, 0, 0, 0}; // the packet we send

        /* set up address to connect to */
        memset(&addr, 0, sizeof(addr));
        addr.sin_len = sizeof(addr);
        addr.sin_family = AF_INET;
        addr.sin_port = htons(123);
        addr.sin_addr.s_addr = inet_addr("10.0.2.34");

        /* create the socket */
        if ((s = lwip_socket(AF_INET, SOCK_DGRAM, 0)) == -1)
        {
                err = errno;
                printk("create socket error, errno: %d\n", err);
                go_idle();
        }

        /* connect */
        if ((ret = lwip_connect(s, (struct sockaddr*)&addr, sizeof(addr))) == 
-1)
        {
                err = errno;
                printk("Connect error, errno: %d\n", err);
                go_idle();
        }

        /* set recv timeout (100 ms) */
        opt = 100;
        ret = lwip_setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &opt, sizeof(int));

        /* Write data */
        ret = lwip_write(s, (char *)msg, sizeof(msg));
        ret = lwip_write(s, (char *)msg, sizeof(msg));
        ret = lwip_write(s, (char *)msg, sizeof(msg));

        /* Read data*/
        ret = lwip_read(s, (char *)rxbuf, 12 * 4);

        if (ret == 48)
        {
                timetest  = ntohl((time_t)rxbuf[10]);
                timetest -= 2208988800U;

                tm_time = gmtime(&timetest)[0];

sprintf (errs, "time : %02d/%02d/%d %02d:%02d:%02d\n", tm_time.tm_mday, tm_time.tm_mon + 1, tm_time.tm_year + 1900, tm_time.tm_hour, tm_time.tm_min, tm_time.tm_sec);
                printk(errs);
        }

        go_idle();
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]