1
votes

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?

2
I'm going to waste my time asking: Why doesn't it work for you? If you're going to claim that [product that works for everyone else] doesn't work, then you ought to spend a least a sentence or two backing it up. - Thanatos
It would take too long to explain and would lead to more questions. - Chroma
You're right - it typically leads to more questions, and most times (especially when the OP doesn't explain their situation up front) it leads to us discovering that's they not using [product that works for everyone else] correctly. Take nearly every "I think I found a bug in GCC" post, for example. Hence, I ask the time wasting question. - Thanatos
If your Winsock implementation is actually broken then I'm afraid you're pretty F'd mate. I recommended Boost.Asio, but if WS32 is really not working than anything that wraps it will be broken too. - Anthony
Actually I will try: using the different parameters to the socket function of winsock either causes my app to not receive any packets (sock_raw, ipproto_raw), causes all the sockets I have created to receive the same packet (sock_raw, ipproto_udp) or function properly but not receive headers (sock_dgram, ipproto_udp) - Chroma

2 Answers

6
votes

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.

1
votes

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