//-----------------------------------------------------------------------------
/**
* UDP loopback program.
*/
void loopback_udp(SOCKET s, uint16 port)
{
unsigned int len;
unsigned char buf[MAX_BUF_SIZE];
unsigned char destip[4];
unsigned int destport;
switch(getSn_SR(s))
{
// -------------------------------
case SOCK_UDP: //
if((len=getSn_RX_RSR(s)) > 0) // check the size of received data
{
len = recvfrom(s,buf,len,destip,&destport); // receive data from a destination
if(len !=sendto(s,buf,len,destip,destport)) // send the data to the destination
{
printf("%d : Sendto Fail.len=%ld,",s,len);
printf("%d.%d.%d.%d(%d)\r\n",destip[0],destip[1],destip[2],destip[3],destport);
}
}
break;
// -----------------
case SOCK_CLOSED: // CLOSED
close(s); // close the SOCKET
socket(s,Sn_MR_UDP,port,0); // open the SOCKET with UDP mode
break;
default:
break;
}
}
//-----------------------------------------------------------------------------
// Main function
//-----------------------------------------------------------------------------
void main(void)
{
InitMCU();
initUART();
InitNET();
printf("W5100 Simple UDP Loopback Test Program.\r\n");
DisplayConfig();
while(1)
{
loopback_udp(0, 5000);
loopback_udp(1, 5001);
loopback_udp(2, 5002);
loopback_udp(3, 5003);
}
}
//----------------------------------------------------------------------------- |
댓글을 달아 주세요