diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-11-11 15:17:40 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-11-11 15:17:40 +0000 |
commit | 69c3a32784b8c638ea10c269c3f63ede86b8aaa0 (patch) | |
tree | ee065fbe0bbeaf3121ff359e2cca3671b426de08 /src/socket.cpp | |
parent | 0b230aa96b81b7a6426e48a509a19699556cf190 (diff) |
Add irc::portparser, a class to parse port ranges in the form "6660,6661,6662-6669,7000".
Needs testing, watch next few commits.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5690 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/socket.cpp')
-rw-r--r-- | src/socket.cpp | 59 |
1 files changed, 12 insertions, 47 deletions
diff --git a/src/socket.cpp b/src/socket.cpp index 560541f4d..b68de7159 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -409,55 +409,20 @@ int InspIRCd::BindPorts(bool bail, int &ports_found) if ((!*Type) || (!strcmp(Type,"clients"))) { - irc::commasepstream portrange(configToken); - std::string portno = "*"; - while ((portno = portrange.GetToken()) != "") + irc::portparser portrange(configToken); + long portno = -1; + while (portno = portrange.GetToken()) { - std::string::size_type dash = portno.rfind('-'); - if (dash != std::string::npos) + if (!HasPort(portno, Addr)) { - this->Log(DEBUG,"Port range, %s", portno.c_str()); - /* Range of ports */ - std::string sbegin = portno.substr(0, dash); - std::string send = portno.substr(dash+1, portno.length()); - long begin = atoi(sbegin.c_str()); - long end = atoi(send.c_str()); - if ((begin < 0) || (end < 0) || (begin > 65535) || (end > 65535) || (begin >= end)) - { - this->Log(DEFAULT,"WARNING: Port range \"%d-%d\" discarded. begin >= end, or begin/end out of range.", begin, end); - } - else - { - for (int portval = begin; portval <= end; ++portval) - { - if (!HasPort(portval, Addr)) - { - ports_found++; - Config->ports[clientportcount+InitialPortCount] = portval; - if (*Addr == '*') - *Addr = 0; - - strlcpy(Config->addrs[clientportcount+InitialPortCount],Addr,256); - clientportcount++; - this->Log(DEBUG,"NEW binding %s:%d [%s] from config (part of port range %s)",Addr, portval, Type, portno.c_str()); - } - } - } - } - else - { - this->Log(DEBUG,"Single port, %s", portno.c_str()); - /* Single port */ - if (!HasPort(atoi(portno.c_str()), Addr)) - { - ports_found++; - Config->ports[clientportcount+InitialPortCount] = atoi(portno.c_str()); - if (*Addr == '*') - *Addr = 0; - strlcpy(Config->addrs[clientportcount+InitialPortCount],Addr,256); - clientportcount++; - this->Log(DEBUG,"NEW binding %s:%s [%s] from config (single port)",Addr, portno.c_str(), Type); - } + ports_found++; + Config->ports[clientportcount+InitialPortCount] = portno; + if (*Addr == '*') + *Addr = 0; + + strlcpy(Config->addrs[clientportcount+InitialPortCount],Addr,256); + clientportcount++; + this->Log(DEBUG,"NEW binding %s:%d [%s] from config",Addr, portno, Type); } } } |