Fw: [En-Nut-Discussion] UDP BroadCast

Avex avexwu at yahoo.com.tw
Wed Sep 25 03:08:43 CEST 2002


Hi  Harald,

Did you test my code already ? After modified the bug you
mentioned , I still fail to send broadcast msg back.
Can you help me to test the sample code again ?

#include <string.h>
#include <dev/nicrtl.h>
#include <sys/heap.h>
#include <sys/timer.h>
#include <dev/uartavr.h>
#include <sys/thread.h>
#include <sys/print.h>
#include <sys/confnet.h>
#include <netinet/sostream.h>
#include <arpa/inet.h>

THREAD(NutMain, arg)
{
    NUTDEVICE *uart;
    u_long baud = 9600;
    char *data = "test";
    char *p;
    // for UDP
     unsigned char buff[512];
     u_long address;
     UDPSOCKET *sock_udp;
     int nRead;
     u_short cli_port;

    // Register Realtek controller at address 8300 hex
    // and interrupt 5 and configure lan interface.

    NutRegisterDevice(&devUart0, 0, 0);
    NutNetAutoConfig("eth0");

    uart = NutDeviceOpen("uart0");
    NutDeviceIOCtl(uart, UART_SETSPEED, &baud);
    NutRegisterDevice(&devEth0, 0x8300, 5);
    NutNetAutoConfig("eth0");

    NutPrintFormat(uart, "program started!");
    NutPrintFlush(uart);

    // Create a socket.
    sock_udp = NutUdpCreateSocket(1234);

    while(1)
    {

        if((nRead = NutUdpReceiveFrom(sock_udp, &address, &cli_port,
buff,sizeof(buff), 600000)) > 0)
        {
            buff[nRead] = 0;
            NutPrintFormat(uart, "Data received :%s\r\n", buff);
            p = (char*)&address;
            NutPrintFormat(uart, "address
:%ud,%ud,%ud,%ud",p[0],p[1],p[2],p[3]);
            NutPrintFormat(uart, "%s\r\n",inet_ntoa(address));
            NutPrintFlush(uart);

            NutUdpSendTo(sock_udp, 0xffffffff, 1234, data, 4);

            // the line below is not workable. as echo
            NutUdpSendTo(sock_udp, inet_addr("255.255.255.255"), 1234,
buff,nRead);

            // the line below is workable. send "test" string
            NutUdpSendTo(sock_udp, address, 1234, data, 4);
        }

    }

    NutUdpDestroySocket(sock_udp);
}



Avex


> Avex,
>
> Wow, big problem in the checksum routines. It appeared
> once, but suddenly disappeared again for no know reason.
>
> The broadcast telegrams in your code produce these wrong
> checksums again.




-----------------------------------------------------------------
< ¨C¤Ñ³£ Yahoo!©_¼¯ >  www.yahoo.com.tw



More information about the En-Nut-Discussion mailing list