diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-01 15:07:52 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-01 15:07:52 +0000 |
commit | b47228902d585dd16953b7f9bc395553890fc56e (patch) | |
tree | ffc4ed1d4177c2e2f0d10ea01f17c4ea8ee0409a /src/inspsocket.cpp | |
parent | 77d5c9f765702a06a1ad77f239d1cbe2d9b11662 (diff) |
Move IP<->sockaddr conversions into irc::sockets:: namespace
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11580 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/inspsocket.cpp')
-rw-r--r-- | src/inspsocket.cpp | 53 |
1 files changed, 6 insertions, 47 deletions
diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index a23518148..e42990a74 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -53,22 +53,8 @@ BufferedSocket::BufferedSocket(InspIRCd* SI, const std::string &ipaddr, int apor strlcpy(this->host,ipaddr.c_str(),MAXBUF); this->port = aport; - bool ipvalid = true; -#ifdef IPV6 - if (strchr(host,':')) - { - in6_addr n; - if (inet_pton(AF_INET6, host, &n) < 1) - ipvalid = false; - } - else -#endif - { - in_addr n; - if (inet_aton(host,&n) < 1) - ipvalid = false; - } - if (!ipvalid) + irc::sockets::sockaddrs testaddr; + if (!irc::sockets::aptosa(host, aport, &testaddr)) { this->ServerInstance->Logs->Log("SOCKET", DEBUG,"BUG: Hostname passed to BufferedSocket, rather than an IP address!"); this->OnError(I_ERR_CONNECT); @@ -106,40 +92,13 @@ void BufferedSocket::SetQueues() bool BufferedSocket::DoBindMagic(const std::string ¤t_ip, bool v6) { irc::sockets::sockaddrs s; - socklen_t size = sizeof(sockaddr_in); -#ifdef IPV6 - if (v6) + if (!irc::sockets::aptosa(current_ip.c_str(), 0, &s)) { - if (inet_pton(AF_INET6, current_ip.c_str(), &s.in6.sin6_addr) > 0) - { - s.in6.sin6_port = 0; - s.in6.sin6_family = AF_INET6; - size = sizeof(sockaddr_in6); - } - else - { - // Well, this is as good as it's gonna get. - errno = EADDRNOTAVAIL; - return false; - } - } - else -#endif - { - if (inet_aton(current_ip.c_str(), &s.in4.sin_addr) > 0) - { - s.in4.sin_port = 0; - s.in4.sin_family = AF_INET; - } - else - { - // Well, this is as good as it's gonna get. - errno = EADDRNOTAVAIL; - return false; - } + errno = EADDRNOTAVAIL; + return false; } - if (ServerInstance->SE->Bind(this->fd, &s.sa, size) < 0) + if (ServerInstance->SE->Bind(this->fd, &s.sa, sizeof(s)) < 0) { this->state = I_ERROR; this->OnError(I_ERR_BIND); |