1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-27 04:11:35 +01:00

Modified PacketWriter interface to take references instead of pointers.

This commit is contained in:
Matias Fontanini
2012-09-12 23:02:53 -03:00
parent e8151724c4
commit fc0ccffe18
5 changed files with 74 additions and 10 deletions

View File

@@ -32,7 +32,6 @@
#include "utils.h"
#include "pdu.h"
#include "ip.h"
#include "icmp.h"
#include "arp.h"
#include "endianness.h"
#include "network_interface.h"
@@ -119,6 +118,20 @@ bool Utils::resolve_hwaddr(const NetworkInterface &iface, IPv4Address ip,
return false;
}
HWAddress<6> Utils::resolve_hwaddr(const NetworkInterface &iface, IPv4Address ip, PacketSender &sender)
{
IPv4Address my_ip;
NetworkInterface::Info info(iface.addresses());
std::auto_ptr<PDU> packet(ARP::make_arp_request(iface, ip, info.ip_addr, info.hw_addr));
std::auto_ptr<PDU> response(sender.send_recv(*packet));
if(response.get()) {
const ARP *arp_resp = response->find_pdu<ARP>();
if(arp_resp)
return arp_resp->sender_hw_addr();
}
throw std::runtime_error("Could not resolve hardware address");
}
bool Utils::gateway_from_ip(IPv4Address ip, IPv4Address &gw_addr) {
typedef std::vector<RouteEntry> entries_type;
entries_type entries;