PC Review


Reply
Thread Tools Rate Thread

receiving the IP header with a UDP datagram

 
 
Guest
Posts: n/a
 
      14th Apr 2004
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);

 
Reply With Quote
 
 
 
 
John Phillips
Guest
Posts: n/a
 
      14th Apr 2004
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);
>



 
Reply With Quote
 
Guest
Posts: n/a
 
      16th Apr 2004
the setsockopt() didn't make a difference, nor should it
have since it only applies to outgoing packets.

Tried my code on both 2000 and XP with the same results.

I would be interested in your sample code.

>-----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);
>>

>
>
>.
>

 
Reply With Quote
 
Guest
Posts: n/a
 
      16th Apr 2004
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);
>>

>
>
>.
>

 
Reply With Quote
 
John Phillips
Guest
Posts: n/a
 
      16th Apr 2004
Ach....you're right...I was taking a look at a some code I'd written
to -=write=- raw packets. Lack of coffee, sorry.

--
John Phillips
MVP - Windows SDK



<(E-Mail Removed)> wrote in message
news:1d39201c42340$c5bfb190$(E-Mail Removed)...
> the setsockopt() didn't make a difference, nor should it
> have since it only applies to outgoing packets.
>
> Tried my code on both 2000 and XP with the same results.
>
> I would be interested in your sample code.
>
> >-----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);
> >>

> >
> >
> >.
> >



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
UdpClient Stop Receiving Broadcast Datagram On Lan When Connect to Internet greenxiar Microsoft Dot NET Framework 1 1st Apr 2007 07:09 AM
UdpClient Stop Receiving Broadcast Datagram On Lan When Connect to Internet greenxiar Microsoft Dot NET 1 1st Apr 2007 07:09 AM
Datagram supported in RC1 =?Utf-8?B?U2xvd2VyQnlUaGVNaWxl?= Windows Vista Networking 0 16th Oct 2006 10:26 AM
DHCP / Datagram Errors =?Utf-8?B?VmlwIFBhdGVs?= Microsoft Windows 2000 Networking 0 3rd May 2005 07:41 PM
UDP Datagram? Boris Mohar Anti-Virus 3 13th Jul 2004 11:59 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:08 AM.