mirror of
https://github.com/mfontanini/libtins
synced 2026-01-29 21:14:28 +01:00
Documented PacketSender. Added Utils::resolve_hwaddr, it's not working yet.
This commit is contained in:
@@ -46,6 +46,8 @@ namespace Tins {
|
||||
public:
|
||||
static const uint32_t DEFAULT_TIMEOUT;
|
||||
|
||||
/** \brief Flags to indicate the socket type.
|
||||
*/
|
||||
enum SocketType {
|
||||
ETHER_SOCKET,
|
||||
IP_SOCKET,
|
||||
@@ -56,30 +58,105 @@ namespace Tins {
|
||||
|
||||
/**
|
||||
* \brief Constructor for PacketSender objects.
|
||||
*
|
||||
* \param recv_timeout The timeout which will be used when receiving responses.
|
||||
*/
|
||||
PacketSender(uint32_t recv_timeout = DEFAULT_TIMEOUT);
|
||||
|
||||
~PacketSender();
|
||||
|
||||
/**
|
||||
* \brief
|
||||
*
|
||||
/** \brief Opens a layer y socket.
|
||||
*
|
||||
* \return Returns true if the socket was open successfully, false otherwise.
|
||||
*/
|
||||
bool open_l2_socket();
|
||||
|
||||
/** \brief Opens a layer 3 socket, using the corresponding protocol
|
||||
* for the given flag.
|
||||
*
|
||||
* \param type The type of socket which will be used to pick the protocol flag
|
||||
* for this socket.
|
||||
* \return Returns true if the socket was open successfully, false otherwise.
|
||||
*/
|
||||
bool open_l3_socket(SocketType type);
|
||||
|
||||
/** \brief Closes the socket associated with the given flag.
|
||||
*
|
||||
* \param flag
|
||||
* \return Returns true if the socket was closed successfully, false otherwise.
|
||||
*/
|
||||
bool close_socket(uint32_t flag);
|
||||
|
||||
/** \brief Sends a PDU.
|
||||
*
|
||||
* This method is used to send PDUs. It opens the required socket(if it's not open yet).
|
||||
*
|
||||
* \param pdu The PDU to send.
|
||||
* \return Returns true if the PDU is sent successfully, false otherwise.
|
||||
*/
|
||||
bool send(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.
|
||||
* \return Returns the response PDU, 0 if not response was received.
|
||||
*/
|
||||
PDU *send_recv(PDU *pdu);
|
||||
|
||||
PDU *recv_l2(PDU *pdu, struct sockaddr *link_addr, uint32_t len_link_addr);
|
||||
/** \brief Receives a layer 2 PDU response to a previously sent PDU.
|
||||
*
|
||||
* This PacketSender will receive data from a raw socket, open using the corresponding flag,
|
||||
* according to the given type of protocol, until a match for the given PDU is received.
|
||||
*
|
||||
* \param pdu The PDU which will try to match the responses.
|
||||
* \param link_addr The sockaddr struct which will be used to receive the PDU.
|
||||
* \param len_addr The sockaddr struct length.
|
||||
* \return Returns the response PDU. If no response is received, then 0 is returned.
|
||||
*/
|
||||
PDU *recv_l2(PDU *pdu, struct sockaddr *link_addr, uint32_t len_addr);
|
||||
|
||||
bool send_l2(PDU *pdu, struct sockaddr* link_addr, uint32_t len_link_addr);
|
||||
/** \brief Sends a level 2 PDU.
|
||||
*
|
||||
* This method sends a layer 2 PDU, using a raw socket, open using the corresponding flag,
|
||||
* according to the given type of protocol.
|
||||
*
|
||||
* \param pdu The PDU to send.
|
||||
* \param link_addr The sockaddr struct which will be used to send the PDU.
|
||||
* \param len_addr The sockaddr struct length.
|
||||
* \return Returns true if the PDU was successfully sent, false otherwise.
|
||||
*/
|
||||
bool send_l2(PDU *pdu, struct sockaddr* link_addr, uint32_t len_addr);
|
||||
|
||||
PDU *recv_l3(PDU *pdu, struct sockaddr *link_addr, uint32_t len_link_addr, SocketType type);
|
||||
/** \brief Receives a layer 3 PDU response to a previously sent PDU.
|
||||
*
|
||||
* This PacketSender will receive data from a raw socket, open using the corresponding flag,
|
||||
* according to the given type of protocol, until a match for the given PDU is received.
|
||||
*
|
||||
* \param pdu The PDU which will try to match the responses.
|
||||
* \param link_addr The sockaddr struct which will be used to receive the PDU.
|
||||
* \param len_addr The sockaddr struct length.
|
||||
* \param type The socket protocol type.
|
||||
* \return Returns the response PDU. If no response is received, then 0 is returned.
|
||||
*/
|
||||
PDU *recv_l3(PDU *pdu, struct sockaddr *link_addr, uint32_t len_addr, SocketType type);
|
||||
|
||||
bool send_l3(PDU *pdu, struct sockaddr *link_addr, uint32_t len_link_addr, SocketType type);
|
||||
/** \brief Sends a level 3 PDU.
|
||||
*
|
||||
* This method sends a layer 3 PDU, using a raw socket, open using the corresponding flag,
|
||||
* according to the given type of protocol.
|
||||
*
|
||||
* \param pdu The PDU to send.
|
||||
* \param link_addr The sockaddr struct which will be used to send the PDU.
|
||||
* \param len_addr The sockaddr struct length.
|
||||
* \param type The socket protocol type.
|
||||
* \return Returns true if the PDU was successfully sent, false otherwise.
|
||||
*/
|
||||
bool send_l3(PDU *pdu, struct sockaddr *link_addr, uint32_t len_addr, SocketType type);
|
||||
private:
|
||||
static const int INVALID_RAW_SOCKET;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user