- 论坛徽章:
- 0
|
WORD version=MAKEWORD(2,1);
WSADATA wsadata;
WSAStartup(version,&wsadata);
if(wsadata.wVersion!=version)
printf("wrong!!\n" ;
ip="192.168.1.15";
m_iphostsource=inet_addr(ip);
m_s=socket( AF_INET, SOCK_RAW, IPPROTO_IP );
int rcvtimeo=5000; //5 sec insteadof 45 as default
setsockopt(m_s,SOL_SOCKET,SO_RCVTIMEO,(const char *)&rcvtimeo, sizeof(rcvtimeo));
sa.sin_family=AF_INET;
sa.sin_port=htons(4000);
sa.sin_addr.s_addr=m_iphostsource;
if(bind(m_s,(sockaddr *)&sa,sizeof(sa))!=0)
printf("bind error:%d\n",WSAGetLastError());
if(WSAIoctl(m_s,SIO_RCVALL,&dwBufferInLen,sizeof(dwBufferInLen),&dwBufferLen,sizeof(dwBufferLen),&dwBytesReturned,NULL,NULL)!=0)
printf("Ioctl error:%d\n",WSAGetLastError());
if(recv(m_s,buf,sizeof(buf),0)<0)
printf("recv error:%d\n",WSAGetLastError());
编译后的错误代码是10060,MSDN说是连接超时,需要我调用connet()和WSAConnect()
可是为什么呢?有人帮我解释一下吗? |
|