1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-29 04:54:28 +01:00

Documented PacketSender. Added Utils::resolve_hwaddr, it's not working yet.

This commit is contained in:
Matias Fontanini
2011-08-16 13:48:49 -03:00
parent 7bf8bd6ee7
commit 0989027f3d
4 changed files with 114 additions and 21 deletions

View File

@@ -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;

View File

@@ -77,6 +77,16 @@ namespace Tins {
*/
uint32_t resolve_ip(const std::string &to_resolve);
/** \brief Resolves the hardware address for a given ip.
*
* \param ip The ip to resolve, in integer format.
* \param buffer The buffer in which the host's hardware address will be stored.
* \param sender The sender to use to send and receive the ARP requests.(optional)
* \return Returns true if the hardware address was resolved successfully,
* false otherwise.
*/
bool resolve_hwaddr(uint32_t ip, uint8_t *buffer, PacketSender *sender = 0);
/** \brief List all network interfaces.
*
* Returns a set of strings, each of them representing the name