Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 7 Windows 7拒绝UDP数据包_Windows 7_Udp_Raw Sockets - Fatal编程技术网

Windows 7 Windows 7拒绝UDP数据包

Windows 7 Windows 7拒绝UDP数据包,windows-7,udp,raw-sockets,Windows 7,Udp,Raw Sockets,我正在编写一个程序,可以同时发送和接收特殊的原始UDP数据包。几乎所有字段(MAC地址除外)都是我自己填写的。除此之外,我还使用了一些假IP选项,如:FE 04 01 00(我尝试了不同的),但整个IP头是正确的。下面是一个示例数据包 MAC:30 85 a9 1f b8 d6 00 25 22 62 22 07 08 00 IP标头:48 00 00 3e 03 d0 00 00 40 11 bb b7 c0 a8 89 a1 c0 a8 89 01 IP选项: fd 04 01 00

我正在编写一个程序,可以同时发送和接收特殊的原始UDP数据包。几乎所有字段(MAC地址除外)都是我自己填写的。除此之外,我还使用了一些假IP选项,如:
FE 04 01 00
(我尝试了不同的),但整个IP头是正确的。下面是一个示例数据包

  • MAC:
    30 85 a9 1f b8 d6 00 25 22 62 22 07 08 00
  • IP标头:
    48 00 00 3e 03 d0 00 00 40 11 bb b7 c0 a8 89 a1 c0 a8 89 01
    • IP选项:
      • fd 04 01 00
      • fe 08 01 11 1d 15 0a 00
  • UDP报头,有效负载:
    c3 50 c3 55 00 1e d7 ce 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 11 22 33 44 55 66 77

问题 前提条件:windows防火墙已禁用,没有其他防火墙正在运行。在Windows 7上,主机程序以“管理员身份运行”启动。 在Windows XP上,用户是管理员。

当使用Windows XP(LAN)将数据包发送到远程主机,或发送到Windows 7或Windows XP上的本地主机时,数据包将被成功接收(在远程主机或本地主机上)。但是,如果数据包通过Windows 7(LAN)发送到远程主机,则远程主机将通过ICMP消息“Parameter problem”拒绝该数据包。只有使用(例如)Wireshark:sample才能看到这一点

这里有一些关于发送的源代码

ressrc = ResolveAddress(srcAddrStr, srcPort, addressFamily, socketType, protocol);
if (ressrc == NULL) {
  // handling
}

resdest = ResolveAddress(dstAddrStr, dstPort, ressrc->ai_family, ressrc->ai_socktype, ressrc->ai_protocol);
if (resdest == NULL)  {
  // handling
}

sendSock = socket(ressrc->ai_family, socketType, ressrc->ai_protocol);
if (sendSock == INVALID_SOCKET) {
  // handling
}

int optval = 1;
rc = setsockopt(sendSock, IPPROTO_IP, IP_HDRINCL, (char *)&optval, sizeof(optval));
if (rc == SOCKET_ERROR) {
  // handling
}

// packetizing
WSABUF *wbuf = ...

rc = sendto(sendSock, wbuf[0].buf, wbuf[0].len, 0, resdest->ai_addr, resdest->ai_addrlen);
ressrc = ResolveAddress(srcAddrStr, NULL, addressFamily, socketType, protocol);
if (ressrc == NULL) {
    //handling
}

recvSock = socket(ressrc->ai_family, socketType, ressrc->ai_protocol);
if (recvSock == INVALID_SOCKET) {
    //handling
}

rc = bind(recvSock, ressrc->ai_addr, ressrc->ai_addrlen);
if (rc == SOCKET_ERROR) {
    //handling
}

while (1)
{
    fromlen = sizeof(safrom);
    rc = recvfrom(recvSock, buf, MAX_PACKET, 0, (SOCKADDR *)&safrom, &fromlen);
    if (rc == SOCKET_ERROR) {
        //handling
    }

    /*
     * handling received packet
     */
}
接收

ressrc = ResolveAddress(srcAddrStr, srcPort, addressFamily, socketType, protocol);
if (ressrc == NULL) {
  // handling
}

resdest = ResolveAddress(dstAddrStr, dstPort, ressrc->ai_family, ressrc->ai_socktype, ressrc->ai_protocol);
if (resdest == NULL)  {
  // handling
}

sendSock = socket(ressrc->ai_family, socketType, ressrc->ai_protocol);
if (sendSock == INVALID_SOCKET) {
  // handling
}

int optval = 1;
rc = setsockopt(sendSock, IPPROTO_IP, IP_HDRINCL, (char *)&optval, sizeof(optval));
if (rc == SOCKET_ERROR) {
  // handling
}

// packetizing
WSABUF *wbuf = ...

rc = sendto(sendSock, wbuf[0].buf, wbuf[0].len, 0, resdest->ai_addr, resdest->ai_addrlen);
ressrc = ResolveAddress(srcAddrStr, NULL, addressFamily, socketType, protocol);
if (ressrc == NULL) {
    //handling
}

recvSock = socket(ressrc->ai_family, socketType, ressrc->ai_protocol);
if (recvSock == INVALID_SOCKET) {
    //handling
}

rc = bind(recvSock, ressrc->ai_addr, ressrc->ai_addrlen);
if (rc == SOCKET_ERROR) {
    //handling
}

while (1)
{
    fromlen = sizeof(safrom);
    rc = recvfrom(recvSock, buf, MAX_PACKET, 0, (SOCKADDR *)&safrom, &fromlen);
    if (rc == SOCKET_ERROR) {
        //handling
    }

    /*
     * handling received packet
     */
}
我试过:

  • 比较不同主机上接收的数据包(无差异)
  • 使用
    WSAIoctl
    ioctlsocket
    函数将接收套接字置于混杂模式
  • 谷歌搜索,但我发现关于我的问题的唯一一件事是

什么会导致这个问题?我应该打开/关闭一些东西吗?还是我做错了什么?

我的猜测是,无论防火墙是打开还是关闭,Win7网络堆栈都会检测到无效数据包。“其他系统也有同样的功能。”我也这么认为,但找不到任何相关的功能。你有什么建议吗?我几个月前通过使用WinPcap接收数据包解决了这个问题。不知道是Win7的网络堆栈(@SteffenUllrich)还是别的什么。