mirror of
https://github.com/mfontanini/libtins
synced 2026-01-28 12:44:25 +01:00
Link layer PDUs no longer contain a NetworkInterface.
This commit is contained in:
@@ -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());
|
||||
|
||||
|
||||
@@ -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<option> _options;
|
||||
};
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
#include "pdu.h"
|
||||
#include "endianness.h"
|
||||
#include "hw_address.h"
|
||||
#include "network_interface.h"
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -65,15 +64,13 @@ namespace Tins {
|
||||
* Constructor that builds an Dot3 PDU taking the interface name,
|
||||
* destination's and source's MAC.
|
||||
*
|
||||
* \param iface string containing the interface's name from where to send the packet.
|
||||
* \param dst_hw_addr The destination hardware address.
|
||||
* \param src_hw_addr The source hardware address.
|
||||
* \param child The PDU which will be set as the inner PDU.
|
||||
*/
|
||||
Dot3(const NetworkInterface& iface = NetworkInterface(),
|
||||
const address_type &dst_hw_addr = address_type(),
|
||||
const address_type &src_hw_addr = address_type(),
|
||||
PDU* child = 0);
|
||||
Dot3(const address_type &dst_hw_addr = address_type(),
|
||||
const address_type &src_hw_addr = address_type(),
|
||||
PDU* child = 0);
|
||||
|
||||
/**
|
||||
* \brief Constructs a Dot3 object from a buffer and adds a
|
||||
@@ -102,13 +99,6 @@ namespace Tins {
|
||||
*/
|
||||
address_type src_addr() const { return _eth.src_mac; }
|
||||
|
||||
/**
|
||||
* \brief Getter for the interface.
|
||||
*
|
||||
* \return The network interface.
|
||||
*/
|
||||
const NetworkInterface &iface() const { return this->_iface; }
|
||||
|
||||
/**
|
||||
* \brief Getter for the length field.
|
||||
* \return The length field value.
|
||||
@@ -131,13 +121,6 @@ namespace Tins {
|
||||
*/
|
||||
void src_addr(const address_type &new_src_mac);
|
||||
|
||||
/**
|
||||
* \brief Setter for the interface.
|
||||
*
|
||||
* \param new_iface The interface in which to send this PDU.
|
||||
*/
|
||||
void iface(const NetworkInterface &new_iface);
|
||||
|
||||
/**
|
||||
* \brief Setter for the length field.
|
||||
*
|
||||
@@ -158,7 +141,7 @@ namespace Tins {
|
||||
/**
|
||||
* \sa PDU::send()
|
||||
*/
|
||||
void send(PacketSender &sender);
|
||||
void send(PacketSender &sender, const NetworkInterface &iface);
|
||||
#endif // WIN32
|
||||
|
||||
/**
|
||||
@@ -172,12 +155,9 @@ namespace Tins {
|
||||
|
||||
#ifndef WIN32
|
||||
/**
|
||||
* \brief Receives a matching response for this packet.
|
||||
*
|
||||
* \sa PDU::recv_response
|
||||
* \param sender The packet sender which will receive the packet.
|
||||
*/
|
||||
PDU *recv_response(PacketSender &sender);
|
||||
PDU *recv_response(PacketSender &sender, const NetworkInterface &iface);
|
||||
#endif // WIN32
|
||||
|
||||
/**
|
||||
@@ -220,7 +200,6 @@ namespace Tins {
|
||||
|
||||
|
||||
ethhdr _eth;
|
||||
NetworkInterface _iface;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
#include "pdu.h"
|
||||
#include "endianness.h"
|
||||
#include "hw_address.h"
|
||||
#include "network_interface.h"
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -60,18 +59,13 @@ namespace Tins {
|
||||
static const address_type BROADCAST;
|
||||
|
||||
/**
|
||||
* \brief Constructor for creating an ethernet PDU
|
||||
* \brief Constructs an ethernet II PDU.
|
||||
*
|
||||
* Constructor that builds an ethernet PDU taking the interface name,
|
||||
* destination's and source's MAC.
|
||||
*
|
||||
* \param iface string containing the interface's name from where to send the packet.
|
||||
* \param dst_hw_addr address_type containing the destination's MAC(optional).
|
||||
* \param src_hw_addr address_type containing the source's MAC(optional).
|
||||
* \param child PDU* with the PDU contained by the ethernet PDU (optional).
|
||||
*/
|
||||
EthernetII(const NetworkInterface& iface = NetworkInterface(),
|
||||
const address_type &dst_hw_addr = address_type(),
|
||||
EthernetII(const address_type &dst_hw_addr = address_type(),
|
||||
const address_type &src_hw_addr = address_type(),
|
||||
PDU* child = 0);
|
||||
|
||||
@@ -106,13 +100,6 @@ namespace Tins {
|
||||
*/
|
||||
address_type src_addr() const { return _eth.src_mac; }
|
||||
|
||||
/**
|
||||
* \brief Getter for the interface.
|
||||
*
|
||||
* \return Returns the interface in which this PDU will be sent.
|
||||
*/
|
||||
const NetworkInterface &iface() const { return _iface; }
|
||||
|
||||
/**
|
||||
* \brief Getter for the payload_type
|
||||
* \return The payload type.
|
||||
@@ -135,13 +122,6 @@ namespace Tins {
|
||||
*/
|
||||
void src_addr(const address_type &new_src_addr);
|
||||
|
||||
/**
|
||||
* \brief Setter for the interface.
|
||||
*
|
||||
* \param new_iface the interface to be set.
|
||||
*/
|
||||
void iface(const NetworkInterface& new_iface);
|
||||
|
||||
/**
|
||||
* \brief Setter for the payload type.
|
||||
*
|
||||
@@ -163,7 +143,7 @@ namespace Tins {
|
||||
/**
|
||||
* \sa PDU::send()
|
||||
*/
|
||||
void send(PacketSender &sender);
|
||||
void send(PacketSender &sender, const NetworkInterface &iface);
|
||||
#endif // WIN32
|
||||
|
||||
/**
|
||||
@@ -176,12 +156,12 @@ namespace Tins {
|
||||
bool matches_response(uint8_t *ptr, uint32_t total_sz);
|
||||
|
||||
#ifndef WIN32
|
||||
/** \brief Receives a matching response for this packet.
|
||||
/**
|
||||
* \brief Receives a matching response for this packet.
|
||||
*
|
||||
* \sa PDU::recv_response
|
||||
* \param sender The packet sender which will receive the packet.
|
||||
*/
|
||||
PDU *recv_response(PacketSender &sender);
|
||||
PDU *recv_response(PacketSender &sender, const NetworkInterface &iface);
|
||||
#endif // WIN32
|
||||
|
||||
/**
|
||||
@@ -223,7 +203,6 @@ namespace Tins {
|
||||
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
|
||||
|
||||
ethhdr _eth;
|
||||
NetworkInterface _iface;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -72,6 +72,20 @@ public:
|
||||
return "PDU not found";
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Exception thrown when PDU::send requires a valid interface,
|
||||
* but an invalid is used.
|
||||
*/
|
||||
class invalid_interface : public std::runtime_error {
|
||||
public:
|
||||
invalid_interface()
|
||||
: std::runtime_error(std::string()) { }
|
||||
|
||||
const char* what() const throw() {
|
||||
return "Invalid interface";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // TINS_EXCEPTIONS_H
|
||||
|
||||
@@ -572,7 +572,7 @@ namespace Tins {
|
||||
/**
|
||||
* \sa PDU::send()
|
||||
*/
|
||||
void send(PacketSender &sender);
|
||||
void send(PacketSender &sender, const NetworkInterface &);
|
||||
|
||||
/**
|
||||
* \brief Check wether ptr points to a valid response for this PDU.
|
||||
@@ -589,7 +589,7 @@ namespace Tins {
|
||||
* \sa PDU::recv_response
|
||||
* \param sender The packet sender which will receive the packet.
|
||||
*/
|
||||
PDU *recv_response(PacketSender &sender);
|
||||
PDU *recv_response(PacketSender &sender, const NetworkInterface &);
|
||||
|
||||
/**
|
||||
* \brief Getter for the PDU's type.
|
||||
|
||||
@@ -276,7 +276,7 @@ public:
|
||||
/**
|
||||
* \sa PDU::send()
|
||||
*/
|
||||
void send(PacketSender &sender);
|
||||
void send(PacketSender &sender, const NetworkInterface &);
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
|
||||
#include "pdu.h"
|
||||
#include "macros.h"
|
||||
#include "network_interface.h"
|
||||
|
||||
namespace Tins {
|
||||
class Loopback : public PDU {
|
||||
@@ -55,10 +54,9 @@ public:
|
||||
* The NetworkInterface object will only be used in *BSD, where
|
||||
* Null/Loopback PDUs can actually be sent.
|
||||
*
|
||||
* \param iface The network interface in which to send this PDU.
|
||||
* \param inner_pdu The inner pdu to be set.
|
||||
*/
|
||||
Loopback(const NetworkInterface &iface, PDU *inner_pdu = 0);
|
||||
Loopback(PDU *inner_pdu = 0);
|
||||
|
||||
/**
|
||||
* \brief Construct a Loopback object from a buffer and adds
|
||||
@@ -98,18 +96,6 @@ public:
|
||||
*/
|
||||
PDUType pdu_type() const { return PDU::IP; }
|
||||
|
||||
/**
|
||||
* \brief Getter for the interface member.
|
||||
*/
|
||||
const NetworkInterface &iface() const { return _iface; }
|
||||
|
||||
/**
|
||||
* \brief Setter for the interface member.
|
||||
*
|
||||
* \param new_iface The new interface to be set.
|
||||
*/
|
||||
void iface(const NetworkInterface &new_iface);
|
||||
|
||||
/**
|
||||
* \sa PDU::clone
|
||||
*/
|
||||
@@ -121,13 +107,12 @@ public:
|
||||
/**
|
||||
* \sa PDU::send()
|
||||
*/
|
||||
void send(PacketSender &sender);
|
||||
void send(PacketSender &sender, const NetworkInterface &iface);
|
||||
#endif // BSD
|
||||
private:
|
||||
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
|
||||
|
||||
uint32_t _family;
|
||||
NetworkInterface _iface;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -162,6 +162,20 @@ namespace Tins {
|
||||
* \return Returns the response PDU, 0 if not response was received.
|
||||
*/
|
||||
PDU *send_recv(PDU &pdu);
|
||||
|
||||
/**
|
||||
* \brief Sends a PDU and waits for its response.
|
||||
*
|
||||
* This method is used to send PDUs and receive their response.
|
||||
* It opens the required socket(if it's not open yet). This can be used
|
||||
* to expect responses for ICMP, ARP, and such packets that are normally
|
||||
* answered by the host that receives the packet.
|
||||
*
|
||||
* \param pdu The PDU to send.
|
||||
* \param iface The network interface in which to send and receive.
|
||||
* \return Returns the response PDU, 0 if not response was received.
|
||||
*/
|
||||
PDU *send_recv(PDU &pdu, const NetworkInterface &iface);
|
||||
|
||||
#ifndef WIN32
|
||||
/**
|
||||
@@ -236,11 +250,7 @@ namespace Tins {
|
||||
#endif
|
||||
template<typename T>
|
||||
void send(PDU &pdu, const NetworkInterface &iface) {
|
||||
T *actual_pdu = static_cast<T*>(&pdu);
|
||||
NetworkInterface old_iface = actual_pdu->iface();
|
||||
actual_pdu->iface(iface);
|
||||
send(*actual_pdu);
|
||||
actual_pdu->iface(old_iface);
|
||||
static_cast<T&>(pdu).send(*this, iface);
|
||||
}
|
||||
|
||||
PDU *recv_match_loop(int sock, PDU &pdu, struct sockaddr* link_addr, uint32_t addrlen);
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
namespace Tins {
|
||||
|
||||
class PacketSender;
|
||||
class NetworkInterface;
|
||||
|
||||
/**
|
||||
* The type used to store several PDU option values.
|
||||
@@ -286,25 +287,37 @@ namespace Tins {
|
||||
*/
|
||||
virtual PDU *clone() const = 0;
|
||||
|
||||
/** \brief Send the stack of PDUs through a PacketSender.
|
||||
/**
|
||||
* \brief Send the stack of PDUs through a PacketSender.
|
||||
*
|
||||
* This method will be called only for the PDU on the bottom of the stack,
|
||||
* therefore it should only implement this method if it can be sent.
|
||||
*
|
||||
* PacketSender implements specific methods to send packets which start
|
||||
* on every valid TCP/IP stack layer; this should only be a proxy for
|
||||
* those methods.
|
||||
*
|
||||
* If this PDU does not represent a link layer protocol, then
|
||||
* the interface argument will be ignored.
|
||||
*
|
||||
* \param sender The PacketSender which will send the packet.
|
||||
* \param iface The network interface in which this packet will
|
||||
* be sent.
|
||||
*/
|
||||
virtual void send(PacketSender &sender);
|
||||
virtual void send(PacketSender &sender, const NetworkInterface &iface);
|
||||
|
||||
/** \brief Receives a matching response for this packet.
|
||||
/**
|
||||
* \brief Receives a matching response for this packet.
|
||||
*
|
||||
* This method should act as a proxy for PacketSender::recv_lX methods.
|
||||
*
|
||||
* \param sender The packet sender which will receive the packet.
|
||||
* \param iface The interface in which to expect the response.
|
||||
*/
|
||||
virtual PDU *recv_response(PacketSender &sender);
|
||||
virtual PDU *recv_response(PacketSender &sender, const NetworkInterface &iface);
|
||||
|
||||
/** \brief Check wether ptr points to a valid response for this PDU.
|
||||
/**
|
||||
* \brief Check wether ptr points to a valid response for this PDU.
|
||||
*
|
||||
* This method must check wether the buffer pointed by ptr is a valid
|
||||
* response for this PDU. If it is valid, then it might want to propagate
|
||||
|
||||
@@ -95,15 +95,15 @@ public:
|
||||
/**
|
||||
* Forwards the call to the cached PDU. \sa PDU::send.
|
||||
*/
|
||||
void send(PacketSender &sender) {
|
||||
cached.send(sender);
|
||||
void send(PacketSender &sender, const NetworkInterface &iface) {
|
||||
cached.send(sender, iface);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forwards the call to the cached PDU. \sa PDU::recv_responde.
|
||||
*/
|
||||
PDU *recv_response(PacketSender &sender) {
|
||||
return cached.recv_response(sender);
|
||||
PDU *recv_response(PacketSender &sender, const NetworkInterface &iface) {
|
||||
return cached.recv_response(sender, iface);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#include "macros.h"
|
||||
#include "pdu.h"
|
||||
#include "endianness.h"
|
||||
#include "network_interface.h"
|
||||
|
||||
namespace Tins {
|
||||
class PacketSender;
|
||||
@@ -109,11 +108,9 @@ namespace Tins {
|
||||
|
||||
/**
|
||||
* \brief Creates an instance of RadioTap.
|
||||
* \param iface The interface in which to send this PDU.
|
||||
* \param child The child PDU.(optional)
|
||||
*/
|
||||
RadioTap(const NetworkInterface &iface = NetworkInterface(),
|
||||
PDU *child = 0);
|
||||
RadioTap(PDU *child = 0);
|
||||
|
||||
/**
|
||||
* \brief Constructs a RadioTap object from a buffer and adds all
|
||||
@@ -133,7 +130,7 @@ namespace Tins {
|
||||
/**
|
||||
* \sa PDU::send()
|
||||
*/
|
||||
void send(PacketSender &sender);
|
||||
void send(PacketSender &sender, const NetworkInterface &iface);
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -203,13 +200,6 @@ namespace Tins {
|
||||
*/
|
||||
void rx_flags(uint16_t new_rx_flag);
|
||||
|
||||
/**
|
||||
* \brief Setter for the interface.
|
||||
*
|
||||
* \param new_iface the interface to be set.
|
||||
*/
|
||||
void iface(const NetworkInterface& new_iface);
|
||||
|
||||
/* Getters */
|
||||
|
||||
/**
|
||||
@@ -303,13 +293,6 @@ namespace Tins {
|
||||
return (PresentFlags)*(uint32_t*)(&_radio.it_len + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Getter for the interface.
|
||||
*
|
||||
* \return Returns the interface in which this PDU will be sent.
|
||||
*/
|
||||
const NetworkInterface &iface() const { return _iface; }
|
||||
|
||||
/** \brief Check wether ptr points to a valid response for this PDU.
|
||||
*
|
||||
* \sa PDU::matches_response
|
||||
@@ -403,7 +386,6 @@ namespace Tins {
|
||||
|
||||
|
||||
radiotap_hdr _radio;
|
||||
NetworkInterface _iface;
|
||||
// present fields...
|
||||
uint64_t _tsft;
|
||||
uint32_t _channel_type;
|
||||
|
||||
Reference in New Issue
Block a user