<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=big5" http-equiv=Content-Type>
<META content="MSHTML 5.00.3315.2870" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=MingLiu size=2>Hi all,</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=細明體 size=2>I tested UDP 'NutUdpSendTo' function and fail before
(OS 2.5.2).</FONT></DIV>
<DIV><FONT face=細明體 size=2>So I wrote a simple test program to test it. I found,
broadcast </FONT></DIV>
<DIV><FONT face=細明體 size=2>function is not workable, peer to peer is ok. What's
wrong with </FONT></DIV>
<DIV><FONT face=細明體 size=2>it ? <FONT face=細明體 size=2>Hope someone can help
me.</FONT></FONT></DIV>
<DIV><FONT face=細明體 size=2></FONT> </DIV>
<DIV><FONT face=細明體 size=2>see codes below.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=MingLiu size=2></FONT> </DIV>
<DIV><FONT face=MingLiu size=2>#include <string.h></FONT></DIV>
<DIV><FONT face=MingLiu size=2>#include <dev/nicrtl.h></FONT></DIV>
<DIV><FONT face=MingLiu size=2>#include <sys/heap.h><BR>#include
<sys/timer.h></FONT></DIV>
<DIV><FONT face=MingLiu size=2>#include <dev/uartavr.h></FONT></DIV>
<DIV><FONT face=MingLiu size=2>#include <sys/thread.h><BR>#include
<sys/print.h><BR>#include <sys/confnet.h><BR>#include
<netinet/sostream.h><BR>#include <arpa/inet.h></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=MingLiu size=2>THREAD(NutMain, arg)<BR>{<BR>
UDPSOCKET* sock;<BR> NUTDEVICE *uart;<BR>
u_long baud = 9600;<BR> char *data =
"test";<BR> char *p;<BR> // for
UDP<BR> unsigned char
buff[512];<BR> u_long
address;<BR> UDPSOCKET
*sock_udp;<BR> int nRead;<BR>
u_short cli_port;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=MingLiu size=2> // Register Realtek controller
at address 8300 hex<BR> // and interrupt 5 and configure lan
interface.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=MingLiu size=2>
NutRegisterDevice(&devUart0, 0, 0);<BR>
NutNetAutoConfig("eth0");</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=MingLiu size=2> uart =
NutDeviceOpen("uart0");<BR> NutDeviceIOCtl(uart,
UART_SETSPEED, &baud);</FONT></DIV>
<DIV><FONT face=MingLiu size=2>
NutRegisterDevice(&devEth0, 0x8300, 5);</FONT></DIV>
<DIV><FONT face=MingLiu size=2>
NutNetAutoConfig("eth0");</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=MingLiu size=2> NutPrintFormat(uart, "program
started!");<BR> NutPrintFlush(uart);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=MingLiu size=2> // Create a
socket.<BR> sock_udp = NutUdpCreateSocket(1234);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=MingLiu size=2> while(1)<BR>
{</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=MingLiu size=2>
if((nRead = NutUdpReceiveFrom(sock_udp, &address, &cli_port, buff,
sizeof(buff), 600000)) > 0)<BR>
{<BR>
buff[nRead] =
0;<BR>
NutPrintFormat(uart, "Data received :%s\r\n",
buff);<BR> p =
(char*)&address;<BR>
NutPrintFormat(uart, "address :%d,%d,%d,%d",
p[3],p[2],p[1],p[0]);<BR>
NutPrintFormat(uart,
"%s\r\n",inet_ntoa(address));<BR>
NutPrintFlush(uart);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=MingLiu
size=2>
NutUdpSendTo(sock_udp, 0xffffffff, 1234, data, 4);</FONT></DIV>
<DIV><FONT face=MingLiu size=2></FONT> </DIV>
<DIV><FONT face=MingLiu
size=2> // the
line below is not workable. as
echo<BR>
NutUdpSendTo(sock_udp, inet_addr("255.255.255.255"), 1234, buff,
nRead);</FONT></DIV>
<DIV><FONT face=MingLiu size=2><FONT face=MingLiu
size=2></FONT></FONT> </DIV>
<DIV><FONT face=MingLiu size=2><FONT face=MingLiu
size=2> // the
line below is workable. send "test" string
<BR></FONT>
NutUdpSendTo(sock_udp, address, 1234, buff,
nRead);<BR> }<BR></DIV></FONT>
<DIV><FONT face=MingLiu size=2> }</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=MingLiu size=2>
NutUdpDestroySocket(sock_udp);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=MingLiu size=2>}<BR></FONT></DIV></BODY></HTML>