views:

147

answers:

2

Are there any viable alternatives to Winsock for C++? The reason I need of is because Winsock's raw sockets are not behaving properly (no, this is not fixable, don't waste your time asking) and WinPCAP can only monitor network traffic, not actually receive packets. I need something that can receive complete packets including any IP, UDP, TCP headers, etc. Does such a thing exist, and if not, why not?

+1  A: 

You could look at Boost.Asio. C++ cross-platform IO library. Support for UDP, TCP and ICMP.

Duracell
And that allows you to receive the entire packet including all headers and everything?
Chroma
Boost.Asio wraps the BSD socket library. Seeing as Winsock can do it (and Winsock is based on BSD sockets too) then Asio can do it. The basic_socket class wraps the `ioctl` function.
Duracell
Yes, boost can assure you that the entire packet is received. Look at http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/reference/async_read.html
Default
+4  A: 

WinPCAP can only monitor network traffic, not actually receive packets

Monitoring network traffic is equivalent to receiving packets. That's exactly what tools such as Wireshark do: read off your network card and reconstruct packet boundaries.

I need something that can receive complete packets including any IP, UDP, TCP headers, etc.

This is very much possible using the Winsock API. Have a look at the WSAIoctl function, specifically the SIO_RCVALL option - enabling this option will deliver ALL packets received on an interface to your socket. And these are raw IP packets starting with the IP header.

casablanca
No, monitoring traffic is not equivalent to receiving packets because when you monitor, you just observe the conversation of other programs without being able to participate. I do not want to receive all the packets on the network, I just want the ones I would normally get but I want the headers.
Chroma
Could you not then write a function that narrows all of the packets down to just the ones you want, and passes those on to the rest of your system?
Thanatos
@Chroma: Raw packets do not correspond to any application by themselves. It's the port number in the headers that directs them to the right program. So you have two choices: either get all raw packets and filter them yourself, or let the OS do this for you and lose the headers.
casablanca