36 uint8_t family = (options.
getIpVersion() == 6) ? AF_INET6 : AF_INET;
42 "Values for IP version: " <<
44 " and server address: " << servername <<
" are mismatched.");
48 if (family == AF_INET6) {
50 port = DHCP6_CLIENT_PORT;
53 port = DHCP6_SERVER_PORT;
62 if (!localname.empty()) {
75 }
else if (!servername.empty()) {
90 int broadcast_enable = 1;
91 int ret = setsockopt(sock, SOL_SOCKET, SO_BROADCAST,
92 &broadcast_enable,
sizeof(broadcast_enable));
95 "unable to set broadcast option on the socket");
102 int ret = setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
103 &hops,
sizeof(hops));
113 int idx = iface->getIndex();
114 ret = setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_IF,
119 "unable to enable multicast on socket " << sock
120 <<
". errno = " << errno);
138 for (
auto const& s : iface->getSockets()) {
155 }
catch (
const std::exception &e) {
157 std::cout <<
"Incorrect DHCP packet received"
158 << e.what() << std::endl;
170 }
catch (
const std::exception &e) {
172 std::cout <<
"Incorrect DHCP packet received"
173 << e.what() << std::endl;
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown if a function is called in a prohibited way.
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
A generic exception that is thrown when an unexpected error condition occurs.
The IOAddress class represents an IP addresses (version agnostic)
bool isV6Multicast() const
checks whether and address is IPv6 and is multicast
short getFamily() const
Returns the address family.
int openSocketFromAddress(const isc::asiolink::IOAddress &addr, const uint16_t port)
Opens UDP/IP socket and binds to address specified.
IfacePtr getIface(const unsigned int ifindex)
Returns interface specified interface index.
int openSocketFromIface(const std::string &ifname, const uint16_t port, const uint8_t family)
Opens UDP/IP socket and binds it to interface specified.
Pkt6Ptr receive6(uint32_t timeout_sec, uint32_t timeout_usec=0)
Receive IPv4 packets or data from external sockets.
static IfaceMgr & instance()
IfaceMgr is a singleton class.
int openSocketFromRemoteAddress(const isc::asiolink::IOAddress &remote_addr, const uint16_t port)
Opens UDP/IP socket to be used to connect to remote address.
bool send(const Pkt6Ptr &pkt)
Sends an IPv6 packet.
Pkt4Ptr receive4(uint32_t timeout_sec, uint32_t timeout_usec=0)
Receive IPv4 packets or data from external sockets.
unsigned int ifindex_
Interface index.
uint8_t getIpVersion() const
Returns IP version.
std::string getLocalName() const
Returns local address or interface name.
int getLocalPort() const
Returns local port number.
bool isBroadcast() const
Checks if broadcast address is to be used.
std::string getServerName() const
Returns server name.
bool isUseRelayedV6() const
Check if generated DHCPv6 messages should appear as relayed.
bool isInterface() const
Checks if interface name was used.
static int malformed_pkts_
virtual ~PerfSocket()
Destructor of the socket wrapper class.
PerfSocket(CommandOptions &options)
Constructor of socket wrapper class.
virtual dhcp::Pkt6Ptr receive6(uint32_t timeout_sec, uint32_t timeout_usec) override
Receive DHCPv6 packet from interface.
virtual dhcp::IfacePtr getIface() override
Get interface from IfaceMgr.
virtual bool send(const dhcp::Pkt4Ptr &pkt) override
Send DHCPv4 packet through interface.
int openSocket(CommandOptions &options) const
Open socket to communicate with DHCP server.
void initSocketData()
Initialize socket data.
virtual dhcp::Pkt4Ptr receive4(uint32_t timeout_sec, uint32_t timeout_usec) override
Receive DHCPv4 packet from interface.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
boost::shared_ptr< Iface > IfacePtr
Type definition for the pointer to an Iface object.
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Defines the logger used by the top-level component of kea-lfc.
isc::asiolink::IOAddress addr_