mfontanini / libtins

High-level, multiplatform C++ network packet sniffing and crafting library.
http://libtins.github.io/
BSD 2-Clause "Simplified" License
1.91k stars 377 forks source link

Response not beeing detected on Windows #104

Open LegITdevel opened 9 years ago

LegITdevel commented 9 years ago

Using the ARP request sample from http://libtins.github.io/tutorial/sending/

if(response) { const ARP &arp = response->rfind_pdu(); std::cout << "Hardware address: " << arp.sender_hw_addr() << std::endl; }

does not receive any response, while wireshark properly detects the correct answer from the given ip

surely c++11 is used, memory included

mfontanini commented 9 years ago

I'll have a look at this later, thanks for the report.

LegITdevel commented 9 years ago

in packet_sender.h:

ifndef _WIN32

    PDU *recv_l2(PDU &pdu, struct sockaddr *link_addr, uint32_t len_addr,
      const NetworkInterface &iface = NetworkInterface());

endif // _WIN32

mfontanini commented 9 years ago

Yes, that was my initial concern. Raw sockets on Windows have a lot of limitations, and I'm not sure if you can read ARP packets from them. This can be done using winpcap, but PacketSender doesn't use that (and for a reason, since timeouts on libpcap/winpcap work pretty badly).

LegITdevel commented 9 years ago

I didnt had the spare time to read through the complete lib, but in my view this (read any kind of packages from raw sockets) is an essential feature. Would be best if it can be patched to work without winpcap yes, but if required it should be possible to pass an argument due compilation to use winpcap for it if not possible another way.

mfontanini commented 9 years ago

The problem is that, IIRC from some stuff I worked on some time ago, the winpcap/libpcap capture timeout simply doesn't work. So if you don't receive a packet, the recv_l2 function will just hang forever.

You can always start a capture thread, send the packets, and match the responses (you can actually use PDU::matches_response, so you don't actually have to do the matching yourself), like the traceroute example does.