join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
arp.hpp
Go to the documentation of this file.
1
25#ifndef __JOIN_ARP_HPP__
26#define __JOIN_ARP_HPP__
27
28// libjoin.
29#include <join/macaddress.hpp>
30
31// C++.
32#include <string>
33
34// C.
35#include <linux/if_arp.h>
36
37namespace join
38{
42 class Arp
43 {
44 public:
48 Arp () = delete;
49
54 Arp (const std::string& interface);
55
59 virtual ~Arp () = default;
60
66 MacAddress get (const IpAddress& ip);
67
74 static MacAddress get (const IpAddress& ip, const std::string& interface);
75
81 MacAddress request (const IpAddress& ip);
82
89 static MacAddress request (const IpAddress& ip, const std::string& interface);
90
97 int add (const MacAddress& mac, const IpAddress& ip);
98
106 static int add (const MacAddress& mac, const IpAddress& ip, const std::string& interface);
107
113 MacAddress cache (const IpAddress& ip);
114
121 static MacAddress cache (const IpAddress& ip, const std::string& interface);
122
123 private:
127 struct __attribute__ ((packed)) ArpPacket
128 {
129 uint16_t ar_hrd;
130 uint16_t ar_pro;
131 uint8_t ar_hln;
132 uint8_t ar_pln;
133 uint16_t ar_op;
134 uint8_t ar_sha[ETH_ALEN];
135 uint32_t ar_sip;
136 uint8_t ar_tha[ETH_ALEN];
137 uint32_t ar_tip;
138 };
139
143 struct __attribute__ ((packed)) Packet
144 {
145 struct ethhdr eth;
146 ArpPacket arp;
147 };
148
150 std::string _interface;
151 };
152}
153
154#endif
ARP protocol class.
Definition arp.hpp:43
int add(const MacAddress &mac, const IpAddress &ip)
add entry the MAC address of the given IP address to ARP cache.
Definition arp.cpp:200
MacAddress request(const IpAddress &ip)
get the MAC address for the given IP address using ARP request.
Definition arp.cpp:87
Arp()=delete
create the Arp instance.
MacAddress get(const IpAddress &ip)
get the MAC address for the given IP address using ARP cache or ARP request.
Definition arp.cpp:56
MacAddress cache(const IpAddress &ip)
get the MAC address for the given IP address using ARP cache.
Definition arp.cpp:247
virtual ~Arp()=default
destroy the Arp instance.
IPv6, IPv4 address class.
Definition ipaddress.hpp:51
MAC address class.
Definition macaddress.hpp:46
Definition acceptor.hpp:32