Skip to content

Commit 007659a

Browse files
committed
exclude NetworkInterface where not supported
Exclude NetworkInterface and MulticastSocket on platforms where we do not have network interface detection implemented
1 parent ba70e7f commit 007659a

13 files changed

Lines changed: 96 additions & 8 deletions

Foundation/include/Poco/Platform.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@
102102
#elif defined(__QNX__)
103103
#define POCO_OS_FAMILY_UNIX 1
104104
#define POCO_OS POCO_OS_QNX
105+
#elif defined(__CYGWIN__)
106+
#define POCO_OS_FAMILY_UNIX 1
107+
#define POCO_OS POCO_OS_CYGWIN
108+
#elif defined(POCO_VXWORKS)
109+
#define POCO_OS_FAMILY_UNIX 1
110+
#define POCO_OS POCO_OS_VXWORKS
105111
#elif defined(unix) || defined(__unix) || defined(__unix__)
106112
#define POCO_OS_FAMILY_UNIX 1
107113
#define POCO_OS POCO_OS_UNKNOWN_UNIX
@@ -111,15 +117,9 @@
111117
#elif defined(_WIN32) || defined(_WIN64)
112118
#define POCO_OS_FAMILY_WINDOWS 1
113119
#define POCO_OS POCO_OS_WINDOWS_NT
114-
#elif defined(__CYGWIN__)
115-
#define POCO_OS_FAMILY_UNIX 1
116-
#define POCO_OS POCO_OS_CYGWIN
117120
#elif defined(__VMS)
118121
#define POCO_OS_FAMILY_VMS 1
119122
#define POCO_OS POCO_OS_VMS
120-
#elif defined(POCO_VXWORKS)
121-
#define POCO_OS_FAMILY_UNIX 1
122-
#define POCO_OS POCO_OS_VXWORKS
123123
#endif
124124

125125

Net/include/Poco/Net/MulticastSocket.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141

4242

4343
#include "Poco/Net/Net.h"
44+
45+
46+
#ifdef POCO_NET_HAS_INTERFACE
47+
48+
4449
#include "Poco/Net/DatagramSocket.h"
4550
#include "Poco/Net/NetworkInterface.h"
4651

@@ -135,4 +140,7 @@ class Net_API MulticastSocket: public DatagramSocket
135140
} } // namespace Poco::Net
136141

137142

143+
#endif // POCO_NET_HAS_INTERFACE
144+
145+
138146
#endif // Net_MulticastSocket_INCLUDED

Net/include/Poco/Net/Net.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,12 @@ inline void Net_API uninitializeNetwork();
134134
#endif // POCO_NET_NO_WINDOWS_INIT
135135

136136

137+
//
138+
// Define POCO_NET_HAS_INTERFACE for platforms that have network interface detection implemented.
139+
//
140+
#if defined(POCO_OS_FAMILY_WINDOWS) || (POCO_OS == POCO_OS_LINUX) || defined(POCO_OS_FAMILY_BSD) || (POCO_OS == POCO_OS_SOLARIS) || (POCO_OS == POCO_OS_QNX)
141+
#define POCO_NET_HAS_INTERFACE
142+
#endif
143+
144+
137145
#endif // Net_Net_INCLUDED

Net/include/Poco/Net/NetworkInterface.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141

4242

4343
#include "Poco/Net/Net.h"
44+
45+
46+
#ifdef POCO_NET_HAS_INTERFACE
47+
48+
4449
#include "Poco/Net/IPAddress.h"
4550
#include "Poco/Mutex.h"
4651
#include "Poco/Tuple.h"
@@ -330,4 +335,7 @@ inline bool NetworkInterface::operator == (const NetworkInterface& other) const
330335
Net_API std::ostream& operator<<(std::ostream& os, const Poco::Net::NetworkInterface::MACAddress& mac);
331336

332337

338+
#endif // POCO_NET_HAS_INTERFACE
339+
340+
333341
#endif // Net_NetworkInterface_INCLUDED

Net/src/MulticastSocket.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535

3636

3737
#include "Poco/Net/MulticastSocket.h"
38+
39+
40+
#ifdef POCO_NET_HAS_INTERFACE
41+
42+
3843
#include "Poco/Net/NetException.h"
3944
#include <cstring>
4045

@@ -263,3 +268,6 @@ void MulticastSocket::leaveGroup(const IPAddress& groupAddress, const NetworkInt
263268

264269

265270
} } // namespace Poco::Net
271+
272+
273+
#endif // POCO_NET_HAS_INTERFACE

Net/src/NetworkInterface.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535

3636

3737
#include "Poco/Net/NetworkInterface.h"
38+
39+
40+
#ifdef POCO_NET_HAS_INTERFACE
41+
42+
3843
#include "Poco/Net/DatagramSocket.h"
3944
#include "Poco/Net/NetException.h"
4045
#include "Poco/NumberFormatter.h"
@@ -949,7 +954,7 @@ NetworkInterface::Map NetworkInterface::map(bool ipOnly, bool upOnly)
949954
pAddress = reinterpret_cast<IP_ADAPTER_ADDRESSES*>(memory.begin()); // leave in the loop, begin may change after resize
950955
poco_assert (memory.capacity() >= outBufLen);
951956
if (ERROR_BUFFER_OVERFLOW == (dwRetVal = GetAdaptersAddresses(family, flags, 0, pAddress, &outBufLen)))
952-
memory.resize(outBufLen); // adjust size and try again
957+
memory.resize(outBufLen, false); // adjust size and try again
953958
else if (ERROR_NO_DATA == dwRetVal) // no network interfaces found
954959
return result;
955960
else if (NO_ERROR != dwRetVal) // error occurred
@@ -1540,3 +1545,6 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
15401545

15411546

15421547
#endif
1548+
1549+
1550+
#endif // POCO_NET_HAS_INTERFACE

Net/testsuite/src/MulticastEchoServer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131

3232

3333
#include "MulticastEchoServer.h"
34+
35+
36+
#ifdef POCO_NET_HAS_INTERFACE
37+
38+
3439
#include "Poco/Timespan.h"
3540
#include <iostream>
3641

@@ -120,3 +125,5 @@ Poco::Net::NetworkInterface MulticastEchoServer::findInterface()
120125
}
121126
return NetworkInterface();
122127
}
128+
129+
#endif // POCO_NET_HAS_INTERFACE

Net/testsuite/src/MulticastEchoServer.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737

3838

3939
#include "Poco/Net/Net.h"
40+
41+
42+
#ifdef POCO_NET_HAS_INTERFACE
43+
44+
4045
#include "Poco/Net/MulticastSocket.h"
4146
#include "Poco/Net/SocketAddress.h"
4247
#include "Poco/Net/NetworkInterface.h"
@@ -82,4 +87,7 @@ class MulticastEchoServer: public Poco::Runnable
8287
};
8388

8489

90+
#endif // POCO_NET_HAS_INTERFACE
91+
92+
8593
#endif // MulticastEchoServer_INCLUDED

Net/testsuite/src/MulticastSocketTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131

3232

3333
#include "MulticastSocketTest.h"
34+
35+
36+
#ifdef POCO_NET_HAS_INTERFACE
37+
38+
3439
#include "CppUnit/TestCaller.h"
3540
#include "CppUnit/TestSuite.h"
3641
#include "MulticastEchoServer.h"
@@ -94,3 +99,6 @@ CppUnit::Test* MulticastSocketTest::suite()
9499

95100
return pSuite;
96101
}
102+
103+
104+
#endif // POCO_NET_HAS_INTERFACE

Net/testsuite/src/MulticastSocketTest.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737

3838

3939
#include "Poco/Net/Net.h"
40+
41+
42+
#ifdef POCO_NET_HAS_INTERFACE
43+
44+
4045
#include "CppUnit/TestCase.h"
4146

4247

@@ -57,4 +62,7 @@ class MulticastSocketTest: public CppUnit::TestCase
5762
};
5863

5964

65+
#endif // POCO_NET_HAS_INTERFACE
66+
67+
6068
#endif // MulticastSocketTest_INCLUDED

0 commit comments

Comments
 (0)