From 8c2b56e286f9d0b330bb6c4f2a81613508921834 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sat, 18 Apr 2015 19:37:57 -0700 Subject: [PATCH] Allow sending Dot3 on Windows using pcap_sendpacket. --- include/tins/dot3.h | 5 +++-- include/tins/ethernetII.h | 1 + src/dot3.cpp | 10 +++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/tins/dot3.h b/include/tins/dot3.h index 2947f32..4d4fa11 100644 --- a/include/tins/dot3.h +++ b/include/tins/dot3.h @@ -33,6 +33,7 @@ #include #include "macros.h" #include "pdu.h" +#include "config.h" #include "endianness.h" #include "hw_address.h" @@ -137,12 +138,12 @@ namespace Tins { */ uint32_t header_size() const; - #ifndef WIN32 + #if !defined(WIN32) || defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET) /** * \sa PDU::send() */ void send(PacketSender &sender, const NetworkInterface &iface); - #endif // WIN32 + #endif // !WIN32 || HAVE_PACKET_SENDER_PCAP_SENDPACKET /** * \brief Check wether ptr points to a valid response for this PDU. diff --git a/include/tins/ethernetII.h b/include/tins/ethernetII.h index fc2bb58..cebded6 100644 --- a/include/tins/ethernetII.h +++ b/include/tins/ethernetII.h @@ -33,6 +33,7 @@ #include #include "macros.h" #include "pdu.h" +#include "config.h" #include "endianness.h" #include "hw_address.h" diff --git a/src/dot3.cpp b/src/dot3.cpp index 9fcf4fa..bc5e1e8 100644 --- a/src/dot3.cpp +++ b/src/dot3.cpp @@ -87,12 +87,14 @@ uint32_t Dot3::header_size() const { return sizeof(ethhdr); } -#ifndef WIN32 +#if !defined(WIN32) || defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET) void Dot3::send(PacketSender &sender, const NetworkInterface &iface) { if(!iface) throw invalid_interface(); - #if !defined(BSD) && !defined(__FreeBSD_kernel__) + #if defined(BSD) || defined(__FreeBSD_kernel__) || defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET) + sender.send_l2(*this, 0, 0, iface); + #else struct sockaddr_ll addr; memset(&addr, 0, sizeof(struct sockaddr_ll)); @@ -104,11 +106,9 @@ void Dot3::send(PacketSender &sender, const NetworkInterface &iface) { memcpy(&(addr.sll_addr), _eth.dst_mac, sizeof(_eth.dst_mac)); sender.send_l2(*this, (struct sockaddr*)&addr, (uint32_t)sizeof(addr)); - #else - sender.send_l2(*this, 0, 0, iface); #endif } -#endif // WIN32 +#endif // !WIN32 || HAVE_PACKET_SENDER_PCAP_SENDPACKET bool Dot3::matches_response(const uint8_t *ptr, uint32_t total_sz) const { if(total_sz < sizeof(ethhdr))