From: Bert Hubert Date: Thu, 12 Jun 2008 13:39:12 +0000 (+0000) Subject: forgot to commit bind() stuff X-Git-Tag: rec-3.1.7.1~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e76a82e699a1a69b94ab1d735ad350fb359bec5;p=thirdparty%2Fpdns.git forgot to commit bind() stuff git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1192 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/sstuff.hh b/pdns/sstuff.hh index 9c4ef75131..10a004d248 100644 --- a/pdns/sstuff.hh +++ b/pdns/sstuff.hh @@ -136,6 +136,18 @@ public: Utility::setNonBlocking(d_socket); } + //! Bind the socket to a specified endpoint + void bind(const struct sockaddr_in &local) + { + int tmp=1; + if(setsockopt(d_socket,SOL_SOCKET,SO_REUSEADDR,(char*)&tmp,sizeof tmp)<0) + throw NetworkError(string("Setsockopt failed: ")+strerror(errno)); + + if(::bind(d_socket,(struct sockaddr *)&local,sizeof(local))<0) + throw NetworkError(strerror(errno)); + } + + //! Bind the socket to a specified endpoint void bind(const IPEndpoint &ep) { @@ -145,12 +157,7 @@ public: local.sin_addr.s_addr=ep.address.byte; local.sin_port=htons(ep.port); - int tmp=1; - if(setsockopt(d_socket,SOL_SOCKET,SO_REUSEADDR,(char*)&tmp,sizeof tmp)<0) - throw NetworkError(string("Setsockopt failed: ")+strerror(errno)); - - if(::bind(d_socket,(struct sockaddr *)&local,sizeof(local))<0) - throw NetworkError(strerror(errno)); + bind(local); } //! Connect the socket to a specified endpoint