diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2010-02-23 18:45:26 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2010-02-23 18:45:26 +0000 |
commit | 03a1bf15b1da7643b237c22db1a478916a976ccf (patch) | |
tree | 609b6f51455bb2cf62f56295c388399821e3d998 /src | |
parent | fbb1ebd08b6e4f3322da57884d6c90447bd21460 (diff) |
Replace #define IPV6 with <config defaultbind="ipv6">, and autodetect if not specified
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12550 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/configreader.cpp | 20 | ||||
-rw-r--r-- | src/listensocket.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_spanningtree/capab.cpp | 5 | ||||
-rw-r--r-- | src/socket.cpp | 51 |
4 files changed, 37 insertions, 41 deletions
diff --git a/src/configreader.cpp b/src/configreader.cpp index 6f576fcd7..1905b36d0 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -22,7 +22,7 @@ ServerConfig::ServerConfig() { WhoWasGroupSize = WhoWasMaxGroups = WhoWasMaxKeep = 0; NoUserDns = OperSpyWhois = HideBans = HideSplits = UndernetMsgPrefix = false; - CycleHosts = InvBypassModes = true; + WildcardIPv6 = CycleHosts = InvBypassModes = true; dns_timeout = 5; MaxTargets = 20; NetBufferSize = 10240; @@ -498,6 +498,24 @@ void ServerConfig::Fill() if (!sid.empty() && !ServerInstance->IsSID(sid)) throw CoreException(sid + " is not a valid server ID. A server ID must be 3 characters long, with the first character a digit and the next two characters a digit or letter."); + std::string defbind = options->getString("defaultbind"); + if (assign(defbind) == "ipv4") + { + WildcardIPv6 = false; + } + else if (assign(defbind) == "ipv6") + { + WildcardIPv6 = true; + } + else + { + WildcardIPv6 = true; + int socktest = socket(AF_INET6, SOCK_STREAM, 0); + if (socktest < 0) + WildcardIPv6 = false; + else + close(socktest); + } ConfigTagList tags = ConfTags("uline"); for(ConfigIter i = tags.first; i != tags.second; ++i) { diff --git a/src/listensocket.cpp b/src/listensocket.cpp index b0fce7b5b..d511d536e 100644 --- a/src/listensocket.cpp +++ b/src/listensocket.cpp @@ -11,8 +11,6 @@ * --------------------------------------------------- */ -/* $Core */ - #include "inspircd.h" #include "socket.h" #include "socketengine.h" diff --git a/src/modules/m_spanningtree/capab.cpp b/src/modules/m_spanningtree/capab.cpp index 1e2fe710a..cb3611d33 100644 --- a/src/modules/m_spanningtree/capab.cpp +++ b/src/modules/m_spanningtree/capab.cpp @@ -124,10 +124,6 @@ void TreeSocket::SendCapabilities(int phase) WriteLine("CAPAB CHANMODES :" + BuildModeList(MODETYPE_CHANNEL)); WriteLine("CAPAB USERMODES :" + BuildModeList(MODETYPE_USER)); - int ip6 = 0; -#ifdef IPV6 - ip6 = 1; -#endif std::string extra; /* Do we have sha256 available? If so, we send a challenge */ if (Utils->ChallengeResponse && (ServerInstance->Modules->Find("m_sha256.so"))) @@ -146,7 +142,6 @@ void TreeSocket::SendCapabilities(int phase) " MAXKICK="+ConvToStr(ServerInstance->Config->Limits.MaxKick)+ " MAXGECOS="+ConvToStr(ServerInstance->Config->Limits.MaxGecos)+ " MAXAWAY="+ConvToStr(ServerInstance->Config->Limits.MaxAway)+ - " IP6NATIVE="+ConvToStr(ip6)+ " IP6SUPPORT=1"+ " PROTOCOL="+ConvToStr(ProtocolVersion)+extra+ " PREFIX="+ServerInstance->Modes->BuildPrefixes()+ diff --git a/src/socket.cpp b/src/socket.cpp index 63b373cce..3ee996193 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -145,13 +145,16 @@ bool irc::sockets::aptosa(const std::string& addr, int port, irc::sockets::socka memset(&sa, 0, sizeof(sa)); if (addr.empty() || addr.c_str()[0] == '*') { -#ifdef IPV6 - sa.in6.sin6_family = AF_INET6; - sa.in6.sin6_port = htons(port); -#else - sa.in4.sin_family = AF_INET; - sa.in4.sin_port = htons(port); -#endif + if (ServerInstance->Config->WildcardIPv6) + { + sa.in6.sin6_family = AF_INET6; + sa.in6.sin6_port = htons(port); + } + else + { + sa.in4.sin_family = AF_INET; + sa.in4.sin_port = htons(port); + } return true; } else if (inet_pton(AF_INET, addr.c_str(), &sa.in4.sin_addr) > 0) @@ -210,35 +213,17 @@ std::string irc::sockets::sockaddrs::str() const char buffer[MAXBUF]; if (sa.sa_family == AF_INET) { -#ifndef IPV6 - if (in4.sin_addr.s_addr == 0) - { - sprintf(buffer, "*:%u", ntohs(in4.sin_port)); - } - else -#endif - { - const uint8_t* bits = reinterpret_cast<const uint8_t*>(&in4.sin_addr); - sprintf(buffer, "%d.%d.%d.%d:%u", bits[0], bits[1], bits[2], bits[3], ntohs(in4.sin_port)); - } + const uint8_t* bits = reinterpret_cast<const uint8_t*>(&in4.sin_addr); + sprintf(buffer, "%d.%d.%d.%d:%u", bits[0], bits[1], bits[2], bits[3], ntohs(in4.sin_port)); } else if (sa.sa_family == AF_INET6) { -#ifdef IPV6 - if (!memcmp(all_zero, &in6.sin6_addr, 16)) - { - sprintf(buffer, "*:%u", ntohs(in6.sin6_port)); - } - else -#endif - { - buffer[0] = '['; - if (!inet_ntop(AF_INET6, &in6.sin6_addr, buffer+1, MAXBUF - 10)) - return "<unknown>"; // should never happen, buffer is large enough - int len = strlen(buffer); - // no need for snprintf, buffer has at least 9 chars left, max short len = 5 - sprintf(buffer + len, "]:%u", ntohs(in6.sin6_port)); - } + buffer[0] = '['; + if (!inet_ntop(AF_INET6, &in6.sin6_addr, buffer+1, MAXBUF - 10)) + return "<unknown>"; // should never happen, buffer is large enough + int len = strlen(buffer); + // no need for snprintf, buffer has at least 9 chars left, max short len = 5 + sprintf(buffer + len, "]:%u", ntohs(in6.sin6_port)); } else return "<unknown>"; |