原始套接字的问题

huangzhtao 2008-11-18 11:55:17
在Windows NT系统下创建原始套接字需要有Administrator权限,所以自己编写Ping程序运行的时候需要使用管理员权限,但是使用系统的Ping程序时却不需要使用管理员权限是怎么回事?
...全文
107 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
huangzhtao 2008-11-19
  • 打赏
  • 举报
回复
好的,谢谢了。
shadowstar 2008-11-18
  • 打赏
  • 举报
回复
// Declare and initialize variables
char[] SendData = "Data Buffer";
LPVOID ReplyBuffer;

ReplyBuffer = (VOID*) malloc(sizeof(ICMP_ECHO_REPLY) + sizeof(SendData));
if ((dwRetVal = IcmpSendEcho(hIcmpFile,
inet_addr("123.456.789.0"),
SendData, sizeof(SendData) + sizeof(ICMP_ECHO_REPLY),
NULL, ReplyBuffer,
sizeof(SendData),
1000)) != 0) {
PICMP_ECHO_REPLY pEchoReply = (PICMP_ECHO_REPLY)ReplyBuffer;
printf("\tReceived %ld messages.\n", dwRetVal);
printf("\tMessage: %s\n", pEchoReply->Data);
}
else {
printf("\tCall to IcmpSendEcho() failed.\n");
printf("\tError: %ld\n", GetLastError());
}


huangzhtao 2008-11-18
  • 打赏
  • 举报
回复
那Windows系统自带的Ping程序是怎么实现的?
shadowstar 2008-11-18
  • 打赏
  • 举报
回复
ping可以不用原始套接字

如果非要用的话

To work around this problem in Windows NT 4.0, you can disable the security check on RAW sockets by creating the following registry variable and setting its value to DWORD 1:


HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Afd\Parameters\
DisableRawSecurity


After you change the registry, you need to restart your computer.
huangzhtao 2008-11-18
  • 打赏
  • 举报
回复
有人知道吗?

1,316

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧