9 #ifndef __libutilxx__sella__net__EtherSocket_H__
10 #define __libutilxx__sella__net__EtherSocket_H__
12 #include "../../common.h"
15 #include <sys/socket.h>
17 #include <linux/if_ether.h>
18 #include <linux/if_packet.h>
28 typedef std::shared_ptr<EtherSocket> shared;
32 static const int EthAll = ETH_P_ALL;
33 static const int EthIP = ETH_P_IP;
34 static const int EthARP = ETH_P_ARP;
35 static const int EthRARP = ETH_P_RARP;
36 static const int Eth8021Q = ETH_P_8021Q;
37 static const int EthMPLSUC = ETH_P_MPLS_UC;
38 static const int EthMPLSMC = ETH_P_MPLS_MC;
40 static const unsigned char BroadcastMAC[];
43 EtherSocket(
int etherType,
const std::string &interface,
bool raw =
false)
throw (SocketException);
44 EtherSocket(
int etherType,
int ifIndex,
bool raw =
false)
throw (SocketException);
45 EtherSocket(
int etherType,
bool raw =
false)
throw (SocketException);
50 static const EtherSocket::shared shared_ptr(
int etherType)
throw (SocketException);
52 EtherSocket& setInterface(
const std::string &interface)
throw (SocketException);
55 int getEtherType(
void)
const throw ();
56 std::string getInterface(
void)
const throw (SocketException);
57 int getIfIndex(
void)
const throw ();
58 bool isRaw(
void)
const throw ();
60 void bindInterface(
void)
throw (SocketException);
61 void setSoBindToDevice(
const std::string &interface)
throw (SocketException);
62 void setSoBindToDevice(
void)
throw (SocketException);
63 void setPromiscous(
bool on =
true)
throw (SocketException);
65 ssize_t sendto(
const void *data,
size_t len,
const std::string &dst_mac,
int flags = 0)
throw (SocketException);
66 ssize_t sendto(
const void *data,
size_t len,
const unsigned char *dst_mac = BroadcastMAC,
int flags = 0)
throw (SocketException);
67 ssize_t sendto(
const void *data,
size_t len,
int flags,
const struct sockaddr_ll *dst_addr, socklen_t addrlen)
throw (SocketException);
68 ssize_t recvfrom(
void *data,
size_t len,
int flags = 0,
struct sockaddr_ll *src_addr = NULL, socklen_t *addrlen = NULL)
throw (SocketException);
69 ssize_t recvfrom(
void *data,
size_t len, std::string &src_mac,
int flags = 0)
throw (SocketException);
71 void bind(
const IPAddressPort &addressport)
throw (SocketException) =
delete;
72 void bind(
const IPAddress &address,
const Port &port)
throw (SocketException) =
delete;
73 void bind(
const std::string &address = std::string(),
const unsigned short port = 0)
throw (SocketException) =
delete;
74 void connect(
const IPAddressPort &addressport)
throw (SocketException) =
delete;
75 void connect(
const IPAddress &address,
const Port &port)
throw (SocketException) =
delete;
76 void connect(
const std::string &address,
const unsigned short port)
throw (SocketException) =
delete;
78 virtual ssize_t send(
const void *data,
size_t len,
int flags = 0)
throw (SocketException) {
79 THROW(SocketException,
"Not supported with EtherSocket");
82 virtual ssize_t recv(
void *data,
size_t len,
int flags = 0)
throw (SocketException) {
83 THROW(SocketException,
"Not supported with EtherSocket");