|
@@ -1,4 +1,4 @@
|
|
|
-// Copyright (C) 2011, 2013-2014 Internet Systems Consortium, Inc. ("ISC")
|
|
|
+// Copyright (C) 2011, 2013-2015 Internet Systems Consortium, Inc. ("ISC")
|
|
|
//
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
@@ -39,19 +39,20 @@ namespace dhcp {
|
|
|
/// only, as earlier versions did not support getifaddrs() API.
|
|
|
void
|
|
|
IfaceMgr::detectIfaces() {
|
|
|
- struct ifaddrs * iflist = 0, * ifptr = 0;
|
|
|
+ struct ifaddrs* iflist = 0;// The whole interface list
|
|
|
+ struct ifaddrs* ifptr = 0; // The interface we're processing now
|
|
|
|
|
|
// Gets list of ifaddrs struct
|
|
|
- if(getifaddrs(& iflist) != 0) {
|
|
|
+ if(getifaddrs(&iflist) != 0) {
|
|
|
isc_throw(Unexpected, "Network interfaces detection failed.");
|
|
|
}
|
|
|
|
|
|
- typedef std::map<string, Iface> ifaceLst;
|
|
|
- ifaceLst::iterator iface_iter;
|
|
|
- ifaceLst ifaces;
|
|
|
+ typedef map<string, IfacePtr> IfaceLst;
|
|
|
+ IfaceLst::iterator iface_iter;
|
|
|
+ IfaceLst ifaces;
|
|
|
|
|
|
// First lookup for getting interfaces ...
|
|
|
- for(ifptr = iflist; ifptr != 0; ifptr = ifptr->ifa_next) {
|
|
|
+ for (ifptr = iflist; ifptr != 0; ifptr = ifptr->ifa_next) {
|
|
|
const char * ifname = ifptr->ifa_name;
|
|
|
uint ifindex = 0;
|
|
|
|
|
@@ -66,53 +67,52 @@ IfaceMgr::detectIfaces() {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- Iface iface(ifname, ifindex);
|
|
|
- iface.setFlags(ifptr->ifa_flags);
|
|
|
- ifaces.insert(pair<string, Iface>(ifname, iface));
|
|
|
+ IfacePtr iface(new Iface(ifname, ifindex));
|
|
|
+ iface->setFlags(ifptr->ifa_flags);
|
|
|
+ ifaces.insert(pair<string, IfacePtr>(ifname, iface));
|
|
|
}
|
|
|
|
|
|
// Second lookup to get MAC and IP addresses
|
|
|
for (ifptr = iflist; ifptr != 0; ifptr = ifptr->ifa_next) {
|
|
|
-
|
|
|
iface_iter = ifaces.find(ifptr->ifa_name);
|
|
|
if (iface_iter == ifaces.end()) {
|
|
|
continue;
|
|
|
}
|
|
|
// Common byte pointer for following data
|
|
|
const uint8_t * ptr = 0;
|
|
|
- if (ifptr->ifa_addr->sa_family == AF_LINK) {
|
|
|
+ if(ifptr->ifa_addr->sa_family == AF_LINK) {
|
|
|
// HWAddr
|
|
|
struct sockaddr_dl * ldata =
|
|
|
reinterpret_cast<struct sockaddr_dl *>(ifptr->ifa_addr);
|
|
|
ptr = reinterpret_cast<uint8_t *>(LLADDR(ldata));
|
|
|
|
|
|
- iface_iter->second.setHWType(ldata->sdl_type);
|
|
|
- iface_iter->second.setMac(ptr, ldata->sdl_alen);
|
|
|
- } else if (ifptr->ifa_addr->sa_family == AF_INET6) {
|
|
|
+ iface_iter->second->setHWType(ldata->sdl_type);
|
|
|
+ iface_iter->second->setMac(ptr, ldata->sdl_alen);
|
|
|
+ } else if(ifptr->ifa_addr->sa_family == AF_INET6) {
|
|
|
// IPv6 Addr
|
|
|
struct sockaddr_in6 * adata =
|
|
|
reinterpret_cast<struct sockaddr_in6 *>(ifptr->ifa_addr);
|
|
|
- ptr = reinterpret_cast<uint8_t *>(& adata->sin6_addr);
|
|
|
+ ptr = reinterpret_cast<uint8_t *>(&adata->sin6_addr);
|
|
|
|
|
|
IOAddress a = IOAddress::fromBytes(AF_INET6, ptr);
|
|
|
- iface_iter->second.addAddress(a);
|
|
|
+ iface_iter->second->addAddress(a);
|
|
|
} else {
|
|
|
// IPv4 Addr
|
|
|
struct sockaddr_in * adata =
|
|
|
reinterpret_cast<struct sockaddr_in *>(ifptr->ifa_addr);
|
|
|
- ptr = reinterpret_cast<uint8_t *>(& adata->sin_addr);
|
|
|
+ ptr = reinterpret_cast<uint8_t *>(&adata->sin_addr);
|
|
|
|
|
|
IOAddress a = IOAddress::fromBytes(AF_INET, ptr);
|
|
|
- iface_iter->second.addAddress(a);
|
|
|
+ iface_iter->second->addAddress(a);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
freeifaddrs(iflist);
|
|
|
|
|
|
// Interfaces registering
|
|
|
- for (ifaceLst::const_iterator iface_iter = ifaces.begin();
|
|
|
+ for(IfaceLst::const_iterator iface_iter = ifaces.begin();
|
|
|
iface_iter != ifaces.end(); ++iface_iter) {
|
|
|
- ifaces_.push_back(iface_iter->second);
|
|
|
+ addInterface(iface_iter->second);
|
|
|
}
|
|
|
}
|
|
|
|