summaryrefslogtreecommitdiff
path: root/src/sockets.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2011-04-25 04:17:21 -0400
committerAdam <Adam@anope.org>2011-04-25 04:17:21 -0400
commit4a733c93d45e0ca5d757abf826d65bc1cbaf610e (patch)
treee09f093a9926b4285ea1d33da93828ddd5b6bbcb /src/sockets.cpp
parent03d2378a9fc2fdc868ee4476597ec1901242a0c5 (diff)
Don't attempt to connect to the uplink if given invalid hostnames
Diffstat (limited to 'src/sockets.cpp')
-rw-r--r--src/sockets.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/sockets.cpp b/src/sockets.cpp
index 941169c17..3f334e26e 100644
--- a/src/sockets.cpp
+++ b/src/sockets.cpp
@@ -129,17 +129,27 @@ void sockaddrs::pton(int type, const Anope::string &address, int pport)
switch (type)
{
case AF_INET:
- if (inet_pton(type, address.c_str(), &sa4.sin_addr) < 1)
- throw SocketException(Anope::string("Invalid host: ") + Anope::LastError());
+ {
+ int i = inet_pton(type, address.c_str(), &sa4.sin_addr);
+ if (i == 0)
+ throw SocketException("Invalid host");
+ else if (i <= -1)
+ throw SocketException("Invalid host: " + Anope::LastError());
sa4.sin_family = type;
sa4.sin_port = htons(pport);
return;
+ }
case AF_INET6:
- if (inet_pton(type, address.c_str(), &sa6.sin6_addr) < 1)
- throw SocketException(Anope::string("Invalid host: ") + Anope::LastError());
+ {
+ int i = inet_pton(type, address.c_str(), &sa6.sin6_addr);
+ if (i == 0)
+ throw SocketException("Invalid host");
+ else if (i <= -1)
+ throw SocketException("Invalid host: " + Anope::LastError());
sa6.sin6_family = type;
sa6.sin6_port = htons(pport);
return;
+ }
default:
break;
}