18#include <sys/socket.h>
38 struct ifaddrs* iflist = 0;
39 struct ifaddrs* ifptr = 0;
42 if (getifaddrs(&iflist) != 0) {
46 typedef map<string, IfacePtr> IfaceLst;
47 IfaceLst::iterator iface_iter;
51 for (ifptr = iflist; ifptr != 0; ifptr = ifptr->ifa_next) {
52 const char * ifname = ifptr->ifa_name;
55 if (!(ifindex = if_nametoindex(ifname))) {
61 iface_iter = ifaces.find(ifname);
62 if (iface_iter != ifaces.end()) {
71 iface.reset(
new Iface(ifname, ifindex));
73 iface->setFlags(ifptr->ifa_flags);
74 ifaces.insert(pair<string, IfacePtr>(ifname, iface));
78 for (ifptr = iflist; ifptr != 0; ifptr = ifptr->ifa_next) {
79 iface_iter = ifaces.find(ifptr->ifa_name);
80 if (iface_iter == ifaces.end()) {
84 const uint8_t * ptr = 0;
85 if (ifptr->ifa_addr->sa_family == AF_LINK) {
87 struct sockaddr_dl * ldata =
88 reinterpret_cast<struct sockaddr_dl *
>(ifptr->ifa_addr);
89 ptr =
reinterpret_cast<uint8_t *
>(LLADDR(ldata));
91 iface_iter->second->setHWType(ldata->sdl_type);
92 iface_iter->second->setMac(ptr, ldata->sdl_alen);
93 }
else if (ifptr->ifa_addr->sa_family == AF_INET6) {
95 struct sockaddr_in6 * adata =
96 reinterpret_cast<struct sockaddr_in6 *
>(ifptr->ifa_addr);
97 ptr =
reinterpret_cast<uint8_t *
>(&adata->sin6_addr);
100 iface_iter->second->addAddress(a);
103 struct sockaddr_in * adata =
104 reinterpret_cast<struct sockaddr_in *
>(ifptr->ifa_addr);
105 ptr =
reinterpret_cast<uint8_t *
>(&adata->sin_addr);
108 iface_iter->second->addAddress(a);
115 for (IfaceLst::const_iterator iface_iter = ifaces.begin();
116 iface_iter != ifaces.end(); ++iface_iter) {
119 iface =
getIface(iface_iter->first);
151 if (direct_response_desired) {
161IfaceMgr::openMulticastSocket(
Iface& iface,
172 "Failed to open link-local socket on "
173 "interface " << iface.
getName() <<
": "
183 const bool join_multicast) {
189 SocketInfo info = packet_filter6_->openSocket(iface, actual_address, port,
192 return (
info.sockfd_);
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown when an unexpected error condition occurs.
The IOAddress class represents an IP addresses (version agnostic)
static IOAddress fromBytes(short family, const uint8_t *data)
Creates an address from over wire data.
int openSocket(const std::string &ifname, const isc::asiolink::IOAddress &addr, const uint16_t port, const bool receive_bcast=false, const bool send_bcast=false)
Opens UDP/IP socket and binds it to address, interface and port.
void setPacketFilter(const PktFilterPtr &packet_filter)
Set packet filter object to handle sending and receiving DHCPv4 messages.
void detectIfaces(bool update_only=false)
Detects network interfaces.
int openSocket6(Iface &iface, const isc::asiolink::IOAddress &addr, uint16_t port, const bool join_multicast)
Opens IPv6 socket.
bool isTestMode() const
Checks if the IfaceMgr is in the test mode.
void addInterface(const IfacePtr &iface)
Adds an interface to list of known interfaces.
IfacePtr getIface(int ifindex)
Returns interface specified interface index.
void setMatchingPacketFilter(const bool direct_response_desired=false)
Set Packet Filter object to handle send/receive packets.
Represents a single network interface.
uint64_t flags_
Interface flags (this value is as is returned by OS, it may mean different things on different OSes).
bool flag_multicast_
Flag specifies if selected interface is multicast capable.
std::string getName() const
Returns interface name.
void setFlags(uint64_t flags)
Sets flag_*_ fields based on bitmask value returned by OS.
bool flag_running_
Flag specifies if selected interface is running (e.g.
bool flag_loopback_
Specifies if selected interface is loopback.
void addSocket(const SocketInfo &sock)
Adds socket descriptor to an interface.
bool flag_up_
Specifies if selected interface is up.
bool flag_broadcast_
Flag specifies if selected interface is broadcast capable.
Packet handling class using Berkeley Packet Filtering (BPF)
Packet handling class using AF_INET socket family.
IfaceMgr exception thrown thrown when socket opening or configuration failed.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define IFACEMGR_ERROR(ex_type, handler, iface, stream)
A macro which handles an error in IfaceMgr.
boost::shared_ptr< PktFilter > PktFilterPtr
Pointer to a PktFilter object.
boost::shared_ptr< Iface > IfacePtr
Type definition for the pointer to an Iface object.
std::function< void(const std::string &errmsg)> IfaceMgrErrorMsgCallback
This type describes the callback function invoked when error occurs in the IfaceMgr.
Defines the logger used by the top-level component of kea-lfc.
Holds information about socket.