24 sockfd_ = openSocket(options);
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);
128 PerfSocket::~PerfSocket() {
131 iface->delSocket(sockfd_);
136 PerfSocket::initSocketData() {
139 if (s.sockfd_ == sockfd_) {
140 ifindex_ = iface->getIndex();
150 PerfSocket::receive4(uint32_t timeout_sec, uint32_t timeout_usec) {
155 }
catch (
const std::exception &e) {
156 ExchangeStats::malformed_pkts_++;
157 std::cout <<
"Incorrect DHCP packet received" 158 << e.what() << std::endl;
165 PerfSocket::receive6(uint32_t timeout_sec, uint32_t timeout_usec) {
170 }
catch (
const std::exception &e) {
171 ExchangeStats::malformed_pkts_++;
172 std::cout <<
"Incorrect DHCP packet received" 173 << e.what() << std::endl;
190 PerfSocket::getIface() {
IfacePtr getIface(int ifindex)
Returns interface specified interface index.
int openSocketFromRemoteAddress(const isc::asiolink::IOAddress &remote_addr, const uint16_t port)
Opens UDP/IP socket to be used to connect to remote address.
std::string getLocalName() const
Returns local address or interface name.
bool isUseRelayedV6() const
Check if generated DHCPv6 messages should appear as relayed.
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
boost::shared_ptr< Iface > IfacePtr
Type definition for the pointer to an Iface object.
uint8_t getIpVersion() const
Returns IP version.
int openSocketFromAddress(const isc::asiolink::IOAddress &addr, const uint16_t port)
Opens UDP/IP socket and binds to address specified.
bool send(const Pkt6Ptr &pkt)
Sends an IPv6 packet.
bool isBroadcast() const
Checks if broadcast address is to be used.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Pkt4Ptr receive4(uint32_t timeout_sec, uint32_t timeout_usec=0)
Receive IPv4 packets or data from external sockets.
bool isInterface() const
Checks if interface name was used.
A generic exception that is thrown when an unexpected error condition occurs.
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
std::string getServerName() const
Returns server name.
bool isV6Multicast() const
checks whether and address is IPv6 and is multicast
int getLocalPort() const
Returns local port number.
Defines the logger used by the top-level component of kea-lfc.
A generic exception that is thrown if a function is called in a prohibited way.
static IfaceMgr & instance()
IfaceMgr is a singleton class.
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.
The IOAddress class represents an IP addresses (version agnostic)
Holds information about socket.
short getFamily() const
Returns the address family.