read udp header with winsock
Are any way to get the header of a datagram with winsock? I want to get the sender ip, the size and the checksum.
Setting the IP_HDRINCL option to TRUE causes the send function to include the IP header ahead of the data it's sending and causes the receive function to include the IP header as part of the data. Thus, when you call a Winsock send function, you must include the entire IP header ahead of the data and fill each field of the IP header correctly. This option is available only on Windows 2000+.
what i reaaly want is to get the size of the udp from the header, and then read the data of the datagram when i have the size, It's possible?
I've read about raw sockets but I don't find any sample or well documented tutorial about.
I've read about raw sockets but I don't find any sample or well documented tutorial about.
This is unnecessary. All UDP datagrams arrive fully or do not arrive at all. You will never receive more than one datagram from a single call to recvfrom() -- UDP is not a streaming protocol that requires you determine the length before reading.
recvfrom() returns the number of bytes in the datagram. If the sender sent 0 bytes in the datagram message, the recvfrom() function returns 0 bytes. If 100 senders send 100 40-byte datagrams, you will have to call recvfrom() 100 times and each time the recvfrom() function will return 40 bytes.
The IP header's packet size field will ALWAYS EQUAL (minus the size of the UDP packet header) the value returned by recvfrom(). It is therefore redundant and a lot more work to try and snag it.
Robert
recvfrom() returns the number of bytes in the datagram. If the sender sent 0 bytes in the datagram message, the recvfrom() function returns 0 bytes. If 100 senders send 100 40-byte datagrams, you will have to call recvfrom() 100 times and each time the recvfrom() function will return 40 bytes.
The IP header's packet size field will ALWAYS EQUAL (minus the size of the UDP packet header) the value returned by recvfrom(). It is therefore redundant and a lot more work to try and snag it.
Robert
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement