Skip to content

Commit f4bd7c2

Browse files
authored
Fix compile with -DPOCO_NET_NO_IPv6 (pocoproject#4021)
1 parent 1211613 commit f4bd7c2

File tree

5 files changed

+66
-31
lines changed

5 files changed

+66
-31
lines changed

Net/include/Poco/Net/HTTPClientSession.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,10 @@ class Net_API HTTPClientSession: public HTTPSession
164164
const SocketAddress& getSourceAddress4();
165165
/// Returns the last IPv4 source address set with setSourceAddress
166166

167+
#if defined(POCO_HAVE_IPv6)
167168
const SocketAddress& getSourceAddress6();
168169
/// Returns the last IPV6 source address set with setSourceAddress
169-
170+
#endif // POCO_HAVE_IPv6
170171
void setProxy(const std::string& host, Poco::UInt16 port = HTTPSession::HTTP_PORT);
171172
/// Sets the proxy host name and port number.
172173

@@ -371,7 +372,9 @@ class Net_API HTTPClientSession: public HTTPSession
371372
Poco::UInt16 _port;
372373
SocketAddress _sourceAddress;
373374
SocketAddress _sourceAddress4;
375+
#if defined(POCO_HAVE_IPv6)
374376
SocketAddress _sourceAddress6;
377+
#endif // POCO_HAVE_IPv6
375378
ProxyConfig _proxyConfig;
376379
Poco::Timespan _keepAliveTimeout;
377380
Poco::Timestamp _lastRequest;

Net/include/Poco/Net/IPAddress.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,13 @@ class Net_API IPAddress
6060
using RawIP = std::vector<unsigned char>;
6161

6262
static const unsigned IPv4Size = sizeof(in_addr);
63+
#if defined(POCO_HAVE_IPv6)
6364
static const unsigned IPv6Size = sizeof(in6_addr);
65+
#endif
6466
using RawIPv4 = std::array<unsigned char, IPv4Size>;
67+
#if defined(POCO_HAVE_IPv6)
6568
using RawIPv6 = std::array<unsigned char, IPv6Size>;
69+
#endif // POCO_HAVE_IPv6
6670

6771
// The following declarations keep the Family type
6872
// backwards compatible with the previously used
@@ -71,7 +75,7 @@ class Net_API IPAddress
7175
static const Family IPv4 = AddressFamily::IPv4;
7276
#if defined(POCO_HAVE_IPv6)
7377
static const Family IPv6 = AddressFamily::IPv6;
74-
#endif
78+
#endif // POCO_HAVE_IPv6
7579

7680
IPAddress();
7781
/// Creates a wildcard (zero) IPv4 IPAddress.
@@ -137,9 +141,13 @@ class Net_API IPAddress
137141
/// Move-assigns an IPAddress.
138142

139143
bool isV4() const;
144+
#if defined(POCO_HAVE_IPv6)
140145
bool isV6() const;
146+
#endif // POCO_HAVE_IPv6
141147
RawIPv4 toV4Bytes() const;
148+
#if defined(POCO_HAVE_IPv6)
142149
RawIPv6 toV6Bytes() const;
150+
#endif // POCO_HAVE_IPv6
143151
RawIP toBytes() const;
144152

145153
Family family() const;
@@ -398,7 +406,7 @@ class Net_API IPAddress
398406
void newIPv6(unsigned prefix);
399407
static std::string& compressV6(std::string& v6addr);
400408
static std::string trimIPv6(const std::string v6Addr);
401-
#endif
409+
#endif // POCO_HAVE_IPv6
402410
Ptr _pImpl;
403411
};
404412

@@ -412,12 +420,12 @@ inline bool IPAddress::isV4() const
412420
return family() == IPv4;
413421
}
414422

415-
423+
#if defined(POCO_HAVE_IPv6)
416424
inline bool IPAddress::isV6() const
417425
{
418426
return family() == IPv6;
419427
}
420-
428+
#endif // POCO_HAVE_IPv6
421429

422430
inline IPAddress::Ptr IPAddress::pImpl() const
423431
{

Net/src/DatagramSocket.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,16 @@ DatagramSocket::DatagramSocket(SocketAddress::Family family): Socket(new Datagra
3737
DatagramSocket::DatagramSocket(const SocketAddress& address, bool reuseAddress, bool reusePort, bool ipV6Only):
3838
Socket(new DatagramSocketImpl(address.family()))
3939
{
40+
#if defined(POCO_HAVE_IPv6)
4041
if (address.family() == SocketAddress::IPv6)
42+
{
4143
bind6(address, reuseAddress, reusePort, ipV6Only);
42-
else bind(address, reuseAddress, reusePort);
44+
}
45+
else
46+
#endif // POCO_HAVE_IPv6
47+
{
48+
bind(address, reuseAddress, reusePort);
49+
}
4350
}
4451

4552

Net/src/HTTPClientSession.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ HTTPClientSession::ProxyConfig HTTPClientSession::_globalProxyConfig;
4141
HTTPClientSession::HTTPClientSession():
4242
_port(HTTPSession::HTTP_PORT),
4343
_sourceAddress4(IPAddress::wildcard(IPAddress::IPv4), 0),
44+
#if defined(POCO_HAVE_IPv6)
4445
_sourceAddress6(IPAddress::wildcard(IPAddress::IPv6), 0),
46+
#endif // POCO_HAVE_IPv6
4547
_proxyConfig(_globalProxyConfig),
4648
_keepAliveTimeout(DEFAULT_KEEP_ALIVE_TIMEOUT, 0),
4749
_reconnect(false),
@@ -57,7 +59,9 @@ HTTPClientSession::HTTPClientSession(const StreamSocket& socket):
5759
HTTPSession(socket),
5860
_port(HTTPSession::HTTP_PORT),
5961
_sourceAddress4(IPAddress::wildcard(IPAddress::IPv4), 0),
62+
#if defined(POCO_HAVE_IPv6)
6063
_sourceAddress6(IPAddress::wildcard(IPAddress::IPv6), 0),
64+
#endif // POCO_HAVE_IPv6
6165
_proxyConfig(_globalProxyConfig),
6266
_keepAliveTimeout(DEFAULT_KEEP_ALIVE_TIMEOUT, 0),
6367
_reconnect(false),
@@ -73,7 +77,9 @@ HTTPClientSession::HTTPClientSession(const SocketAddress& address):
7377
_host(address.host().toString()),
7478
_port(address.port()),
7579
_sourceAddress4(IPAddress::wildcard(IPAddress::IPv4), 0),
80+
#if defined(POCO_HAVE_IPv6)
7681
_sourceAddress6(IPAddress::wildcard(IPAddress::IPv6), 0),
82+
#endif // POCO_HAVE_IPv6
7783
_proxyConfig(_globalProxyConfig),
7884
_keepAliveTimeout(DEFAULT_KEEP_ALIVE_TIMEOUT, 0),
7985
_reconnect(false),
@@ -89,7 +95,9 @@ HTTPClientSession::HTTPClientSession(const std::string& host, Poco::UInt16 port)
8995
_host(host),
9096
_port(port),
9197
_sourceAddress4(IPAddress::wildcard(IPAddress::IPv4), 0),
98+
#if defined(POCO_HAVE_IPv6)
9299
_sourceAddress6(IPAddress::wildcard(IPAddress::IPv6), 0),
100+
#endif // POCO_HAVE_IPv6
93101
_proxyConfig(_globalProxyConfig),
94102
_keepAliveTimeout(DEFAULT_KEEP_ALIVE_TIMEOUT, 0),
95103
_reconnect(false),
@@ -119,7 +127,9 @@ HTTPClientSession::HTTPClientSession(const StreamSocket& socket, const ProxyConf
119127
HTTPSession(socket),
120128
_port(HTTPSession::HTTP_PORT),
121129
_sourceAddress4(IPAddress::wildcard(IPAddress::IPv4), 0),
130+
#if defined(POCO_HAVE_IPv6)
122131
_sourceAddress6(IPAddress::wildcard(IPAddress::IPv6), 0),
132+
#endif // POCO_HAVE_IPv6
123133
_proxyConfig(proxyConfig),
124134
_keepAliveTimeout(DEFAULT_KEEP_ALIVE_TIMEOUT, 0),
125135
_reconnect(false),
@@ -159,8 +169,10 @@ void HTTPClientSession::setSourceAddress(const SocketAddress& address)
159169
{
160170
if (address.family() == IPAddress::IPv4)
161171
_sourceAddress4 = address;
172+
#if defined(POCO_HAVE_IPv6)
162173
else
163174
_sourceAddress6 = address;
175+
#endif // POCO_HAVE_IPv6
164176
_sourceAddress = address;
165177
}
166178
else
@@ -180,11 +192,12 @@ const SocketAddress& HTTPClientSession::getSourceAddress4()
180192
}
181193

182194

195+
#if defined(POCO_HAVE_IPv6)
183196
const SocketAddress& HTTPClientSession::getSourceAddress6()
184197
{
185198
return _sourceAddress6;
186199
}
187-
200+
#endif // POCO_HAVE_IPv6
188201

189202
void HTTPClientSession::setProxy(const std::string& host, Poco::UInt16 port)
190203
{
@@ -465,8 +478,10 @@ void HTTPClientSession::reconnect()
465478

466479
if ((!_sourceAddress4.host().isWildcard()) || (_sourceAddress4.port() != 0))
467480
connect(addr, _sourceAddress4);
481+
#if defined(POCO_HAVE_IPv6)
468482
else if ((!_sourceAddress6.host().isWildcard()) || (_sourceAddress6.port() != 0))
469483
connect(addr, _sourceAddress6);
484+
#endif // POCO_HAVE_IPv6
470485
else
471486
connect(addr);
472487
}
@@ -596,7 +611,9 @@ StreamSocket HTTPClientSession::proxyConnect()
596611
proxySession.proxyAuthenticateImpl(proxyRequest, _proxyConfig);
597612
proxySession.setKeepAlive(true);
598613
proxySession.setSourceAddress(_sourceAddress4);
614+
#if defined(POCO_HAVE_IPv6)
599615
proxySession.setSourceAddress(_sourceAddress6);
616+
#endif // POCO_HAVE_IPv6
600617
proxySession.sendRequest(proxyRequest);
601618
proxySession.receiveResponse(proxyResponse);
602619
if (proxyResponse.getStatus() != HTTPResponse::HTTP_OK)

0 commit comments

Comments
 (0)