From 97f049580bfc23b4be2ca4572be6d120583fe5f4 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 21 Apr 2013 18:50:08 -0300 Subject: [PATCH] Link layer PDUs no longer contain a NetworkInterface. --- examples/arpspoofing.cpp | 23 +- examples/portscan.cpp | 4 +- include/arp.h | 14 +- include/dot11.h | 19 +- include/dot3.h | 31 +- include/ethernetII.h | 33 +- include/exceptions.h | 14 + include/ip.h | 4 +- include/ipv6.h | 2 +- include/loopback.h | 19 +- include/packet_sender.h | 20 +- include/pdu.h | 23 +- include/pdu_cacher.h | 8 +- include/radiotap.h | 22 +- src/arp.cpp | 13 +- src/dot11.cpp | 14 +- src/dot3.cpp | 28 +- src/ethernetII.cpp | 26 +- src/ip.cpp | 4 +- src/ipv6.cpp | 2 +- src/loopback.cpp | 16 +- src/packet_sender.cpp | 11 +- src/pdu.cpp | 4 +- src/radiotap.cpp | 18 +- src/utils.cpp | 8 +- tests/depends.d | 845 +++++++++++++++++++++------------------ tests/src/ethernetII.cpp | 23 +- 27 files changed, 599 insertions(+), 649 deletions(-) diff --git a/examples/arpspoofing.cpp b/examples/arpspoofing.cpp index 8677641..8c2f4f1 100644 --- a/examples/arpspoofing.cpp +++ b/examples/arpspoofing.cpp @@ -43,23 +43,18 @@ using namespace std; using namespace Tins; -int do_arp_spoofing(NetworkInterface iface, IPv4Address gw, IPv4Address victim, +void do_arp_spoofing(NetworkInterface iface, IPv4Address gw, IPv4Address victim, const NetworkInterface::Info &info) { PacketSender sender; EthernetII::address_type gw_hw, victim_hw; // Resolves gateway's hardware address. - if(!Utils::resolve_hwaddr(iface, gw, &gw_hw, sender)) { - cout << "Could not resolve gateway's ip address.\n"; - return 5; - } + gw_hw = Utils::resolve_hwaddr(iface, gw, sender); // Resolves victim's hardware address. - if(!Utils::resolve_hwaddr(iface, victim, &victim_hw, sender)) { - cout << "Could not resolve victim's ip address.\n"; - return 6; - } + victim_hw = Utils::resolve_hwaddr(iface, victim, sender); + // Print out the hw addresses we're using. cout << " Using gateway hw address: " << gw_hw << "\n"; cout << " Using victim hw address: " << victim_hw << "\n"; @@ -77,12 +72,12 @@ int do_arp_spoofing(NetworkInterface iface, IPv4Address gw, IPv4Address victim, * We include our hw address as the source address * in ethernet layer, to avoid possible packet dropping * performed by any routers. */ - EthernetII to_gw(iface, gw_hw, info.hw_addr, gw_arp); - EthernetII to_victim(iface, victim_hw, info.hw_addr, victim_arp); + EthernetII to_gw(gw_hw, info.hw_addr, gw_arp); + EthernetII to_victim(victim_hw, info.hw_addr, victim_arp); while(true) { // Just send them once every 5 seconds. - sender.send(to_gw); - sender.send(to_victim); + sender.send(to_gw, iface); + sender.send(to_victim, iface); sleep(5); } } @@ -116,7 +111,7 @@ int main(int argc, char *argv[]) { return 3; } try { - return do_arp_spoofing(iface, gw, victim, info); + do_arp_spoofing(iface, gw, victim, info); } catch(std::runtime_error &ex) { std::cout << "Runtime error: " << ex.what() << std::endl; diff --git a/examples/portscan.cpp b/examples/portscan.cpp index 4ef7478..615e5fb 100644 --- a/examples/portscan.cpp +++ b/examples/portscan.cpp @@ -97,8 +97,8 @@ void send_syns(const NetworkInterface &iface, IPv4Address dest_ip, const vector< // Pretend we're the scanned host... ip.src_addr(dest_ip); // We use an ethernet pdu, otherwise the kernel will drop it. - EthernetII eth(iface, info.hw_addr, info.hw_addr, ip.clone()); - sender.send(eth); + EthernetII eth(info.hw_addr, info.hw_addr, ip.clone()); + sender.send(eth, iface); } void *thread_proc(void *param) { diff --git a/include/arp.h b/include/arp.h index 499cd2c..44c15ec 100644 --- a/include/arp.h +++ b/include/arp.h @@ -236,34 +236,32 @@ namespace Tins { PDUType pdu_type() const { return PDU::ARP; } /** - * \brief Creates an ARP Request within a Layer 2 PDU using uint32_t for target and sender. + * \brief Creates an ARP Request within an EthernetII PDU. * * Creates an ARP Request PDU and embeds it within a Layer 2 PDU ready to be - * sent. The target and sender's protocol address are given using uint32_t. + * sent. * - * \param iface string with the interface from where to send the ARP. * \param target IPv4Address with the target's IP. * \param sender IPv4Address with the sender's IP. * \param hw_snd uint8_t array of 6 bytes containing the sender's hardware address. * \return Returns a EthernetII containing the ARP Request. */ - static EthernetII make_arp_request(const NetworkInterface& iface, ipaddress_type target, + static EthernetII make_arp_request(ipaddress_type target, ipaddress_type sender, const hwaddress_type &hw_snd = hwaddress_type()); /** - * \brief Creates an ARP Reply within a Layer 2 PDU using uint32_t for target and sender. + * \brief Creates an ARP Reply within an EthernetII PDU. * * Creates an ARP Reply PDU and embeds it within a Layer 2 PDU ready to be - * sent. The target and sender's protocol address are given using uint32_t. + * sent. * - * \param iface string with the interface from where to send the ARP. * \param target IPv4Address with the target's IP. * \param sender IPv4Address with the sender's IP. * \param hw_tgt uint8_t array of 6 bytes containing the target's hardware address. * \param hw_snd uint8_t array of 6 bytes containing the sender's hardware address. * \return Returns an EthetnetII containing the ARP Replay. */ - static EthernetII make_arp_reply(const NetworkInterface& iface, ipaddress_type target, + static EthernetII make_arp_reply(ipaddress_type target, ipaddress_type sender, const hwaddress_type &hw_tgt = hwaddress_type(), const hwaddress_type &hw_snd = hwaddress_type()); diff --git a/include/dot11.h b/include/dot11.h index 3d8a14a..8651cda 100644 --- a/include/dot11.h +++ b/include/dot11.h @@ -285,14 +285,6 @@ namespace Tins { */ address_type addr1() const { return _header.addr1; } - /** - * \brief Getter for the network interface. - * - * \return const NetworkInterface& containing the network - * interface in which this PDU will be sent. - */ - const NetworkInterface &iface() const { return _iface; } - /** * \brief Setter for the protocol version. * @@ -377,14 +369,6 @@ namespace Tins { */ void addr1(const address_type &new_addr1); - /** - * \brief Setter for the network interface. - * - * \param new_iface The network interface in which this PDU - * will be sent. - */ - void iface(const NetworkInterface &new_iface); - /* Virtual methods */ /** * \brief Returns the 802.11 frame's header length. @@ -398,7 +382,7 @@ namespace Tins { /** * \sa PDU::send() */ - void send(PacketSender &sender); + void send(PacketSender &sender, const NetworkInterface &iface); #endif // WIN32 /** @@ -520,7 +504,6 @@ namespace Tins { ieee80211_header _header; - NetworkInterface _iface; uint32_t _options_size; std::list