summaryrefslogtreecommitdiff
path: root/src/inspircd_io.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-03-10 11:50:03 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-03-10 11:50:03 +0000
commitda2ad810d29d16446adf5b88f8371704c1c88786 (patch)
treec2f34c7e5120ba9c22e06ae282d709e3005d3d91 /src/inspircd_io.cpp
parentbaa9673d291b9b9a2d7ad0d3aab56487de434502 (diff)
Support for hostnames in <bind> tag (so long as the hostname resolves to a locally bindable ip)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3621 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/inspircd_io.cpp')
-rw-r--r--src/inspircd_io.cpp51
1 files changed, 42 insertions, 9 deletions
diff --git a/src/inspircd_io.cpp b/src/inspircd_io.cpp
index 53f58c4f1..4fa87a5f1 100644
--- a/src/inspircd_io.cpp
+++ b/src/inspircd_io.cpp
@@ -25,6 +25,7 @@ using namespace std;
#include <sstream>
#include <iostream>
#include <fstream>
+#include "message.h"
#include "inspircd.h"
#include "inspircd_io.h"
#include "inspstring.h"
@@ -1303,25 +1304,57 @@ int BindSocket (int sockfd, struct sockaddr_in client, struct sockaddr_in server
{
memset((char *)&server,0,sizeof(server));
struct in_addr addy;
- inet_aton(addr,&addy);
- server.sin_family = AF_INET;
- if (!*addr)
+ bool resolved = false;
+ char resolved_addr[128];
+
+ if (*addr == '*')
+ *addr = 0;
+
+ if (*addr && !inet_aton(addr,&addy))
{
- server.sin_addr.s_addr = htonl(INADDR_ANY);
+ /* If they gave a hostname, bind to the IP it resolves to */
+ if (CleanAndResolve(resolved_addr, addr, true))
+ {
+ inet_aton(resolved_addr,&addy);
+ log(DEFAULT,"Resolved binding '%s' -> '%s'",addr,resolved_addr);
+ server.sin_addr = addy;
+ resolved = true;
+ }
+ else
+ {
+ log(DEFAULT,"WARNING: Could not resolve '%s' to an IP for binding to on port %d",addr,port);
+ return(FALSE);
+ }
}
- else
+ server.sin_family = AF_INET;
+ if (!resolved)
{
- server.sin_addr = addy;
+ if (!*addr)
+ {
+ server.sin_addr.s_addr = htonl(INADDR_ANY);
+ }
+ else
+ {
+ server.sin_addr = addy;
+ }
}
server.sin_port = htons(port);
- if (bind(sockfd,(struct sockaddr*)&server,sizeof(server))<0)
+ if (bind(sockfd,(struct sockaddr*)&server,sizeof(server)) < 0)
{
return(ERROR);
}
else
{
- listen(sockfd, Config->MaxConn);
- return(TRUE);
+ log(DEBUG,"Bound port %s:%d",*addr ? addr : "*",port);
+ if (listen(sockfd, Config->MaxConn) == -1)
+ {
+ log(DEFAULT,"ERROR in listen(): %s",strerror(errno));
+ return(FALSE);
+ }
+ else
+ {
+ return(TRUE);
+ }
}
}