无法设置IP_TTL和IP_TOS Setsockopt

时间:2013-07-09 11:08:03

标签: c++ visual-studio-2010 sockets setsockopt

我已经定义了一个UDP套接字

#include<iostream>
#include<WinSock2.h> 
sockaddr_in faraddr; 
        memset(&faraddr, 0, sizeof(sockaddr_in));
        unsigned short Port = 6789;
        faraddr.sin_family      = AF_INET;
        faraddr.sin_port        = htons(Port);
        faraddr.sin_addr.s_addr = inet_addr(Loopbackaddress);
        SOCKET XmitSocket;
        XmitSocket = socket(AF_INET, SOCK_DGRAM,IPPROTO_UDP);
          if (XmitSocket < 0)
          {
              printf("Socket Creation Failed\n");
          }
    int nBuffersize = 1024 * 1024;
    uint8 nOptVal = 255;
  setsockopt(XmitSocket,IPPROTO_IP,IP_TTL, (const char*)&nOptVal, 1); 

// 标识符IP_TTL未定义

    setsockopt(XmitSocket,SOL_SOCKET,SO_SNDBUF, (const char*)&nBuffersize, 4);

    int prio = 6 << 5;//First 3 bits of TOS field
    setsockopt(XmitSocket, SOL_IP, IP_TOS, &prio, sizeof(prio));

// 标识符SOL_IP和IP_TOS未定义

我收到编译错误我错过了一些HeaderFile

1 个答案:

答案 0 :(得分:0)

#include <Ws2tcpip.h>

好像你错过了一些头文件。有关详细信息,请参阅MSDN