socket 10013error #10013...

Top 10 Issues
01. 02. 03. 04. 05. 06. 07. 08. 09. 10.
Socket.error Errno 10013 An Attempt Was Made To Access A Socket In A Way Forbidden Its Access Permis Help VideosPopular Subjects& & & & & & & & & & Latest Issues& & & & & & & & & &
&&&& &&&&0.01Socket 错误一览表_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
Socket 错误一览表
上传于||文档简介
&&S​o​c​k​e​t​ ​错​误​一​览​表
大小:4.42KB
登录百度文库,专享文档复制特权,财富值每天免费拿!
你可能喜欢socket error#10054如何解决?
socket error#10054如何解决?
09-01-23 &
经常出现的Connection reset by peer: 原因可能是多方面的,不过更常见的原因是:①:服务器的并发连接数超过了其承载量,服务器会将其中一些连接Down掉;②:客户关掉了浏览器,而服务器还在给客户端发送数据;③:浏览器端按了Stop 连接被防火樯或proxy中断&或因为您有***ip分享器请将ip分享器先拿掉,直接将计算机接adsl的线路重启后重新上传。
请登录后再发表评论!
经常出现的Connection reset by peer: 原因可能是多方面的,不过更常见的原因是:①:服务器的并发连接数超过了其承载量,服务器会将其中一些连接Down掉;②:客户关掉了浏览器,而服务器还在给客户端发送数据;③:浏览器端按了Stop 连接被防火樯或proxy中断&或因为您有***ip分享器请将ip分享器先拿掉,直接将计算机接adsl的线路重启后重新上传。
请登录后再发表评论!c++ - Windows socket error 10013 - Stack Overflow
to customize your list.
Announcing Stack Overflow Documentation
We started with Q&A. Technical documentation is next, and we need your help.
Whether you're a beginner or an experienced developer, you can contribute.
Here is the code of program, which should send a simple 'ping'. I know that i could use IcmpSendEcho2() function, but i decide to do this this way:
struct ICMPh
unsigned short suma_
unsigned short CalcChecksum (char *pBuffer, int nLen)
////Checksum for ICMP is calculated in the same way as for IP header
//This code was taken from: /ipsum.htm
unsigned short nW
unsigned int nSum = 0;
for (i = 0; i & nL i = i + 2)
nWord =((pBuffer [i] && 8)& 0xFF00) + (pBuffer [i + 1] & 0xFF);
nSum = nSum + (unsigned int)nW
while (nSum && 16)
nSum = (nSum & 0xFFFF) + (nSum && 16);
//One's complement the result
nSum = ~nS
return ((unsigned short) nSum);
int _tmain(int argc, _TCHAR* argv[])
WSADATA wsaD
if(WSAStartup(MAKEWORD(2,2),&wsaData)==SOCKET_ERROR)
cout&&"ERROR at startup:\n";
cout&&WSAGetLastError()&&"\n";
system("pause");
WSACleanup();
return -1;
int seq=0;
soc=socket(AF_INET,SOCK_RAW,IPPROTO_ICMP);
if(soc==INVALID_SOCKET)
cout&&"ERROR: INVALID SOCKET\n";
cout&&WSAGetLastError()&&"\n";
system("pause");
WSACleanup();
return -1;
char* addres=
SOCKADDR_IN
adr.sin_addr.S_un.S_addr=inet_addr(addres);
adr.sin_family=AF_INET;
adr.sin_port=rand();
icmp.kod=0;
icmp.seq=htons(seq++);
icmp.typ=8;
icmp.suma_spr=0;
icmp.id=htons(rand());
int size=32;
buffer=new char[sizeof(ICMPh)+size];
memcpy_s(buffer,sizeof(ICMPh),&icmp,sizeof(ICMPh));
memset(buffer+sizeof(ICMPh),'x',size);
icmp.suma_spr=htons(CalcChecksum(buffer,sizeof(ICMPh)+size));
memcpy_s(buffer,sizeof(ICMPh),&icmp,sizeof(ICMPh));
if(sendto(soc,buffer,sizeof(ICMPh)+size,0,(SOCKADDR*)&adr,sizeof(SOCKADDR_IN))==SOCKET_ERROR)
cout&&"FAIL at 'sendto':\n";
cout&&WSAGetLastError()&&"\n";
system("pause");
WSACleanup();
return -1;
cout&&"FINE";
WSACleanup();
system("pause");
And here is the problem. Everything is working fine untill it comes to sendto() function. I get an 10013 Error code form WSAGetLastError() which means WSAEACCES Permission denied
I start this application witch admin privliges, so i have no idea why i cant send data using this socket configuration.
For sendto(), WSAEACCES is not related to user permissions. You would have gotten an error on socket() instead if you did not have enough rights to use a RAW socket.
When sendto() reports WSAEACCES, it means your sockaddr_in struct was not filled in correctly.
I see three bugs in your code related to that:
1) You are not zeroing out the sockaddr_in before using it.
It is important to do so.
2) You are allocating a 1-character buffer to receive the target address from the user. The buffer needs to be 16 characters instead for an IPv4 address (including the null terminator). So you have a buffer overflow.
3) You are not calling htons() when assigning the sin_port field.
227k13136260
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled&&国之画&&&&&&
&& &&&&&&&&&&&&&&&&&&
鲁ICP备号-4
打开技术之扣,分享程序人生!

参考资料

 

随机推荐