From: bert hubert Date: Tue, 11 Jun 2013 15:17:52 +0000 (+0200) Subject: wait what I don't even this code, my eyes! Built in webserver can now listen on IPv6... X-Git-Tag: auth-3.3-rc2~47 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3640473d0a6ab127d0d1563fc52f479ac8e53e00;p=thirdparty%2Fpdns.git wait what I don't even this code, my eyes! Built in webserver can now listen on IPv6, fixes #843 Also silences some useless messages about timeouts. --- diff --git a/pdns/session.cc b/pdns/session.cc index 13059abe6b..2fcbd80be7 100644 --- a/pdns/session.cc +++ b/pdns/session.cc @@ -26,6 +26,7 @@ #include #include #include "misc.hh" +#include "iputils.hh" void Session::init() { @@ -284,54 +285,24 @@ Session *Server::accept() return new Session(clisock, remote); } - - -Server::Server(int p, const string &p_localaddress) +Server::Server(int port, const string &localaddress) { - d_localaddress="0.0.0.0"; - string localaddress=p_localaddress; - port=p; - - struct sockaddr_in local; - s=socket(AF_INET,SOCK_STREAM,0); - Utility::setCloseOnExec(s); + d_local = ComboAddress(localaddress.empty() ? "0.0.0.0" : localaddress, port); + s = socket(d_local.sin4.sin_family ,SOCK_STREAM,0); - if(s<0) + if(s < 0) throw Exception(string("socket: ")+strerror(errno)); - - memset(&local,0,sizeof(local)); - - local.sin_family=AF_INET; - - struct hostent *h; - if(localaddress=="") - localaddress=d_localaddress; - - if ( localaddress != "0.0.0.0" ) - { - h=gethostbyname(localaddress.c_str()); - - if(!h) - throw Exception(); - - local.sin_addr.s_addr=*(int*)h->h_addr; - } - else - { - local.sin_addr.s_addr = INADDR_ANY; - } - local.sin_port=htons(port); + Utility::setCloseOnExec(s); int tmp=1; - if(setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char*)&tmp,sizeof tmp)<0) + if(setsockopt(s, SOL_SOCKET, SO_REUSEADDR,(char*)&tmp,sizeof tmp)<0) throw SessionException(string("Setsockopt failed: ")+strerror(errno)); - if(bind(s, (sockaddr*)&local,sizeof(local))<0) - throw SessionException("binding to port "+itoa(port)+string(" on ")+localaddress+": "+strerror(errno)); + if(bind(s, (sockaddr*)&d_local, d_local.getSocklen())<0) + throw SessionException("binding to "+d_local.toStringWithPort()+": "+strerror(errno)); if(listen(s,128)<0) - throw SessionException("listen: "+stringerror()); - + throw SessionException("listen: "+stringerror()); } diff --git a/pdns/session.hh b/pdns/session.hh index b9a5a70d75..91ff6aab4c 100644 --- a/pdns/session.hh +++ b/pdns/session.hh @@ -1,6 +1,6 @@ /* PowerDNS Versatile Database Driven Nameserver - Copyright (C) 2002 PowerDNS.COM BV + Copyright (C) 2002 - 2013 PowerDNS.COM BV This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 @@ -34,7 +34,7 @@ # include #endif // WIN32 - +#include "iputils.hh" #include "ahuexception.hh" class SessionException: public AhuException @@ -98,12 +98,12 @@ class Server public: Server(int p, const string &localaddress=""); //!< port on which to listen Session* accept(); //!< Call accept() in an endless loop to accept new connections + ComboAddress d_local; private: int s; int port; int backlog; - string d_localaddress; }; class Exception diff --git a/pdns/webserver.cc b/pdns/webserver.cc index 9eba79c146..97b6fa1d34 100644 --- a/pdns/webserver.cc +++ b/pdns/webserver.cc @@ -177,7 +177,7 @@ void *WebServer::serveConnection(void *p) } catch(SessionTimeoutException &e) { - L<d_local.toStringWithPort() <accept())) { pthread_create(&tid, 0 , &serveConnection, (void *)client); } } catch(SessionTimeoutException &e) { - L<