mirror of
https://github.com/pocoproject/poco.git
synced 2025-05-03 15:58:23 +02:00
NetworkInterface Solaris support
This commit is contained in:
parent
5568621020
commit
08a788a41c
@ -112,7 +112,11 @@ void Net_API uninitializeNetwork();
|
|||||||
|
|
||||||
#if !defined(s6_addr32)
|
#if !defined(s6_addr32)
|
||||||
#if defined(POCO_OS_FAMILY_UNIX)
|
#if defined(POCO_OS_FAMILY_UNIX)
|
||||||
#define s6_addr32 __u6_addr.__u6_addr32
|
#if (POCO_OS == POCO_OS_SOLARIS)
|
||||||
|
#define s6_addr32 _S6_un._S6_u32
|
||||||
|
#else
|
||||||
|
#define s6_addr32 __u6_addr.__u6_addr32
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -63,7 +63,6 @@ namespace Net {
|
|||||||
// NetworkInterfaceImpl
|
// NetworkInterfaceImpl
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
class NetworkInterfaceImpl: public Poco::RefCountedObject
|
class NetworkInterfaceImpl: public Poco::RefCountedObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -108,9 +107,6 @@ public:
|
|||||||
bool running() const;
|
bool running() const;
|
||||||
bool up() const;
|
bool up() const;
|
||||||
|
|
||||||
protected:
|
|
||||||
~NetworkInterfaceImpl();
|
|
||||||
|
|
||||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||||
void setFlags(DWORD flags, DWORD iftype);
|
void setFlags(DWORD flags, DWORD iftype);
|
||||||
#else
|
#else
|
||||||
@ -121,8 +117,11 @@ protected:
|
|||||||
void setMtu(unsigned mtu);
|
void setMtu(unsigned mtu);
|
||||||
void setType(Type type);
|
void setType(Type type);
|
||||||
void setIndex(unsigned index);
|
void setIndex(unsigned index);
|
||||||
void getPhyParams();
|
void setPhyParams();
|
||||||
void getPeerAddress();
|
void setPeerAddress();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
~NetworkInterfaceImpl();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string _name;
|
std::string _name;
|
||||||
@ -164,8 +163,8 @@ NetworkInterfaceImpl::NetworkInterfaceImpl(const std::string& name, const std::s
|
|||||||
_mtu(0)
|
_mtu(0)
|
||||||
{
|
{
|
||||||
_addressList.push_back(AddressTuple(address, IPAddress(), IPAddress()));
|
_addressList.push_back(AddressTuple(address, IPAddress(), IPAddress()));
|
||||||
getPhyParams();
|
setPhyParams();
|
||||||
if (_pointToPoint) getPeerAddress();
|
if (_pointToPoint) setPeerAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -181,8 +180,8 @@ NetworkInterfaceImpl::NetworkInterfaceImpl(const std::string& name, const std::s
|
|||||||
_running(false),
|
_running(false),
|
||||||
_mtu(0)
|
_mtu(0)
|
||||||
{
|
{
|
||||||
getPhyParams();
|
setPhyParams();
|
||||||
if (_pointToPoint) getPeerAddress();
|
if (_pointToPoint) setPeerAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -199,12 +198,12 @@ NetworkInterfaceImpl::NetworkInterfaceImpl(const std::string& name, const std::s
|
|||||||
_mtu(0)
|
_mtu(0)
|
||||||
{
|
{
|
||||||
_addressList.push_back(AddressTuple(address, subnetMask, broadcastAddress));
|
_addressList.push_back(AddressTuple(address, subnetMask, broadcastAddress));
|
||||||
getPhyParams();
|
setPhyParams();
|
||||||
if (_pointToPoint) getPeerAddress();
|
if (_pointToPoint) setPeerAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void NetworkInterfaceImpl::getPhyParams()
|
void NetworkInterfaceImpl::setPhyParams()
|
||||||
{
|
{
|
||||||
#if !defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_VXWORKS)
|
#if !defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_VXWORKS)
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
@ -220,7 +219,7 @@ void NetworkInterfaceImpl::getPhyParams()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void NetworkInterfaceImpl::getPeerAddress()
|
void NetworkInterfaceImpl::setPeerAddress()
|
||||||
{
|
{
|
||||||
AddressList::iterator it = _addressList.begin();
|
AddressList::iterator it = _addressList.begin();
|
||||||
AddressList::iterator end = _addressList.end();
|
AddressList::iterator end = _addressList.end();
|
||||||
@ -948,9 +947,10 @@ NetworkInterface::Map NetworkInterface::map(bool ipOnly, bool upOnly)
|
|||||||
#endif
|
#endif
|
||||||
DWORD dwRetVal = 0;
|
DWORD dwRetVal = 0;
|
||||||
ULONG iterations = 0;
|
ULONG iterations = 0;
|
||||||
PIP_ADAPTER_ADDRESSES pAddress = reinterpret_cast<IP_ADAPTER_ADDRESSES*>(memory.begin());
|
PIP_ADAPTER_ADDRESSES pAddress = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
pAddress = reinterpret_cast<IP_ADAPTER_ADDRESSES*>(memory.begin()); // leave in the loop, begin may change after resize
|
||||||
poco_assert (memory.capacity() >= outBufLen);
|
poco_assert (memory.capacity() >= outBufLen);
|
||||||
if (ERROR_BUFFER_OVERFLOW == (dwRetVal = GetAdaptersAddresses(family, flags, 0, pAddress, &outBufLen)))
|
if (ERROR_BUFFER_OVERFLOW == (dwRetVal = GetAdaptersAddresses(family, flags, 0, pAddress, &outBufLen)))
|
||||||
memory.resize(outBufLen); // adjust size and try again
|
memory.resize(outBufLen); // adjust size and try again
|
||||||
@ -1048,7 +1048,9 @@ NetworkInterface::Map NetworkInterface::map(bool ipOnly, bool upOnly)
|
|||||||
// VxWorks
|
// VxWorks
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#error TODO
|
||||||
|
|
||||||
|
/*
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
namespace Net {
|
namespace Net {
|
||||||
|
|
||||||
@ -1094,11 +1096,11 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
|
|||||||
|
|
||||||
|
|
||||||
} } // namespace Poco::Net
|
} } // namespace Poco::Net
|
||||||
|
*/
|
||||||
|
|
||||||
|
#elif defined(POCO_OS_FAMILY_BSD) || (POCO_OS == POCO_OS_QNX) || (POCO_OS == POCO_OS_SOLARIS)
|
||||||
#elif defined(POCO_OS_FAMILY_BSD) || POCO_OS == POCO_OS_QNX
|
|
||||||
//
|
//
|
||||||
// BSD variants
|
// BSD variants, QNX and Solaris
|
||||||
//
|
//
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
@ -1106,7 +1108,7 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
|
|||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#include <net/if_dl.h>
|
#include <net/if_dl.h>
|
||||||
#include <net/if_types.h>
|
#include <net/if_types.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
namespace Net {
|
namespace Net {
|
||||||
@ -1114,7 +1116,7 @@ namespace Net {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
static NetworkInterface::Type fromNative(u_char nativeType)
|
NetworkInterface::Type fromNative(u_char nativeType)
|
||||||
{
|
{
|
||||||
switch (nativeType)
|
switch (nativeType)
|
||||||
{
|
{
|
||||||
@ -1124,11 +1126,24 @@ static NetworkInterface::Type fromNative(u_char nativeType)
|
|||||||
case IFT_PPP: return NetworkInterface::NI_TYPE_PPP;
|
case IFT_PPP: return NetworkInterface::NI_TYPE_PPP;
|
||||||
case IFT_LOOP: return NetworkInterface::NI_TYPE_SOFTWARE_LOOPBACK;
|
case IFT_LOOP: return NetworkInterface::NI_TYPE_SOFTWARE_LOOPBACK;
|
||||||
case IFT_ATM: return NetworkInterface::NI_TYPE_ATM;
|
case IFT_ATM: return NetworkInterface::NI_TYPE_ATM;
|
||||||
|
#if (POCO_OS != POCO_OS_SOLARIS)
|
||||||
case IFT_IEEE1394: return NetworkInterface::NI_TYPE_IEEE1394;
|
case IFT_IEEE1394: return NetworkInterface::NI_TYPE_IEEE1394;
|
||||||
|
#endif
|
||||||
default: return NetworkInterface::NI_TYPE_OTHER;
|
default: return NetworkInterface::NI_TYPE_OTHER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.setPhyParams();
|
||||||
|
|
||||||
|
impl.setMACAddress(LLADDR(sdl), sdl->sdl_alen);
|
||||||
|
impl.setType(fromNative(sdl->sdl_type));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1156,26 +1171,26 @@ NetworkInterface::Map NetworkInterface::map(bool ipOnly, bool upOnly)
|
|||||||
unsigned family = currIface->ifa_addr->sa_family;
|
unsigned family = currIface->ifa_addr->sa_family;
|
||||||
switch (family)
|
switch (family)
|
||||||
{
|
{
|
||||||
|
#if defined(POCO_OS_FAMILY_BSD)
|
||||||
case AF_LINK:
|
case AF_LINK:
|
||||||
{
|
|
||||||
struct sockaddr_dl* sdl = (struct sockaddr_dl*) currIface->ifa_addr;
|
|
||||||
ifIndex = sdl->sdl_index;
|
ifIndex = sdl->sdl_index;
|
||||||
intf = NetworkInterface(ifIndex);
|
if ((result.find(ifIndex) == result.end()) && ((upOnly && intf.isUp()) || !upOnly))
|
||||||
intf.impl().setName(currIface->ifa_name);
|
{
|
||||||
intf.impl().setDisplayName(currIface->ifa_name);
|
intf = NetworkInterface(ifIndex);
|
||||||
intf.impl().getPhyParams();
|
setInterfaceParams(currIface, intf.impl());
|
||||||
|
|
||||||
intf.impl().setMACAddress(LLADDR(sdl), sdl->sdl_alen);
|
|
||||||
intf.impl().setType(fromNative(sdl->sdl_type));
|
|
||||||
|
|
||||||
if ((upOnly && intf.isUp()) || !upOnly)
|
|
||||||
ifIt = result.insert(Map::value_type(ifIndex, intf)).first;
|
ifIt = result.insert(Map::value_type(ifIndex, intf)).first;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
#endif
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
ifIndex = if_nametoindex(currIface->ifa_name);
|
ifIndex = if_nametoindex(currIface->ifa_name);
|
||||||
ifIt = result.find(ifIndex);
|
ifIt = result.find(ifIndex);
|
||||||
|
if ((ifIt == result.end()) && ((upOnly && intf.isUp()) || !upOnly))
|
||||||
|
{
|
||||||
|
intf = NetworkInterface(ifIndex);
|
||||||
|
setInterfaceParams(currIface, intf.impl());
|
||||||
|
ifIt = result.insert(Map::value_type(ifIndex, intf)).first;
|
||||||
|
}
|
||||||
|
|
||||||
address = IPAddress(*(currIface->ifa_addr));
|
address = IPAddress(*(currIface->ifa_addr));
|
||||||
subnetMask = IPAddress(*(currIface->ifa_netmask));
|
subnetMask = IPAddress(*(currIface->ifa_netmask));
|
||||||
@ -1191,8 +1206,15 @@ NetworkInterface::Map NetworkInterface::map(bool ipOnly, bool upOnly)
|
|||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
ifIndex = if_nametoindex(currIface->ifa_name);
|
ifIndex = if_nametoindex(currIface->ifa_name);
|
||||||
ifIt = result.find(ifIndex);
|
ifIt = result.find(ifIndex);
|
||||||
|
if ((ifIt == result.end()) && ((upOnly && intf.isUp()) || !upOnly))
|
||||||
|
{
|
||||||
|
intf = NetworkInterface(ifIndex);
|
||||||
|
setInterfaceParams(currIface, intf.impl());
|
||||||
|
ifIt = result.insert(Map::value_type(ifIndex, intf)).first;
|
||||||
|
}
|
||||||
|
|
||||||
address = IPAddress(&reinterpret_cast<const struct sockaddr_in6*>(currIface->ifa_addr)->sin6_addr, sizeof(struct in6_addr), ifIndex);
|
address = IPAddress(&reinterpret_cast<const struct sockaddr_in6*>(currIface->ifa_addr)->sin6_addr,
|
||||||
|
sizeof(struct in6_addr), ifIndex);
|
||||||
subnetMask = IPAddress(*(currIface->ifa_netmask));
|
subnetMask = IPAddress(*(currIface->ifa_netmask));
|
||||||
broadcastAddress = IPAddress();
|
broadcastAddress = IPAddress();
|
||||||
break;
|
break;
|
||||||
@ -1295,7 +1317,7 @@ NetworkInterface::Map NetworkInterface::map(bool ipOnly, bool upOnly)
|
|||||||
intf = NetworkInterface(ifIndex);
|
intf = NetworkInterface(ifIndex);
|
||||||
intf.impl().setName(iface->ifa_name);
|
intf.impl().setName(iface->ifa_name);
|
||||||
intf.impl().setDisplayName(iface->ifa_name);
|
intf.impl().setDisplayName(iface->ifa_name);
|
||||||
intf.impl().getPhyParams();
|
intf.impl().setPhyParams();
|
||||||
|
|
||||||
intf.impl().setMACAddress(sll->sll_addr, sll->sll_halen);
|
intf.impl().setMACAddress(sll->sll_addr, sll->sll_halen);
|
||||||
intf.impl().setType(fromNative(sll->sll_hatype));
|
intf.impl().setType(fromNative(sll->sll_hatype));
|
||||||
@ -1361,12 +1383,8 @@ NetworkInterface::Map NetworkInterface::map(bool ipOnly, bool upOnly)
|
|||||||
//
|
//
|
||||||
// Non-BSD Unix variants
|
// Non-BSD Unix variants
|
||||||
//
|
//
|
||||||
|
#error TODO
|
||||||
|
/*
|
||||||
namespace Poco {
|
|
||||||
namespace Net {
|
|
||||||
|
|
||||||
|
|
||||||
NetworkInterface::NetworkInterfaceList NetworkInterface::list()
|
NetworkInterface::NetworkInterfaceList NetworkInterface::list()
|
||||||
{
|
{
|
||||||
FastMutex::ScopedLock lock(_mutex);
|
FastMutex::ScopedLock lock(_mutex);
|
||||||
@ -1446,7 +1464,7 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
|
|||||||
delete [] buf;
|
delete [] buf;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
} } // namespace Poco::Net
|
} } // namespace Poco::Net
|
||||||
|
|
||||||
|
@ -68,4 +68,4 @@ SYSFLAGS = -D_XOPEN_SOURCE=500 -D_REENTRANT -D_THREAD_SAFE -D_FILE_OFFSET_BITS=6
|
|||||||
#
|
#
|
||||||
# System Specific Libraries
|
# System Specific Libraries
|
||||||
#
|
#
|
||||||
SYSLIBS = -lpthread -ldl -lrt
|
SYSLIBS = -lpthread -lrt -lxnet -lsocket -lnsl -lresolv -ldl
|
||||||
|
Loading…
x
Reference in New Issue
Block a user