Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added adapterName() to NetworkInterface #149

Merged
merged 1 commit into from

2 participants

@lbakman

Added adapterName() to NetworkInterface as requested in issue 148.

@aleks-f aleks-f merged commit 02b91b0 into pocoproject:develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 10, 2013
  1. @lbakman
This page is out of date. Refresh to see the latest.
Showing with 58 additions and 18 deletions.
  1. +11 −2 Net/include/Poco/Net/NetworkInterface.h
  2. +47 −16 Net/src/NetworkInterface.cpp
View
13 Net/include/Poco/Net/NetworkInterface.h
@@ -155,6 +155,14 @@ class Net_API NetworkInterface
///
/// On other platforms this is the same as name().
+ const std::string& adapterName() const;
+ /// Returns the interface adapter name.
+ ///
+ /// On Windows platforms, this is the network adapter LUID.
+ /// The adapter name is used by some Windows Net APIs like Dhcp.
+ ///
+ /// On other platforms this is the same as name().
+
const IPAddress& firstAddress(IPAddress::Family family) const;
/// Returns the first IP address bound to the interface.
/// Throws NotFoundException if the address family is not
@@ -282,10 +290,10 @@ class Net_API NetworkInterface
/// member of the pair.
protected:
- NetworkInterface(const std::string& name, const std::string& displayName, const IPAddress& address, unsigned index, MACAddress* pMACAddress = 0);
+ NetworkInterface(const std::string& name, const std::string& displayName, const std::string& adapterName, const IPAddress& address, unsigned index, MACAddress* pMACAddress = 0);
/// Creates the NetworkInterface.
- NetworkInterface(const std::string& name, const std::string& displayName, unsigned index, MACAddress* pMACAddress = 0);
+ NetworkInterface(const std::string& name, const std::string& displayName, const std::string& adapterName, unsigned index, MACAddress* pMACAddress = 0);
/// Creates the NetworkInterface.
NetworkInterface(const std::string& name, const IPAddress& address, unsigned index, MACAddress* pMACAddress = 0);
@@ -293,6 +301,7 @@ class Net_API NetworkInterface
NetworkInterface(const std::string& name,
const std::string& displayName,
+ const std::string& adapterName,
const IPAddress& address,
const IPAddress& subnetMask,
const IPAddress& broadcastAddress,
View
63 Net/src/NetworkInterface.cpp
@@ -93,10 +93,11 @@ class NetworkInterfaceImpl: public Poco::RefCountedObject
typedef NetworkInterface::Type Type;
NetworkInterfaceImpl(unsigned index);
- NetworkInterfaceImpl(const std::string& name, const std::string& displayName, const IPAddress& address, unsigned index, NetworkInterface::MACAddress* pMACAddress = 0);
- NetworkInterfaceImpl(const std::string& name, const std::string& displayName, unsigned index = 0, NetworkInterface::MACAddress* pMACAddress = 0);
+ NetworkInterfaceImpl(const std::string& name, const std::string& displayName, const std::string& adapterName, const IPAddress& address, unsigned index, NetworkInterface::MACAddress* pMACAddress = 0);
+ NetworkInterfaceImpl(const std::string& name, const std::string& displayName, const std::string& adapterName, unsigned index = 0, NetworkInterface::MACAddress* pMACAddress = 0);
NetworkInterfaceImpl(const std::string& name,
const std::string& displayName,
+ const std::string& adapterName,
const IPAddress& address,
const IPAddress& subnetMask,
const IPAddress& broadcastAddress,
@@ -106,6 +107,7 @@ class NetworkInterfaceImpl: public Poco::RefCountedObject
unsigned index() const;
const std::string& name() const;
const std::string& displayName() const;
+ const std::string& adapterName() const;
const IPAddress& firstAddress(IPAddress::Family family) const;
void addAddress(const AddressTuple& address);
const IPAddress& address(unsigned index) const;
@@ -120,6 +122,7 @@ class NetworkInterfaceImpl: public Poco::RefCountedObject
void setName(const std::string& name);
void setDisplayName(const std::string& name);
+ void setAdapterName(const std::string& name);
void addAddress(const IPAddress& addr);
void setMACAddress(const NetworkInterface::MACAddress& addr);
void setMACAddress(const void *addr, std::size_t len);
@@ -154,6 +157,7 @@ class NetworkInterfaceImpl: public Poco::RefCountedObject
private:
std::string _name;
std::string _displayName;
+ std::string _adapterName;
AddressList _addressList;
unsigned _index;
bool _broadcast;
@@ -178,9 +182,10 @@ NetworkInterfaceImpl::NetworkInterfaceImpl(unsigned index):
}
-NetworkInterfaceImpl::NetworkInterfaceImpl(const std::string& name, const std::string& displayName, const IPAddress& address, unsigned index, NetworkInterface::MACAddress* pMACAddress):
+NetworkInterfaceImpl::NetworkInterfaceImpl(const std::string& name, const std::string& displayName, const std::string& adapterName, const IPAddress& address, unsigned index, NetworkInterface::MACAddress* pMACAddress):
_name(name),
_displayName(displayName),
+ _adapterName(adapterName),
_index(index),
_broadcast(false),
_loopback(false),
@@ -196,9 +201,10 @@ NetworkInterfaceImpl::NetworkInterfaceImpl(const std::string& name, const std::s
}
-NetworkInterfaceImpl::NetworkInterfaceImpl(const std::string& name, const std::string& displayName, unsigned index, NetworkInterface::MACAddress* pMACAddress):
+NetworkInterfaceImpl::NetworkInterfaceImpl(const std::string& name, const std::string& displayName, const std::string& adapterName, unsigned index, NetworkInterface::MACAddress* pMACAddress):
_name(name),
_displayName(displayName),
+ _adapterName(adapterName),
_index(index),
_broadcast(false),
_loopback(false),
@@ -215,6 +221,7 @@ NetworkInterfaceImpl::NetworkInterfaceImpl(const std::string& name, const std::s
NetworkInterfaceImpl::NetworkInterfaceImpl(const std::string& name,
const std::string& displayName,
+ const std::string& adapterName,
const IPAddress& address,
const IPAddress& subnetMask,
const IPAddress& broadcastAddress,
@@ -222,6 +229,7 @@ NetworkInterfaceImpl::NetworkInterfaceImpl(const std::string& name,
NetworkInterface::MACAddress* pMACAddress):
_name(name),
_displayName(displayName),
+ _adapterName(adapterName),
_index(index),
_broadcast(false),
_loopback(false),
@@ -305,6 +313,12 @@ inline const std::string& NetworkInterfaceImpl::displayName() const
}
+inline const std::string& NetworkInterfaceImpl::adapterName() const
+{
+ return _adapterName;
+}
+
+
const IPAddress& NetworkInterfaceImpl::firstAddress(IPAddress::Family family) const
{
AddressList::const_iterator it = _addressList.begin();
@@ -517,6 +531,12 @@ inline void NetworkInterfaceImpl::setDisplayName(const std::string& name)
}
+inline void NetworkInterfaceImpl::setAdapterName(const std::string& name)
+{
+ _adapterName = name;
+}
+
+
inline void NetworkInterfaceImpl::addAddress(const IPAddress& addr)
{
_addressList.push_back(addr);
@@ -560,32 +580,33 @@ NetworkInterface::NetworkInterface(const NetworkInterface& interfc):
}
-NetworkInterface::NetworkInterface(const std::string& name, const std::string& displayName, const IPAddress& address, unsigned index, MACAddress* pMACAddress):
- _pImpl(new NetworkInterfaceImpl(name, displayName, address, index, pMACAddress))
+NetworkInterface::NetworkInterface(const std::string& name, const std::string& displayName, const std::string& adapterName, const IPAddress& address, unsigned index, MACAddress* pMACAddress):
+ _pImpl(new NetworkInterfaceImpl(name, displayName, adapterName, address, index, pMACAddress))
{
}
-NetworkInterface::NetworkInterface(const std::string& name, const std::string& displayName, unsigned index, MACAddress* pMACAddress):
- _pImpl(new NetworkInterfaceImpl(name, displayName, index, pMACAddress))
+NetworkInterface::NetworkInterface(const std::string& name, const std::string& displayName, const std::string& adapterName, unsigned index, MACAddress* pMACAddress):
+ _pImpl(new NetworkInterfaceImpl(name, displayName, adapterName, index, pMACAddress))
{
}
NetworkInterface::NetworkInterface(const std::string& name, const IPAddress& address, unsigned index, MACAddress* pMACAddress):
- _pImpl(new NetworkInterfaceImpl(name, name, address, index, pMACAddress))
+ _pImpl(new NetworkInterfaceImpl(name, name, name, address, index, pMACAddress))
{
}
NetworkInterface::NetworkInterface(const std::string& name,
const std::string& displayName,
+ const std::string& adapterName,
const IPAddress& address,
const IPAddress& subnetMask,
const IPAddress& broadcastAddress,
unsigned index,
MACAddress* pMACAddress):
- _pImpl(new NetworkInterfaceImpl(name, displayName, address, subnetMask, broadcastAddress, index, pMACAddress))
+ _pImpl(new NetworkInterfaceImpl(name, displayName, adapterName, address, subnetMask, broadcastAddress, index, pMACAddress))
{
}
@@ -596,7 +617,7 @@ NetworkInterface::NetworkInterface(const std::string& name,
const IPAddress& broadcastAddress,
unsigned index,
MACAddress* pMACAddress):
- _pImpl(new NetworkInterfaceImpl(name, name, address, subnetMask, broadcastAddress, index, pMACAddress))
+ _pImpl(new NetworkInterfaceImpl(name, name, name, address, subnetMask, broadcastAddress, index, pMACAddress))
{
}
@@ -640,6 +661,12 @@ const std::string& NetworkInterface::displayName() const
}
+const std::string& NetworkInterface::adapterName() const
+{
+ return _pImpl->adapterName();
+}
+
+
const IPAddress& NetworkInterface::firstAddress(IPAddress::Family family) const
{
return _pImpl->firstAddress(family);
@@ -854,6 +881,7 @@ NetworkInterface::List NetworkInterface::list(bool ipOnly, bool upOnly)
int index = it->second.index();
std::string name = it->second.name();
std::string displayName = it->second.displayName();
+ std::string adapterName = it->second.adapterName();
NetworkInterface::MACAddress mac = it->second.macAddress();
typedef NetworkInterface::AddressList List;
@@ -866,11 +894,11 @@ NetworkInterface::List NetworkInterface::list(bool ipOnly, bool upOnly)
IPAddress mask = ipIt->get<NetworkInterface::SUBNET_MASK>();
NetworkInterface ni;
if (mask.isWildcard())
- ni = NetworkInterface(name, displayName, addr, index, &mac);
+ ni = NetworkInterface(name, displayName, adapterName, addr, index, &mac);
else
{
IPAddress broadcast = ipIt->get<NetworkInterface::BROADCAST_ADDRESS>();
- ni = NetworkInterface(name, displayName, addr, mask, broadcast, index, &mac);
+ ni = NetworkInterface(name, displayName, adapterName, addr, mask, broadcast, index, &mac);
}
list.push_back(ni);
@@ -1017,6 +1045,7 @@ NetworkInterface::Map NetworkInterface::map(bool ipOnly, bool upOnly)
std::string name;
std::string displayName;
+ std::string adapterName(pAddress->AdapterName);
#ifdef POCO_WIN32_UTF8
Poco::UnicodeConverter::toUTF8(pAddress->FriendlyName, name);
Poco::UnicodeConverter::toUTF8(pAddress->Description, displayName);
@@ -1033,7 +1062,7 @@ NetworkInterface::Map NetworkInterface::map(bool ipOnly, bool upOnly)
bool isIP = (0 != pAddress->FirstUnicastAddress);
if (((ipOnly && isIP) || !ipOnly) && ((upOnly && isUp) || !upOnly))
{
- NetworkInterface ni(name, displayName, ifIndex);
+ NetworkInterface ni(name, displayName, adapterName, ifIndex);
// Create interface even if it has an empty list of addresses; also, set
// physical attributes which are protocol independent (name, media type,
// MAC address, MTU, operational status, etc).
@@ -1149,7 +1178,7 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
{
bcst = IPAddress(std::string(ifAddr));
}
- result.push_back(NetworkInterface(name, name, addr, mask, bcst));
+ result.push_back(NetworkInterface(name, name, name, addr, mask, bcst));
ifIndex++;
}
else break;
@@ -1207,6 +1236,7 @@ void setInterfaceParams(struct ifaddrs* iface, NetworkInterfaceImpl& impl)
struct sockaddr_dl* sdl = (struct sockaddr_dl*) iface->ifa_addr;
impl.setName(iface->ifa_name);
impl.setDisplayName(iface->ifa_name);
+ impl.setAdapterName(iface->ifa_name);
impl.setPhyParams();
impl.setMACAddress(LLADDR(sdl), sdl->sdl_alen);
@@ -1363,6 +1393,7 @@ void setInterfaceParams(struct ifaddrs* iface, NetworkInterfaceImpl& impl)
struct sockaddr_ll* sdl = (struct sockaddr_ll*) iface->ifa_addr;
impl.setName(iface->ifa_name);
impl.setDisplayName(iface->ifa_name);
+ impl.setAdapterName(iface->ifa_name);
impl.setPhyParams();
impl.setMACAddress(sdl->sll_addr, sdl->sll_halen);
@@ -1555,7 +1586,7 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
if (haveAddr)
{
std::string name(ifr->ifr_name);
- result.push_back(NetworkInterface(name, name, addr, ifIndex));
+ result.push_back(NetworkInterface(name, name, name, addr, ifIndex));
}
len += sizeof(ifr->ifr_name);
ptr += len;
Something went wrong with that request. Please try again.