join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::Arp Class Reference

ARP protocol class. More...

#include <arp.hpp>

Inheritance diagram for join::Arp:
Collaboration diagram for join::Arp:

Public Member Functions

 Arp ()=delete
 create the Arp instance.
 
 Arp (const std::string &interface, NeighborManager *neighbors=nullptr)
 create the Arp instance.
 
 Arp (const Arp &other)=delete
 create instance by copy.
 
 Arp (Arp &&other)=delete
 create instance by move.
 
Arpoperator= (const Arp &other)=delete
 assign instance by copy.
 
Arpoperator= (Arp &&other)=delete
 assign instance by move.
 
 ~Arp ()=default
 destroy the Arp instance.
 
template<typename Rep , typename Period >
MacAddress get (const IpAddress &ip, std::chrono::duration< Rep, Period > timeout)
 get the MAC address for the given IP address using netlink neighbor cache or ARP request.
 
MacAddress get (const IpAddress &ip)
 get the MAC address for the given IP address using ARP cache or ARP request.
 
template<typename Rep , typename Period >
MacAddress request (const IpAddress &ip, std::chrono::duration< Rep, Period > timeout)
 get the MAC address for the given IP address using ARP request.
 
MacAddress request (const IpAddress &ip)
 get the MAC address for the given IP address using ARP request.
 
int add (const MacAddress &mac, const IpAddress &ip)
 add entry the MAC address of the given IP address to ARP cache.
 
int remove (const IpAddress &ip)
 remove the MAC address of the given IP address from ARP cache.
 
MacAddress cache (const IpAddress &ip)
 get the MAC address for the given IP address using ARP cache.
 
- Public Member Functions inherited from join::BasicSocket< Protocol >
 BasicSocket ()
 default constructor.
 
 BasicSocket (Mode mode)
 create socket instance specifying the mode.
 
 BasicSocket (const BasicSocket &other)=delete
 copy constructor.
 
BasicSocketoperator= (const BasicSocket &other)=delete
 copy assignment operator.
 
 BasicSocket (BasicSocket &&other)
 move constructor.
 
BasicSocketoperator= (BasicSocket &&other)
 move assignment operator.
 
virtual ~BasicSocket ()
 destroy the socket instance.
 
virtual int open (const Protocol &protocol=Protocol()) noexcept
 open socket using the given protocol.
 
virtual void close () noexcept
 close the socket.
 
virtual int bind (const Endpoint &endpoint) noexcept
 assigns the specified endpoint to the socket.
 
virtual int canRead () const noexcept
 get the number of readable bytes.
 
virtual bool waitReadyRead (int timeout=0) const noexcept
 block until new data is available for reading.
 
virtual int read (char *data, unsigned long maxSize) noexcept
 read data.
 
virtual bool waitReadyWrite (int timeout=0) const noexcept
 block until at least one byte can be written.
 
virtual int write (const char *data, unsigned long maxSize) noexcept
 write data.
 
void setMode (Mode mode) noexcept
 set the socket to the non-blocking or blocking mode.
 
virtual int setOption (Option option, int value) noexcept
 set the given option to the given value.
 
Endpoint localEndpoint () const
 determine the local endpoint associated with this socket.
 
bool opened () const noexcept
 check if the socket is opened.
 
virtual bool encrypted () const noexcept
 check if the socket is secure.
 
int family () const noexcept
 get socket address family.
 
int type () const noexcept
 get the protocol communication semantic.
 
int protocol () const noexcept
 get socket protocol.
 
int handle () const noexcept
 get socket native handle.
 
- Public Member Functions inherited from join::EventHandler
 EventHandler ()=default
 create instance.
 
 EventHandler (const EventHandler &other)=default
 copy constructor.
 
EventHandleroperator= (const EventHandler &other)=default
 copy assignment operator.
 
 EventHandler (EventHandler &&other)=default
 move constructor.
 
EventHandleroperator= (EventHandler &&other)=default
 move assignment operator.
 
virtual ~EventHandler ()=default
 destroy instance.
 

Static Public Member Functions

template<typename Rep , typename Period >
static MacAddress get (const std::string &interface, const IpAddress &ip, std::chrono::duration< Rep, Period > timeout)
 discover the MAC address for the given internet layer address.
 
static MacAddress get (const std::string &interface, const IpAddress &ip)
 discover the MAC address for the given internet layer address.
 
template<typename Rep , typename Period >
static MacAddress request (const std::string &interface, const IpAddress &ip, std::chrono::duration< Rep, Period > timeout)
 get the MAC address for the given IP address using ARP request.
 
static MacAddress request (const std::string &interface, const IpAddress &ip)
 get the MAC address for the given IP address using ARP request.
 
static int add (const std::string &interface, const MacAddress &mac, const IpAddress &ip)
 add entry the MAC address of the given IP address to ARP cache.
 
static int remove (const std::string &interface, const IpAddress &ip)
 remove the MAC address of the given IP address from ARP cache.
 
static MacAddress cache (const std::string &interface, const IpAddress &ip)
 get the MAC address for the given IP address using ARP cache.
 
- Static Public Member Functions inherited from join::BasicSocket< Protocol >
static uint16_t checksum (const uint16_t *data, size_t len, uint16_t current=0)
 get standard 1s complement checksum.
 

Additional Inherited Members

- Public Types inherited from join::BasicSocket< Protocol >
enum  Mode { Blocking , NonBlocking }
 socket modes. More...
 
enum  Option {
  NoDelay , KeepAlive , KeepIdle , KeepIntvl ,
  KeepCount , SndBuffer , RcvBuffer , TimeStamp ,
  ReuseAddr , ReusePort , Broadcast , Ttl ,
  MulticastLoop , MulticastTtl , PathMtuDiscover , RcvError ,
  AuxData
}
 socket options. More...
 
enum  State {
  Connecting , Connected , Disconnecting , Disconnected ,
  Closed
}
 socket states. More...
 
using Ptr = std::unique_ptr<BasicSocket<Protocol>>
 
using Endpoint = typename Protocol::Endpoint
 
- Protected Member Functions inherited from join::BasicSocket< Protocol >
int wait (bool wantRead, bool wantWrite, int timeout) const noexcept
 wait for the socket handle to become ready.
 
- Protected Member Functions inherited from join::EventHandler
virtual void onClose (int fd)
 method called when handle is closed.
 
virtual void onError (int fd)
 method called when an error occurred on handle.
 
- Protected Attributes inherited from join::BasicSocket< Protocol >
State _state = State::Closed
 socket state.
 
Mode _mode = Mode::NonBlocking
 socket mode.
 
int _handle = -1
 socket handle.
 
Protocol _protocol
 protocol.
 

Detailed Description

ARP protocol class.

Constructor & Destructor Documentation

◆ Arp() [1/4]

join::Arp::Arp ( )
delete

create the Arp instance.

◆ Arp() [2/4]

Arp::Arp ( const std::string & interface,
NeighborManager * neighbors = nullptr )

create the Arp instance.

Parameters
interfaceinterface name.
neighborsneighbor manager to use (uses NeighborManager::instance if nullptr).

◆ Arp() [3/4]

join::Arp::Arp ( const Arp & other)
delete

create instance by copy.

Parameters
otherother interface to copy.

◆ Arp() [4/4]

join::Arp::Arp ( Arp && other)
delete

create instance by move.

Parameters
otherother interface to move.

◆ ~Arp()

join::Arp::~Arp ( )
default

destroy the Arp instance.

Member Function Documentation

◆ add() [1/2]

int Arp::add ( const MacAddress & mac,
const IpAddress & ip )

add entry the MAC address of the given IP address to ARP cache.

Parameters
macMAC address.
ipIP address.
Returns
0 on success, -1 on failure.

◆ add() [2/2]

int Arp::add ( const std::string & interface,
const MacAddress & mac,
const IpAddress & ip )
static

add entry the MAC address of the given IP address to ARP cache.

Parameters
interfaceinterface name.
macMAC address.
ipIP address.
Returns
0 on success, -1 on failure.

◆ cache() [1/2]

MacAddress Arp::cache ( const IpAddress & ip)

get the MAC address for the given IP address using ARP cache.

Parameters
ipIP address.
Returns
the MAC address.

◆ cache() [2/2]

MacAddress Arp::cache ( const std::string & interface,
const IpAddress & ip )
static

get the MAC address for the given IP address using ARP cache.

Parameters
interfaceinterface name.
ipIP address.
Returns
the MAC address.

◆ get() [1/4]

MacAddress join::Arp::get ( const IpAddress & ip)
inline

get the MAC address for the given IP address using ARP cache or ARP request.

Parameters
ipIP address.
Returns
the MAC address.

◆ get() [2/4]

template<typename Rep , typename Period >
MacAddress join::Arp::get ( const IpAddress & ip,
std::chrono::duration< Rep, Period > timeout )
inline

get the MAC address for the given IP address using netlink neighbor cache or ARP request.

Parameters
ipIP address.
timeoutrequest timeout.
Returns
the MAC address.

◆ get() [3/4]

static MacAddress join::Arp::get ( const std::string & interface,
const IpAddress & ip )
inlinestatic

discover the MAC address for the given internet layer address.

Parameters
interfaceinterface name.
ipIP address.
Returns
the MAC address.

◆ get() [4/4]

template<typename Rep , typename Period >
static MacAddress join::Arp::get ( const std::string & interface,
const IpAddress & ip,
std::chrono::duration< Rep, Period > timeout )
inlinestatic

discover the MAC address for the given internet layer address.

Parameters
interfaceinterface name.
ipIP address.
timeoutrequest timeout.
Returns
the MAC address.

◆ operator=() [1/2]

Arp & join::Arp::operator= ( Arp && other)
delete

assign instance by move.

Parameters
otherother interface to move.
Returns
A reference of the current object.

◆ operator=() [2/2]

Arp & join::Arp::operator= ( const Arp & other)
delete

assign instance by copy.

Parameters
otherother interface to copy.
Returns
A reference of the current object.

◆ remove() [1/2]

int Arp::remove ( const IpAddress & ip)

remove the MAC address of the given IP address from ARP cache.

Parameters
ipIP address.
Returns
0 on success, -1 on failure.

◆ remove() [2/2]

int Arp::remove ( const std::string & interface,
const IpAddress & ip )
static

remove the MAC address of the given IP address from ARP cache.

Parameters
interfaceinterface name.
ipIP address.
Returns
0 on success, -1 on failure.

◆ request() [1/4]

MacAddress join::Arp::request ( const IpAddress & ip)
inline

get the MAC address for the given IP address using ARP request.

Parameters
ipIP address.
Returns
the MAC address.

◆ request() [2/4]

template<typename Rep , typename Period >
MacAddress join::Arp::request ( const IpAddress & ip,
std::chrono::duration< Rep, Period > timeout )
inline

get the MAC address for the given IP address using ARP request.

Parameters
ipIP address.
timeoutrequest timeout.
Returns
the MAC address.

◆ request() [3/4]

static MacAddress join::Arp::request ( const std::string & interface,
const IpAddress & ip )
inlinestatic

get the MAC address for the given IP address using ARP request.

Parameters
interfaceinterface name.
ipIP address.
Returns
the MAC address.

◆ request() [4/4]

template<typename Rep , typename Period >
static MacAddress join::Arp::request ( const std::string & interface,
const IpAddress & ip,
std::chrono::duration< Rep, Period > timeout )
inlinestatic

get the MAC address for the given IP address using ARP request.

Parameters
interfaceinterface name.
ipIP address.
timeoutrequest timeout.
Returns
the MAC address.

The documentation for this class was generated from the following files: