Generally speaking, the custom IP header is realized by using the option IP_HDRINCL of the library function setsockopt () of socket, although it is easy to realize on unix and linux platforms. Unfortunately, in Winsock 1. 1 and Winsock2.0 libraries of Windows platform, setsockopt () does not support the IP_HDRINCL option, so in Windows 9x/NT, it is impossible to customize the IP header through Winsock library, but of course it can be realized by writing a virtual device driver. More complicated, however, the emergence of Windows2000 has broken this situation. The Winsock2.2 library of Windows 2000 fully supports the option IP_HDRINCL of setsockopt (), which is convenient for us to realize custom IP headers. The implementation method is as follows:
Socket s;
BOOL bopt
s=WSASocket(AF_INET,SOCK_RAW,IPPROTO_UDP,NULL,0,WSA _ FLAG _ OVERLAPPED);
ret = setsockopt(s,IPPROTO_IP,IP_HDRINCL,(char *)bopt,sizeof(bopt);