我把EVT307\EXAM\ETH中 DNS 获得的IP填到 TCPCLinet里面,建立不了链接啊。。。。
DNS Test
SystemClk:120000000
net version:14
mac addr:38 3b 26 89 50 91
WCHNET_LibInit Success
PHY Link Success
DHCP Success
IPAddr = 192.168.10.101
GWIPAddr = 192.168.10.1
IPAddr = 255.255.255.0
DNS1: 192.168.10.1
DNS2: 0.0.0.0
Host Name = www.wch.cn
IP= 58.213.45.186
Connecting to: 58.213.45.186
WCHNET_SocketCreat 0
Error: 1D
Error: 17
void WCHNET_DNSCallBack(const char *name, u8 *ipaddr, void *callback_arg)
{
u8 i;
if(ipaddr == NULL)
{
printf("DNS Fail\r\n");
return;
}
printf("Host Name = %s\r\n", name);
printf("IP= %d.%d.%d.%d\r\n", ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]);
memcpy(DESIP, ipaddr, 4);
if(callback_arg != NULL)
{
printf("callback_arg = %02x\r\n", (*(u8 *)callback_arg));
}
WCHNET_DNSStop(); //stop DNS,and release socket
WCHNET_CreateTcpSocket();
i = WCHNET_SocketConnect(SocketId); //make a TCP connection
mStopIfError(i);
//Create a TCP connection
}
void WCHNET_CreateTcpSocket(void)
{
u8 i;
SOCK_INF TmpSocketInf;
memset((void *) &TmpSocketInf, 0, sizeof(SOCK_INF));
printf("Connecting to: %d.%d.%d.%d \r\n", (u16)DESIP[0], (u16)DESIP[1],
(u16)DESIP[2], (u16)DESIP[3]);
memcpy((void *) TmpSocketInf.IPAddr, DESIP, 4);
TmpSocketInf.DesPort = desport;
TmpSocketInf.SourPort = srcport++;
TmpSocketInf.ProtoType = PROTO_TYPE_TCP;
TmpSocketInf.RecvBufLen = RECE_BUF_LEN;
i = WCHNET_SocketCreat(&SocketId, &TmpSocketInf);
printf("WCHNET_SocketCreat %d\r\n", SocketId);
mStopIfError(i);
}