我写了这样一行代码setsockopt(raw_socket,IPPROTO_IP,IP_HDRINCL ,(char *)&flag,sizeof(flag));其中bool flag=true//表示亲自对ip头进行设置,但不知道为什么在编译时通不过,提示IP_HDRINCL参数未知

解决方案 »

  1.   

    In contrast, the options at this level are defined in Ws2tcpip.h as: 
                                                          ~~~~~~~~~
    /* Option to use with [gs]etsockopt at the IPPROTO_IP level */ #define IP_OPTIONS 1 /* set/get IP options */ 
    #define IP_HDRINCL 2 /* header is included with data */ 
    #define IP_TOS 3 /* IP type of service and preced*/ 
    #define IP_TTL 4 /* IP time to live */ 
    #define IP_MULTICAST_IF 9 /* set/get IP multicast i/f  */ 
    #define IP_MULTICAST_TTL       10 /* set/get IP multicast ttl */ 
    #define IP_MULTICAST_LOOP      11 /*set/get IP multicast loopback */ 
    #define IP_ADD_MEMBERSHIP      12 /* add an IP group membership */ 
    #define IP_DROP_MEMBERSHIP     13/* drop an IP group membership */ 
    #define IP_DONTFRAGMENT     14 /* don't fragment IP datagrams */ 
      

  2.   

    setsockopt
    The setsockopt function sets a socket option.int setsockopt(
      SOCKET s,
      int level,
      int optname,
      const char* optval,
      int optlen
    );Parameters

    [in] Descriptor identifying a socket. 
    level 
    [in] Level at which the option is defined. Example: SOL_SOCKET. 
    optname 
    [in] Socket option for which the value is to be set. Example: SO_BROADCAST. The optname value must be a socket option defined within the specified level, or behavior is undefined. 
    optval 
    [in] Pointer to the buffer in which the value for the requested option is specified. 
    optlen 
    [in] Size of the optval buffer, in bytes. 
    Return Values
    If no error occurs, setsockopt returns zero. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.Error code Meaning 
    WSANOTINITIALISED A successful WSAStartup call must occur before using this function. 
    WSAENETDOWN The network subsystem has failed. 
    WSAEFAULT optval is not in a valid part of the process address space or optlen parameter is too small. 
    WSAEINPROGRESS A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function. 
    WSAEINVAL level is not valid, or the information in optval is not valid. 
    WSAENETRESET Connection has timed out when SO_KEEPALIVE is set. 
    WSAENOPROTOOPT The option is unknown or unsupported for the specified provider or socket (see SO_GROUP_PRIORITY limitations). 
    WSAENOTCONN Connection has been reset when SO_KEEPALIVE is set. 
    WSAENOTSOCK The descriptor is not a socket. 
      

  3.   

    The setsockopt function sets the current value for a socket option associated with a socket of any type, in any state. Although options can exist at multiple protocol levels, they are always present at the uppermost socket level. Options affect socket operations, such as whether expedited data (OOB data for example) is received in the normal data stream, and whether broadcast messages can be sent on the socket.Note  If the setsockopt function is called before the bind function, TCP/IP options will not be checked with TCP/IP until the bind occurs. In this case, the setsockopt function call will always succeed, but the bind function call may fail because of an early setsockopt failing.Note  If a socket is opened, a setsockopt call is made, and then a sendto call is made, Windows Sockets performs an implicit bind function call.There are two types of socket options: Boolean options that enable or disable a feature or behavior, and options that require an integer value or structure. To enable a Boolean option, optval points to a nonzero integer. To disable the option optval points to an integer equal to zero. The optlen parameter should be equal to sizeof(int) for Boolean options. For other options, optval points to the an integer or structure that contains the desired value for the option, and optlen is the length of the integer or structure.The following options are supported for setsockopt. For default values of these options, see the description. The Type identifies the type of data addressed by optval.