Skip to content

Commit

Permalink
Merge pull request satoruhiga#6 from sphaero/nicslist
Browse files Browse the repository at this point in the history
added getNetworkInterfaces method
  • Loading branch information
Machiel Veltkamp authored May 16, 2018
2 parents 08b8aa2 + 5677184 commit 2407d3c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
51 changes: 45 additions & 6 deletions src/ofxNatNet.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#include "ofxNatNet.h"

#include <Poco/Net/SocketAddress.h>
#include <Poco/Net/DatagramSocket.h>
#include <Poco/Net/MulticastSocket.h>
#include <Poco/Net/NetworkInterface.h>
#include <Poco/Net/NetException.h>

const int impl_major = 2;
const int impl_minor = 9;

Expand Down Expand Up @@ -1131,3 +1125,48 @@ void ofxNatNet::debugDraw()
debugDrawInformation();
}

map<string, Poco::Net::IPAddress> ofxNatNet::getNetworkInterfaces()
{
map<string, Poco::Net::IPAddress> ret;

Poco::Net::NetworkInterface::Map m = Poco::Net::NetworkInterface::map(true, true);
assert (!m.empty());
for (Poco::Net::NetworkInterface::Map::const_iterator it = m.begin(); it != m.end(); ++it)
{
std::cout << std::endl << "=============" << std::endl;

std::cout << "Index: " << it->second.index() << std::endl;
std::cout << "Name: " << it->second.name() << std::endl;
std::cout << "DisplayName: " << it->second.displayName() << std::endl;
std::cout << "Status: " << (it->second.isUp() ? "Up" : "Down") << std::endl;

Poco::Net::NetworkInterface::MACAddress mac(it->second.macAddress());
if (!mac.empty() && (it->second.type() != Poco::Net::NetworkInterface::NI_TYPE_SOFTWARE_LOOPBACK))
std::cout << "MAC Address: (" << it->second.type() << ") " << mac << std::endl;

typedef Poco::Net::NetworkInterface::AddressList List;

const List& ipList = it->second.addressList();
List::const_iterator ipIt = ipList.begin();
List::const_iterator ipEnd = ipList.end();
for (int counter = 0; ipIt != ipEnd; ++ipIt, ++counter)
{
int fam = ipIt->get<Poco::Net::NetworkInterface::IP_ADDRESS>().family();

std::cout << std::endl << "----------" << std::endl;
std::cout << "Address " << counter << std::endl;
std::cout << "----------" << std::endl;
std::cout << "Family: " << fam << std::endl;
std::cout << "Address: " << ipIt->get<Poco::Net::NetworkInterface::IP_ADDRESS>() << std::endl;
Poco::Net::IPAddress addr = ipIt->get<Poco::Net::NetworkInterface::SUBNET_MASK>();
if (!addr.isWildcard()) std::cout << "Subnet: " << addr << " (/" << addr.prefixLength() << ")" << ")" << std::endl;
addr = ipIt->get<Poco::Net::NetworkInterface::BROADCAST_ADDRESS>();
if (!addr.isWildcard()) std::cout << "Broadcast: " << addr << std::endl;
if (fam == Poco::Net::AddressFamily::IPv4)
{
ret[it->second.name()] = ipIt->get<Poco::Net::NetworkInterface::IP_ADDRESS>();
}
}
}
return ret;
}
6 changes: 6 additions & 0 deletions src/ofxNatNet.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#pragma once

#include "ofMain.h"
#include <Poco/Net/SocketAddress.h>
#include <Poco/Net/DatagramSocket.h>
#include <Poco/Net/MulticastSocket.h>
#include <Poco/Net/NetworkInterface.h>
#include <Poco/Net/NetException.h>

class ofxNatNet
{
Expand Down Expand Up @@ -174,6 +179,7 @@ class ofxNatNet
inline const vector<RigidBodyDescription> getRigidBodyDescriptions() { return rigidbody_descs; }
inline const vector<SkeletonDescription> getSkeletonDescriptions() { return skeleton_descs; }

static map<string, Poco::Net::IPAddress> getNetworkInterfaces();
protected:
InternalThread* thread;

Expand Down

0 comments on commit 2407d3c

Please sign in to comment.