论坛: 菜鸟乐园 标题: 关于socket连接超时问题 复制本贴地址    
作者: gccbuilder [gccbuilder]    论坛用户   登录
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()
可是为什么呢?有人帮我解释一下吗?


地主 发表时间: 04-02-27 17:38

论坛: 菜鸟乐园

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号