无法在Windows 7上使用管理员帐户创建原始套接字

时间:2016-02-12 01:13:25

标签: c windows sockets raw-sockets

根据this page,如果帐户具有管理权限,则允许在Windows 7下创建原始套接字。我的本地帐户是管理员,但它仍然不允许我创建套接字。

如果我这样做:

#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>
#include <ws2tcpip.h>

void sockerr(char *message)
{
        char errbuf[300];
        FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, WSAGetLastError(),
                      0, errbuf, sizeof(errbuf), NULL);
        printf("%s: (%d) %s", message, WSAGetLastError(), errbuf);
}

int main()
{
    int sock;
    struct sockaddr_in sin;
    struct WSAData data;

    if (WSAStartup(2, &data)) {
        fprintf(stderr, "Error in WSAStartup: %d\n", WSAGetLastError());
        exit(1);
    }

    sock = socket(AF_INET, SOCK_RAW, IPPROTO_IGMP);
    if (sock == -1) {
        sockerr("socket failed");
        exit(1);
    }
    printf("opened raw socket\n");
    closesocket(sock);
    return 0;    
}

我明白了:

  

套接字失败:(10013)尝试以某种方式访问​​套接字   被访问权限禁止。

但我是管理员:

user account

这是在我的家用台式机上使用Windows 7 Pro。我安装了McAfee Antivirus Plus,但禁用它无效。

此程序在我的Windows 7 Enterprise笔记本电脑上运行良好。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

不确定为什么要使用原始套接字,但似乎解决方案是使用winpcap如果您使用谷歌,您可以找到使用它的示例。 以下是一个示例:http://www.binarytides.com/raw-sockets-packets-with-winpcap/

在尝试此操作之前,我还要确保程序以管理员身份运行。也许你是一个管理员,但该程序没有运行该权限。