mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Utils::resolve_hwaddr is not working.
This commit is contained in:
@@ -80,13 +80,14 @@ namespace Tins {
|
||||
|
||||
/** \brief Resolves the hardware address for a given ip.
|
||||
*
|
||||
* \param iface The interface in which the packet will be sent.
|
||||
* \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)
|
||||
* \param sender The sender to use to send and receive the ARP requests.
|
||||
* \return Returns true if the hardware address was resolved successfully,
|
||||
* false otherwise.
|
||||
*/
|
||||
bool resolve_hwaddr(uint32_t ip, uint8_t *buffer, PacketSender *sender = 0);
|
||||
bool resolve_hwaddr(const std::string &iface, uint32_t ip, uint8_t *buffer, PacketSender *sender);
|
||||
|
||||
/** \brief List all network interfaces.
|
||||
*
|
||||
|
||||
@@ -59,9 +59,9 @@ Tins::PDU* Tins::ARP::make_arp_request(const std::string& iface,
|
||||
return eth;
|
||||
}
|
||||
|
||||
Tins::PDU* Tins::ARP::make_arp_reply(const std::string& iface,
|
||||
const std::string& target,
|
||||
const std::string& sender,
|
||||
Tins::PDU* Tins::ARP::make_arp_reply(const string& iface,
|
||||
const string& target,
|
||||
const string& sender,
|
||||
const uint8_t* hw_tgt,
|
||||
const uint8_t* hw_snd) {
|
||||
|
||||
@@ -70,7 +70,7 @@ Tins::PDU* Tins::ARP::make_arp_reply(const std::string& iface,
|
||||
return make_arp_reply(iface, target_ip, sender_ip, hw_tgt, hw_snd);
|
||||
}
|
||||
|
||||
Tins::PDU* Tins::ARP::make_arp_reply(const std::string& iface,
|
||||
Tins::PDU* Tins::ARP::make_arp_reply(const string& iface,
|
||||
uint32_t target,
|
||||
uint32_t sender,
|
||||
const uint8_t* hw_tgt,
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
#include <net/if.h>
|
||||
#endif
|
||||
#include "utils.h"
|
||||
#include "pdu.h"
|
||||
#include "arp.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
@@ -155,8 +157,23 @@ uint32_t Tins::Utils::resolve_ip(const string &to_resolve) {
|
||||
return ((struct in_addr**)data->h_addr_list)[0]->s_addr;
|
||||
}
|
||||
|
||||
bool Tins::Utils::resolve_hwaddr(uint32_t ip, uint8_t *buffer, PacketSender *sender) {
|
||||
return false;
|
||||
bool Tins::Utils::resolve_hwaddr(const string &iface, uint32_t ip, uint8_t *buffer, PacketSender *sender) {
|
||||
uint32_t my_ip;
|
||||
uint8_t my_hw[6];
|
||||
if(!interface_ip(iface, my_ip) || !interface_hwaddr(iface, my_hw))
|
||||
return false;
|
||||
PDU *packet = ARP::make_arp_request(iface, ip, my_ip, my_hw);
|
||||
PDU *response = sender->send_recv(packet);
|
||||
delete packet;
|
||||
if(response) {
|
||||
ARP *arp_resp = dynamic_cast<ARP*>(response->inner_pdu());
|
||||
if(arp_resp)
|
||||
memcpy(buffer, arp_resp->sender_hw_addr(), 6);
|
||||
delete response;
|
||||
return arp_resp;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
set<string> Tins::Utils::network_interfaces() {
|
||||
@@ -179,10 +196,8 @@ bool Tins::Utils::interface_hwaddr(const string &iface, uint8_t *buffer) {
|
||||
}
|
||||
|
||||
bool Tins::Utils::interface_id(const string &iface, uint32_t &id) {
|
||||
|
||||
id = if_nametoindex(iface.c_str());
|
||||
return (((int32_t)id) != -1);
|
||||
|
||||
}
|
||||
|
||||
uint32_t Tins::Utils::crc32(uint8_t* data, uint32_t data_size) {
|
||||
|
||||
Reference in New Issue
Block a user