mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-18 00:15:27 +01:00
SF 3558085: Add formatter to MACAddress object
This commit is contained in:
parent
84ca64e283
commit
e7f2ade581
@ -26,6 +26,8 @@ Release 1.5.0 (2012-08-??)
|
||||
- UTF portability improvements
|
||||
- fixed SF#3556186: Linux shouldn't use <net/if.h> in Net/SocketDefs.h
|
||||
- added IPAddress RFC 4291 compatible site-local prefix support
|
||||
- fixed SF# 3012166: IPv6 patch
|
||||
- added SF# 3558085: Add formatter to MACAddress object
|
||||
|
||||
Release 1.4.4 (2012-08-??)
|
||||
==========================
|
||||
|
@ -104,6 +104,11 @@ public:
|
||||
};
|
||||
|
||||
static const unsigned NO_INDEX = ~0;
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
static const char MAC_SEPARATOR = '-';
|
||||
#else
|
||||
static const char MAC_SEPARATOR = ':';
|
||||
#endif
|
||||
|
||||
NetworkInterface(unsigned index = NO_INDEX);
|
||||
/// Creates a NetworkInterface representing the
|
||||
@ -318,4 +323,7 @@ inline bool NetworkInterface::operator == (const NetworkInterface& other) const
|
||||
} } // namespace Poco::Net
|
||||
|
||||
|
||||
Net_API std::ostream& operator<<(std::ostream& os, const Poco::Net::NetworkInterface::MACAddress& mac);
|
||||
|
||||
|
||||
#endif // Net_NetworkInterface_INCLUDED
|
||||
|
@ -48,6 +48,8 @@
|
||||
#include <ipifcons.h>
|
||||
#endif
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
|
||||
using Poco::NumberFormatter;
|
||||
@ -55,6 +57,20 @@ using Poco::FastMutex;
|
||||
using Poco::format;
|
||||
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Poco::Net::NetworkInterface::MACAddress& mac)
|
||||
{
|
||||
std::ios state(0);
|
||||
state.copyfmt(os);
|
||||
for (unsigned i = 0; i < mac.size(); ++i)
|
||||
{
|
||||
if (i > 0) os << Poco::Net::NetworkInterface::MAC_SEPARATOR;
|
||||
os << std::hex << std::setw(2) << std::setfill('0') << (unsigned) mac[i];
|
||||
}
|
||||
os.copyfmt(state);
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Net {
|
||||
|
||||
|
@ -69,12 +69,7 @@ void NetworkInterfaceTest::testMap()
|
||||
|
||||
NetworkInterface::MACAddress mac(it->second.macAddress());
|
||||
if (!mac.empty() && (it->second.type() != NetworkInterface::NI_TYPE_SOFTWARE_LOOPBACK))
|
||||
{
|
||||
std::cout << "MAC Address: ";
|
||||
for (unsigned i = 0; i < mac.size(); ++i)
|
||||
std::cout << ((i == 0) ? ' ' : ':') << std::hex << std::setw(2) << std::setfill('0') << (unsigned) mac[i];
|
||||
std::cout << std::dec << std::endl;
|
||||
}
|
||||
std::cout << "MAC Address: " << mac << std::endl;
|
||||
|
||||
typedef NetworkInterface::AddressList List;
|
||||
const List& ipList = it->second.addressList();
|
||||
@ -108,6 +103,11 @@ void NetworkInterfaceTest::testList()
|
||||
std::cout << "Index: " << it->index() << std::endl;
|
||||
std::cout << "Name: " << it->name() << std::endl;
|
||||
std::cout << "DisplayName: " << it->displayName() << std::endl;
|
||||
std::cout << "Status: " << (it->isUp() ? "Up" : "Down") << std::endl;
|
||||
|
||||
NetworkInterface::MACAddress mac(it->macAddress());
|
||||
if (!mac.empty() && (it->type() != NetworkInterface::NI_TYPE_SOFTWARE_LOOPBACK))
|
||||
std::cout << "MAC Address: " << mac << std::endl;
|
||||
|
||||
typedef NetworkInterface::AddressList List;
|
||||
const List& ipList = it->addressList();
|
||||
|
Loading…
x
Reference in New Issue
Block a user