After doing some more reasarch (and finding out a few
others have asked with no answers), it appears I can only
receive ALL packets hitting the network interface via
SIO_RCVALL or only certain types of ICMP messages
directed at me. I can't just open a raw socket using
IPPROTO_UDP, bind it and recieve just messages bound for
the port I am interested in.
Which means I need to have a dummy UDP socket bound to
the port I am interested in to avoid ICMP destination
port unreachable messages from being sent back from my
machine, and have my server's main loop be woken up for
EVERY SINGLE PACKET on the network or hope the server is
on a switching hub. This is a rediculous amount of time
spent in user mode, and going between user mode and
waiting on I/O.
All for what is probably a two line bug in winsuck's
source code keeping me from seeting the damn header.
This also means the Winsock Annex topic "TCP/IP Raw
Sockets" in the Plafrom SDK documentation is dead wrong:
"An application always gets the IP header at the front of
each received datagram regardless of the IP_HDRINCL
option."
>-----Original Message-----
>I can confirm that you can use raw sockets to
capture/view IP header
>information in Windows 2000. The only thing which I
think you're missing is
>to call setsockopt(...., IPPROTO_IP, IP_HDRINCL, ...);
>
>--
>John Phillips
>MVP - Windows SDK
>
>
>
><(E-Mail Removed)> wrote in message
>news:1c18401c421b4$64002ee0$(E-Mail Removed)...
>> I need to receive UDP packets with the IP header
>> information. I can see how to do this in XP, which is
>> similar to how it is done in BSD with recvmsg.
>>
>> But that mechanism is exclusive to XP/2003. How do I
do
>> this in Windows 2000? The documentation seems to imply
>> raw sockets will always give the IP header when reading
>> data, but I'm not seeing it.
>>
>> Fragements of my code:
>> s = socket (AF_INET, SOCK_RAW, IPPROTO_UDP);
>>
>> memset (&sin, 0, sizeof (sin));
>> sin.sin_family = AF_INET;
>> sin.sin_port = htons (5002);
>> sin.sin_addr.s_addr = htonl (INADDR_ANY);
>>
>> if (bind (s, (const struct sockaddr *)&sin, sizeof
>> (sin))) ...
>>
>>
>> sinlen = sizeof (sin);
>> r = recvfrom (s, buf, sizeof (buf), 0, (struct
>> sockaddr *) &sin, &sinlen);
>>
>
>
>.
>
|