mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Added a default interface to PacketSender.
This commit is contained in:
2
Doxyfile
2
Doxyfile
@@ -38,7 +38,7 @@ PROJECT_NUMBER = 0.3
|
||||
# If a relative path is entered, it will be relative to the location
|
||||
# where doxygen was started. If left blank the current directory will be used.
|
||||
|
||||
OUTPUT_DIRECTORY = docs/
|
||||
OUTPUT_DIRECTORY = ../docs/
|
||||
|
||||
# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create
|
||||
# 4096 sub-directories (in 2 levels) under the output directory of each output
|
||||
|
||||
@@ -77,7 +77,8 @@ namespace Tins {
|
||||
*
|
||||
* \param recv_timeout The timeout which will be used when receiving responses.
|
||||
*/
|
||||
PacketSender(uint32_t recv_timeout = DEFAULT_TIMEOUT, uint32_t usec = 0);
|
||||
PacketSender(const NetworkInterface &iface = NetworkInterface(),
|
||||
uint32_t recv_timeout = DEFAULT_TIMEOUT, uint32_t usec = 0);
|
||||
|
||||
/**
|
||||
* \brief PacketSender destructor.
|
||||
@@ -121,6 +122,21 @@ namespace Tins {
|
||||
*/
|
||||
void close_socket(SocketType type, const NetworkInterface &iface = NetworkInterface());
|
||||
|
||||
/**
|
||||
* \brief Sets the default interface.
|
||||
*
|
||||
* The interface will be used whenever PacketSender::send(PDU&)
|
||||
* is called.
|
||||
*/
|
||||
void default_interface(const NetworkInterface &iface);
|
||||
|
||||
/**
|
||||
* \brief Gets the default interface.
|
||||
*
|
||||
* \sa PacketSender::default_interface
|
||||
*/
|
||||
const NetworkInterface& default_interface();
|
||||
|
||||
/**
|
||||
* \brief Sends a PDU.
|
||||
*
|
||||
@@ -129,6 +145,11 @@ namespace Tins {
|
||||
*
|
||||
* If any send error occurs, then a SocketWriteError is thrown.
|
||||
*
|
||||
* If the PDU contains a link layer protocol, then default_interface
|
||||
* is used.
|
||||
*
|
||||
* \sa PacketSender::default_interface
|
||||
*
|
||||
* \param pdu The PDU to be sent.
|
||||
*/
|
||||
void send(PDU &pdu);
|
||||
@@ -266,6 +287,7 @@ namespace Tins {
|
||||
#endif
|
||||
SocketTypeMap _types;
|
||||
uint32_t _timeout, _timeout_usec;
|
||||
NetworkInterface default_iface;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace Tins {
|
||||
|
||||
/**
|
||||
* \brief Creates an instance of RadioTap.
|
||||
* \param child The child PDU.(optional)
|
||||
* \param child The child PDU.
|
||||
*/
|
||||
RadioTap(PDU *child = 0);
|
||||
|
||||
|
||||
@@ -83,13 +83,13 @@ const uint32_t PacketSender::DEFAULT_TIMEOUT = 2;
|
||||
}
|
||||
#endif
|
||||
|
||||
PacketSender::PacketSender(uint32_t recv_timeout, uint32_t usec)
|
||||
PacketSender::PacketSender(const NetworkInterface &iface, uint32_t recv_timeout,
|
||||
uint32_t usec)
|
||||
: _sockets(SOCKETS_END, INVALID_RAW_SOCKET),
|
||||
#if !defined(BSD) && !defined(WIN32)
|
||||
_ether_socket(INVALID_RAW_SOCKET),
|
||||
#endif
|
||||
_timeout(recv_timeout),
|
||||
_timeout_usec(usec)
|
||||
_timeout(recv_timeout), _timeout_usec(usec), default_iface(iface)
|
||||
{
|
||||
_types[IP_TCP_SOCKET] = IPPROTO_TCP;
|
||||
_types[IP_UDP_SOCKET] = IPPROTO_UDP;
|
||||
@@ -116,6 +116,14 @@ PacketSender::~PacketSender() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void PacketSender::default_interface(const NetworkInterface &iface) {
|
||||
default_iface = iface;
|
||||
}
|
||||
|
||||
const NetworkInterface& PacketSender::default_interface() {
|
||||
return default_iface;
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
bool PacketSender::ether_socket_initialized(const NetworkInterface& iface) const {
|
||||
#ifdef BSD
|
||||
@@ -219,7 +227,7 @@ void PacketSender::close_socket(SocketType type, const NetworkInterface &iface)
|
||||
}
|
||||
|
||||
void PacketSender::send(PDU &pdu) {
|
||||
pdu.send(*this, NetworkInterface());
|
||||
pdu.send(*this, default_iface);
|
||||
}
|
||||
|
||||
void PacketSender::send(PDU &pdu, const NetworkInterface &iface) {
|
||||
|
||||
Reference in New Issue
Block a user