diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-08-01 11:46:19 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-08-01 11:46:19 +0000 |
commit | 4488e477136ea3daa60a744bac272cc37a604136 (patch) | |
tree | 49ec2884832cea192feb6a667f9ec8d352c14199 /src | |
parent | 4789b3f6536ef8267c79c7cb3ee6678546c2150b (diff) |
The IPV6 stuff compiles now, with compile-correct ipv6 code. I dont know if this works yet.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4611 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/channels.cpp | 2 | ||||
-rw-r--r-- | src/cmd_whois.cpp | 2 | ||||
-rw-r--r-- | src/commands.cpp | 2 | ||||
-rw-r--r-- | src/dns.cpp | 49 | ||||
-rw-r--r-- | src/dnsqueue.cpp | 2 | ||||
-rw-r--r-- | src/hashcomp.cpp | 7 | ||||
-rw-r--r-- | src/helperfuncs.cpp | 2 | ||||
-rw-r--r-- | src/inspircd.cpp | 14 | ||||
-rw-r--r-- | src/inspsocket.cpp | 25 | ||||
-rw-r--r-- | src/modules/extra/m_mysql.cpp | 17 | ||||
-rw-r--r-- | src/modules/m_cgiirc.cpp | 16 | ||||
-rw-r--r-- | src/modules/m_check.cpp | 11 | ||||
-rw-r--r-- | src/modules/m_ident.cpp | 6 | ||||
-rw-r--r-- | src/modules/m_spanningtree.cpp | 8 | ||||
-rw-r--r-- | src/modules/m_userip.cpp | 2 | ||||
-rw-r--r-- | src/socket.cpp | 37 | ||||
-rw-r--r-- | src/userprocess.cpp | 14 | ||||
-rw-r--r-- | src/users.cpp | 18 | ||||
-rw-r--r-- | src/xline.cpp | 2 |
19 files changed, 171 insertions, 65 deletions
diff --git a/src/channels.cpp b/src/channels.cpp index 632e198e5..85097684f 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -352,7 +352,7 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri { for (BanList::iterator i = Ptr->bans.begin(); i != Ptr->bans.end(); i++) { - if ((match(user->GetFullHost(),i->data)) || (match(user->GetFullRealHost(),i->data)) || (match((char*)inet_ntoa(user->ip4),i->data))) + if ((match(user->GetFullHost(),i->data)) || (match(user->GetFullRealHost(),i->data)) || (match((char*)insp_ntoa(user->ip4),i->data))) { WriteServ(user->fd,"474 %s %s :Cannot join channel (You're banned)",user->nick, Ptr->name); return NULL; diff --git a/src/cmd_whois.cpp b/src/cmd_whois.cpp index b8a288a04..0914f75f4 100644 --- a/src/cmd_whois.cpp +++ b/src/cmd_whois.cpp @@ -48,7 +48,7 @@ void do_whois(userrec* user, userrec* dest,unsigned long signon, unsigned long i WriteServ(user->fd,"311 %s %s %s %s * :%s",user->nick, dest->nick, dest->ident, dest->dhost, dest->fullname); if ((user == dest) || (*user->oper)) { - WriteServ(user->fd,"378 %s %s :is connecting from *@%s %s",user->nick, dest->nick, dest->host, inet_ntoa(dest->ip4)); + WriteServ(user->fd,"378 %s %s :is connecting from *@%s %s",user->nick, dest->nick, dest->host, insp_ntoa(dest->ip4)); } std::string cl = chlist(dest,user); if (cl.length()) diff --git a/src/commands.cpp b/src/commands.cpp index a10842ab1..c762510e7 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -243,7 +243,7 @@ bool ip_matches_everyone(const std::string &ip, userrec* user) for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++) { - if (match((char*)inet_ntoa(u->second->ip4),ip.c_str())) + if (match(insp_ntoa(u->second->ip4),ip.c_str())) matches++; } diff --git a/src/dns.cpp b/src/dns.cpp index 59aadd23f..5405f31e1 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -74,7 +74,7 @@ connlist connections; Resolver* dns_classes[MAX_DESCRIPTORS]; -insp_inaddr servers4[8]; +insp_inaddr servers[8]; int i4; int initdone = 0; int lastcreate = -1; @@ -191,7 +191,7 @@ void DNS::dns_init() initdone = 1; srand((unsigned int) TIME); - memset(servers4,'\0',sizeof(insp_inaddr) * 8); + memset(servers,'\0',sizeof(insp_inaddr) * 8); f = fopen("/etc/resolv.conf","r"); if (f == NULL) return; @@ -204,7 +204,7 @@ void DNS::dns_init() if (i4 < 8) { if (dns_aton4_s(&buf[i],&addr) != NULL) - memcpy(&servers4[i4++],&addr,sizeof(insp_inaddr)); + memcpy(&servers[i4++],&addr,sizeof(insp_inaddr)); } } } @@ -216,9 +216,9 @@ void DNS::dns_init_2(const char* dnsserver) insp_inaddr addr; i4 = 0; srand((unsigned int) TIME); - memset(servers4,'\0',sizeof(insp_inaddr) * 8); + memset(servers,'\0',sizeof(insp_inaddr) * 8); if (dns_aton4_s(dnsserver,&addr) != NULL) - memcpy(&servers4[i4++],&addr,sizeof(insp_inaddr)); + memcpy(&servers[i4++],&addr,sizeof(insp_inaddr)); } @@ -235,9 +235,15 @@ int dns_send_requests(const s_header *h, const s_connection *s, const int l) /* otherwise send via standard ipv4 boringness */ memset(&addr,0,sizeof(addr)); - memcpy(&addr.sin_addr,&servers4[i],sizeof(addr.sin_addr)); +#ifdef IPV6 + memcpy(&addr.sin6_addr,&servers[i],sizeof(addr.sin6_addr)); + addr.sin6_family = AF_FAMILY; + addr.sin6_port = htons(53); +#else + memcpy(&addr.sin_addr,&servers[i],sizeof(addr.sin_addr)); addr.sin_family = AF_FAMILY; addr.sin_port = htons(53); +#endif if (sendto(s->fd, payload, l + 12, 0, (sockaddr *) &addr, sizeof(addr)) == -1) { return -1; @@ -276,9 +282,15 @@ s_connection *dns_add_query(s_header *h) { insp_sockaddr addr; memset(&addr,0,sizeof(addr)); +#ifdef IPV6 + addr.sin6_family = AF_FAMILY; + addr.sin6_port = 0; + memset(&addr.sin6_addr,255,sizeof(in6_addr)); +#else addr.sin_family = AF_FAMILY; addr.sin_port = 0; addr.sin_addr.s_addr = INADDR_ANY; +#endif if (bind(s->fd,(sockaddr *)&addr,sizeof(addr)) != 0) { shutdown(s->fd,2); @@ -361,7 +373,7 @@ insp_inaddr* DNS::dns_aton4_r(const char *ipstring) { /* ascii to numeric (reent } insp_inaddr* DNS::dns_aton4_s(const char *ipstring, insp_inaddr *ip) { /* ascii to numeric (buffered): convert string to given 4part IP addr struct */ - inet_aton(ipstring,ip); + insp_aton(ipstring,ip); return ip; } @@ -409,7 +421,11 @@ int DNS::dns_getip4list(const char *name) { /* build, add and send A query; retr return s->fd; } -int DNS::dns_getname4(const insp_inaddr *ip) { /* build, add and send PTR query; retrieve result with dns_getresult() */ +int DNS::dns_getname4(const insp_inaddr *ip) +{ /* build, add and send PTR query; retrieve result with dns_getresult() */ +#ifdef IPV6 + return -1; +#else char query[512]; s_header h; s_connection * s; @@ -432,18 +448,7 @@ int DNS::dns_getname4(const insp_inaddr *ip) { /* build, add and send PTR query; return -1; return s->fd; -} - -char* DNS::dns_ntoa4(const insp_inaddr * const ip) { /* numeric to ascii: convert 4part IP addr struct to static string */ - static char r[256]; - return dns_ntoa4_s(ip,r); -} - -char* DNS::dns_ntoa4_s(const insp_inaddr *ip, char *r) { /* numeric to ascii (buffered): convert 4part IP addr struct to given string */ - unsigned char *m; - m = (unsigned char *)&ip->s_addr; - sprintf(r,"%d.%d.%d.%d",m[0],m[1],m[2],m[3]); - return r; +#endif } char* DNS::dns_getresult(const int cfd) { /* retrieve result of DNS query */ @@ -894,7 +899,7 @@ void* dns_task(void* arg) std::string ip; int iterations = 0; - if (dns1.ReverseLookup(inet_ntoa(u->ip4),false)) + if (dns1.ReverseLookup(insp_ntoa(u->ip4),false)) { /* FIX: Dont make these infinite! */ while ((!dns1.HasResult()) && (++iterations < 20)) @@ -918,7 +923,7 @@ void* dns_task(void* arg) if (dns2.GetFD() != -1) { ip = dns2.GetResultIP(); - if (ip == std::string(inet_ntoa(u->ip4))) + if (ip == std::string(insp_ntoa(u->ip4))) { if (host.length() < 65) { diff --git a/src/dnsqueue.cpp b/src/dnsqueue.cpp index 51a7e1964..e9265fc37 100644 --- a/src/dnsqueue.cpp +++ b/src/dnsqueue.cpp @@ -113,7 +113,7 @@ public: } if ((hostname != "") && (usr->registered != REG_ALL)) { - if ((std::string(inet_ntoa(usr->ip4)) == ip) && (hostname.length() < 65)) + if ((std::string(insp_ntoa(usr->ip4)) == ip) && (hostname.length() < 65)) { if ((hostname.find_last_of(".in-addr.arpa") == hostname.length() - 1) && (hostname.find_last_of(".in-addr.arpa") != std::string::npos)) { diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp index 213d51ffb..9b3b5b5b1 100644 --- a/src/hashcomp.cpp +++ b/src/hashcomp.cpp @@ -87,7 +87,14 @@ bool irc::StrHashComp::operator()(const std::string& s1, const std::string& s2) bool irc::InAddr_HashComp::operator()(const insp_inaddr &s1, const insp_inaddr &s2) const { +#ifdef IPV6 + for (int n = 0; n < 16; n++) + if (s2.s6_addr[n] != s1.s6_addr[n]) + return false; + return true; +#else return (s1.s_addr == s1.s_addr); +#endif } /****************************************************** diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 5f236b668..26f92c4df 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -1405,7 +1405,7 @@ ConnectClass GetClass(userrec *user) { for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++) { - if ((match(inet_ntoa(user->ip4),i->host.c_str())) || (match(user->host,i->host.c_str()))) + if ((match(insp_ntoa(user->ip4),i->host.c_str())) || (match(user->host,i->host.c_str()))) { return *i; } diff --git a/src/inspircd.cpp b/src/inspircd.cpp index b9cd9f36c..57c23b328 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -858,7 +858,11 @@ void InspIRCd::DoOneIteration(bool process_module_sockets) if ((incomingSockfd > -1) && (!getsockname(incomingSockfd,(sockaddr*)&sock_us,&uslen))) { +#ifdef IPV6 + in_port = ntohs(sock_us.sin6_port); +#else in_port = ntohs(sock_us.sin_port); +#endif log(DEBUG,"Accepted socket %d",incomingSockfd); /* Years and years ago, we used to resolve here * using gethostbyaddr(). That is sucky and we @@ -869,7 +873,11 @@ void InspIRCd::DoOneIteration(bool process_module_sockets) { try { - Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, inet_ntoa(client.sin_addr), in_port); +#ifdef IPV6 + Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, insp_ntoa(client.sin6_addr), in_port); +#else + Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, insp_ntoa(client.sin_addr), in_port); +#endif } catch (ModuleException& modexcept) { @@ -877,7 +885,11 @@ void InspIRCd::DoOneIteration(bool process_module_sockets) } } stats->statsAccept++; +#ifdef IPV6 + AddClient(incomingSockfd, in_port, false, client.sin6_addr); +#else AddClient(incomingSockfd, in_port, false, client.sin_addr); +#endif log(DEBUG,"Adding client on port %lu fd=%lu",(unsigned long)in_port,(unsigned long)incomingSockfd); } else diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index 66ba5c58e..054b8b910 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -99,7 +99,7 @@ InspSocket::InspSocket(const std::string &ahost, int aport, bool listening, unsi strlcpy(this->host,ahost.c_str(),MAXBUF); this->port = aport; - if (!inet_aton(host,&addy)) + if (!insp_aton(host,&addy)) { log(DEBUG,"Attempting to resolve %s",this->host); /* Its not an ip, spawn the resolver */ @@ -200,7 +200,7 @@ bool InspSocket::BindAddr() insp_sockaddr s; char resolved_addr[MAXBUF]; - if (!inet_aton(IP.c_str(),&n)) + if (!insp_aton(IP.c_str(),&n)) { /* If they gave a hostname, bind to the IP it resolves to */ log(DEBUG,"Resolving host %s",IP.c_str()); @@ -211,11 +211,16 @@ bool InspSocket::BindAddr() } } - if (inet_aton(IP.c_str(),&n)) + if (insp_aton(IP.c_str(),&n)) { log(DEBUG,"Found an IP to bind to: %s",IP.c_str()); +#ifdef IPV6 + s.sin6_addr = n; + s.sin6_family = AF_FAMILY; +#else s.sin_addr = n; s.sin_family = AF_FAMILY; +#endif if (bind(this->fd,(struct sockaddr*)&s,sizeof(s)) < 0) { log(DEBUG,"Cant bind()"); @@ -254,10 +259,16 @@ bool InspSocket::DoConnect() return false; log(DEBUG,"Part 2 DoConnect() %s",this->IP); - inet_aton(this->IP,&addy); + insp_aton(this->IP,&addy); +#ifdef IPV6 + addr.sin6_family = AF_FAMILY; + memcpy(&addy, &addr.sin6_addr, sizeof(insp_inaddr)); + addr.sin6_port = htons(this->port); +#else addr.sin_family = AF_FAMILY; addr.sin_addr = addy; addr.sin_port = htons(this->port); +#endif int flags; flags = fcntl(this->fd, F_GETFL, 0); @@ -459,7 +470,11 @@ bool InspSocket::Poll() length = sizeof (client); incoming = accept (this->fd, (sockaddr*)&client,&length); this->SetQueues(incoming); - this->OnIncomingConnection(incoming,inet_ntoa(client.sin_addr)); +#ifdef IPV6 + this->OnIncomingConnection(incoming,(char*)insp_ntoa(client.sin6_addr)); +#else + this->OnIncomingConnection(incoming,(char*)insp_ntoa(client.sin_addr)); +#endif return true; break; case I_CONNECTED: diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp index e3639436b..7f2b96227 100644 --- a/src/modules/extra/m_mysql.cpp +++ b/src/modules/extra/m_mysql.cpp @@ -667,7 +667,11 @@ class Notifier : public InspSocket public: /* Create a socket on a random port. Let the tcp stack allocate us an available port */ +#ifdef IPV6 + Notifier(Server* S) : InspSocket("::1", 0, true, 3000), Srv(S) +#else Notifier(Server* S) : InspSocket("127.0.0.1", 0, true, 3000), Srv(S) +#endif { uslen = sizeof(sock_us); if (getsockname(this->fd,(sockaddr*)&sock_us,&uslen)) @@ -684,7 +688,11 @@ class Notifier : public InspSocket /* Using getsockname and ntohs, we can determine which port number we were allocated */ int GetPort() { +#ifdef IPV6 + return ntohs(sock_us.sin6_port); +#else return ntohs(sock_us.sin_port); +#endif } virtual int OnIncomingConnection(int newsock, char* ip) @@ -842,11 +850,18 @@ void* DispatcherThread(void* arg) log(DEBUG,"Initialize QueueFD to %d",QueueFD); insp_sockaddr addr; + +#ifdef IPV6 + insp_aton("::1", &addr.sin6_addr); + addr.sin6_family = AF_FAMILY; + addr.sin6_port = htons(MessagePipe->GetPort()); +#else insp_inaddr ia; - inet_aton("127.0.0.1", &ia); + insp_aton("127.0.0.1", &ia); addr.sin_family = AF_FAMILY; addr.sin_addr = ia; addr.sin_port = htons(MessagePipe->GetPort()); +#endif if (connect(QueueFD, (sockaddr*)&addr,sizeof(addr)) == -1) { diff --git a/src/modules/m_cgiirc.cpp b/src/modules/m_cgiirc.cpp index 7da83c610..6426e054a 100644 --- a/src/modules/m_cgiirc.cpp +++ b/src/modules/m_cgiirc.cpp @@ -198,16 +198,16 @@ public: virtual void OnUserRegister(userrec* user) { - log(DEBUG, "m_cgiirc.so: User %s registering, %s %s", user->nick,user->host,inet_ntoa(user->ip4)); + log(DEBUG, "m_cgiirc.so: User %s registering, %s %s", user->nick,user->host,insp_ntoa(user->ip4)); for(CGIHostlist::iterator iter = Hosts.begin(); iter != Hosts.end(); iter++) { - log(DEBUG, "m_cgiirc.so: Matching %s against (%s or %s)", iter->hostmask.c_str(), user->host, inet_ntoa(user->ip4)); + log(DEBUG, "m_cgiirc.so: Matching %s against (%s or %s)", iter->hostmask.c_str(), user->host, insp_ntoa(user->ip4)); - if(Srv->MatchText(user->host, iter->hostmask) || Srv->MatchText(inet_ntoa(user->ip4), iter->hostmask)) + if(Srv->MatchText(user->host, iter->hostmask) || Srv->MatchText(insp_ntoa(user->ip4), iter->hostmask)) { // Deal with it... - log(DEBUG, "m_cgiirc.so: Handling CGI:IRC user: %s (%s) matched %s", user->GetFullRealHost(), inet_ntoa(user->ip4), iter->hostmask.c_str()); + log(DEBUG, "m_cgiirc.so: Handling CGI:IRC user: %s (%s) matched %s", user->GetFullRealHost(), insp_ntoa(user->ip4), iter->hostmask.c_str()); if(iter->type == PASS) { @@ -240,11 +240,11 @@ public: if(IsValidHost(user->password)) { user->Extend("cgiirc_realhost", new std::string(user->host)); - user->Extend("cgiirc_realip", new std::string(inet_ntoa(user->ip4))); + user->Extend("cgiirc_realip", new std::string(insp_ntoa(user->ip4))); strlcpy(user->host, user->password, 64); strlcpy(user->dhost, user->password, 64); - if(inet_aton(user->password, &user->ip4)) + if(insp_aton(user->password, &user->ip4)) { /* We were given a IP in the password, we don't do DNS so they get this is as their host as well. */ log(DEBUG, "m_cgiirc.so: Got an IP in the user's password"); @@ -305,8 +305,8 @@ public: snprintf(newip, 16, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); user->Extend("cgiirc_realhost", new std::string(user->host)); - user->Extend("cgiirc_realip", new std::string(inet_ntoa(user->ip4))); - inet_aton(newip, &user->ip4); + user->Extend("cgiirc_realip", new std::string(insp_ntoa(user->ip4))); + insp_aton(newip, &user->ip4); try { diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp index 29aaaa6dc..e41e60b80 100644 --- a/src/modules/m_check.cpp +++ b/src/modules/m_check.cpp @@ -160,8 +160,11 @@ class cmd_check : public command_t /* /check on an IP address, or something that doesn't exist */ insp_sockaddr addr; long x = 0; - - if (inet_aton(parameters[0], &addr.sin_addr) == 0) +#ifdef IPV6 + if (insp_aton(parameters[0], &addr.sin6_addr) == 0) +#else + if (insp_aton(parameters[0], &addr.sin_addr) == 0) +#endif { /* hostname or other */ for (user_hash::const_iterator a = clientlist.begin(); a != clientlist.end(); a++) @@ -178,11 +181,15 @@ class cmd_check : public command_t /* IP address */ for (user_hash::const_iterator a = clientlist.begin(); a != clientlist.end(); a++) { +#ifdef IPV6 + /* TODO: Clone matching for IPV6 ips */ +#else if (addr.sin_addr.s_addr == a->second->ip4.s_addr) { /* same IP. */ Srv->SendTo(NULL, user, checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost()); } +#endif } } diff --git a/src/modules/m_ident.cpp b/src/modules/m_ident.cpp index 270457af7..76518d5c1 100644 --- a/src/modules/m_ident.cpp +++ b/src/modules/m_ident.cpp @@ -43,7 +43,7 @@ class RFC1413 : public InspSocket userrec* u; // user record that the lookup is associated with int ufd; - RFC1413(userrec* user, int maxtime, Server* S) : InspSocket((char*)inet_ntoa(user->ip4), 113, false, maxtime), Srv(S), u(user), ufd(user->fd) + RFC1413(userrec* user, int maxtime, Server* S) : InspSocket((char*)insp_ntoa(user->ip4), 113, false, maxtime), Srv(S), u(user), ufd(user->fd) { Srv->Log(DEBUG,"Ident: associated."); } @@ -149,7 +149,11 @@ class RFC1413 : public InspSocket else { // send the request in the following format: theirsocket,oursocket +#ifdef IPV6 + snprintf(ident_request,127,"%d,%d\r\n",ntohs(sock_them.sin6_port),ntohs(sock_us.sin6_port)); +#else snprintf(ident_request,127,"%d,%d\r\n",ntohs(sock_them.sin_port),ntohs(sock_us.sin_port)); +#endif this->Write(ident_request); Srv->Log(DEBUG,"Sent ident request, waiting for reply"); return true; diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp index c55662f9f..0725d7b51 100644 --- a/src/modules/m_spanningtree.cpp +++ b/src/modules/m_spanningtree.cpp @@ -1560,9 +1560,9 @@ class TreeSocket : public InspSocket { clientlist[tempnick]->modes[(*v)-65] = 1; } - inet_aton(params[6].c_str(),&clientlist[tempnick]->ip4); + insp_aton(params[6].c_str(),&clientlist[tempnick]->ip4); - WriteOpers("*** Client connecting at %s: %s!%s@%s [%s]",clientlist[tempnick]->server,clientlist[tempnick]->nick,clientlist[tempnick]->ident,clientlist[tempnick]->host, inet_ntoa(clientlist[tempnick]->ip4)); + WriteOpers("*** Client connecting at %s: %s!%s@%s [%s]",clientlist[tempnick]->server,clientlist[tempnick]->nick,clientlist[tempnick]->ident,clientlist[tempnick]->host, insp_ntoa(clientlist[tempnick]->ip4)); params[7] = ":" + params[7]; DoOneToAllButSender(source,"NICK",params,source); @@ -1767,7 +1767,7 @@ class TreeSocket : public InspSocket { if (u->second->registered == REG_ALL) { - snprintf(data,MAXBUF,":%s NICK %lu %s %s %s %s +%s %s :%s",u->second->server,(unsigned long)u->second->age,u->second->nick,u->second->host,u->second->dhost,u->second->ident,u->second->FormatModes(),inet_ntoa(u->second->ip4),u->second->fullname); + snprintf(data,MAXBUF,":%s NICK %lu %s %s %s %s +%s %s :%s",u->second->server,(unsigned long)u->second->age,u->second->nick,u->second->host,u->second->dhost,u->second->ident,u->second->FormatModes(),insp_ntoa(u->second->ip4),u->second->fullname); this->WriteLine(data); if (*u->second->oper) { @@ -4055,7 +4055,7 @@ class ModuleSpanningTree : public Module params.push_back(user->dhost); params.push_back(user->ident); params.push_back("+"+std::string(user->FormatModes())); - params.push_back((char*)inet_ntoa(user->ip4)); + params.push_back((char*)insp_ntoa(user->ip4)); params.push_back(":"+std::string(user->fullname)); DoOneToMany(Srv->GetServerName(),"NICK",params); diff --git a/src/modules/m_userip.cpp b/src/modules/m_userip.cpp index 4775b518c..d7126684d 100644 --- a/src/modules/m_userip.cpp +++ b/src/modules/m_userip.cpp @@ -45,7 +45,7 @@ class cmd_userip : public command_t userrec *u = Find(parameters[i]); if (u) { - snprintf(junk,MAXBUF,"%s%s=+%s@%s ",u->nick,*u->oper ? "*" : "",u->ident,(char*)inet_ntoa(u->ip4)); + snprintf(junk,MAXBUF,"%s%s=+%s@%s ",u->nick,*u->oper ? "*" : "",u->ident,(char*)insp_ntoa(u->ip4)); strlcat(Return,junk,MAXBUF); } } diff --git a/src/socket.cpp b/src/socket.cpp index 22069b87d..1b8455c65 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -44,14 +44,19 @@ bool BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port if (*addr == '*') *addr = 0; - if (*addr && !inet_aton(addr,&addy)) + if (*addr && !insp_aton(addr,&addy)) { /* If they gave a hostname, bind to the IP it resolves to */ if (CleanAndResolve(resolved_addr, addr, true, 1)) { - inet_aton(resolved_addr,&addy); + insp_aton(resolved_addr,&addy); log(DEFAULT,"Resolved binding '%s' -> '%s'",addr,resolved_addr); +#ifdef IPV6 + /* Todo: Deal with resolution of IPV6 */ + server.sin6_addr = addy; +#else server.sin_addr = addy; +#endif resolved = true; } else @@ -60,19 +65,35 @@ bool BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port return false; } } +#ifdef IPV6 + server.sin6_family = AF_FAMILY; +#else server.sin_family = AF_FAMILY; +#endif if (!resolved) { if (!*addr) { +#ifdef IPV6 + memcpy(&addy, &server.sin6_addr, sizeof(in6_addr)); +#else server.sin_addr.s_addr = htonl(INADDR_ANY); +#endif } else { +#ifdef IPV6 + memcpy(&addy, &server.sin6_addr, sizeof(in6_addr)); +#else server.sin_addr = addy; +#endif } } +#ifdef IPV6 + server.sin6_port = htons(port); +#else server.sin_port = htons(port); +#endif if (bind(sockfd,(struct sockaddr*)&server,sizeof(server)) < 0) { return false; @@ -247,3 +268,15 @@ int BindPorts(bool bail) return BoundPortCount; } + +const char* insp_ntoa(insp_inaddr n) +{ + static char buf[1024]; + inet_ntop(AF_FAMILY, &n, buf, sizeof(buf)); + return buf; +} + +int insp_aton(const char* a, insp_inaddr* n) +{ + return (inet_pton(AF_FAMILY, a, &n) < 0); +} diff --git a/src/userprocess.cpp b/src/userprocess.cpp index fc60974a3..30bb79872 100644 --- a/src/userprocess.cpp +++ b/src/userprocess.cpp @@ -173,9 +173,9 @@ void ProcessUser(userrec* cu) } else { - WriteOpers("*** Excess flood from %s",(char*)inet_ntoa(current->ip4)); - log(DEFAULT,"Excess flood from: %s",(char*)inet_ntoa(current->ip4)); - add_zline(120,Config->ServerName,"Flood from unregistered connection",(char*)inet_ntoa(current->ip4)); + WriteOpers("*** Excess flood from %s",(char*)insp_ntoa(current->ip4)); + log(DEFAULT,"Excess flood from: %s",(char*)insp_ntoa(current->ip4)); + add_zline(120,Config->ServerName,"Flood from unregistered connection",(char*)insp_ntoa(current->ip4)); apply_lines(APPLY_ZLINES); } @@ -190,9 +190,9 @@ void ProcessUser(userrec* cu) } else { - WriteOpers("*** Excess flood from %s",(char*)inet_ntoa(current->ip4)); - log(DEFAULT,"Excess flood from: %s",(char*)inet_ntoa(current->ip4)); - add_zline(120,Config->ServerName,"Flood from unregistered connection",(char*)inet_ntoa(current->ip4)); + WriteOpers("*** Excess flood from %s",(char*)insp_ntoa(current->ip4)); + log(DEFAULT,"Excess flood from: %s",(char*)insp_ntoa(current->ip4)); + add_zline(120,Config->ServerName,"Flood from unregistered connection",(char*)insp_ntoa(current->ip4)); apply_lines(APPLY_ZLINES); } @@ -226,7 +226,7 @@ void ProcessUser(userrec* cu) } else { - add_zline(120,Config->ServerName,"Flood from unregistered connection",(char*)inet_ntoa(current->ip4)); + add_zline(120,Config->ServerName,"Flood from unregistered connection",(char*)insp_ntoa(current->ip4)); apply_lines(APPLY_ZLINES); } diff --git a/src/users.cpp b/src/users.cpp index f52f05b10..93ffadb83 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -706,7 +706,7 @@ void AddClient(int socket, int port, bool iscached, insp_inaddr ip4) { std::string tempnick = ConvToStr(socket) + "-unknown"; user_hash::iterator iter = clientlist.find(tempnick); - const char *ipaddr = inet_ntoa(ip4); + const char *ipaddr = insp_ntoa(ip4); userrec* _new; int j = 0; @@ -832,8 +832,12 @@ long FindMatchingGlobal(userrec* user) long x = 0; for (user_hash::const_iterator a = clientlist.begin(); a != clientlist.end(); a++) { +#ifdef IPV6 + /* TODO: clone matching for ipv6 */ +#else if (a->second->ip4.s_addr == user->ip4.s_addr) x++; +#endif } return x; } @@ -843,9 +847,13 @@ long FindMatchingLocal(userrec* user) long x = 0; for (std::vector<userrec*>::const_iterator a = local_users.begin(); a != local_users.end(); a++) { - userrec* comp = (userrec*)(*a); +#ifdef IPV6 + /* TODO clone matching for ipv6 */ +#else + userrec* comp = *a; if (comp->ip4.s_addr == user->ip4.s_addr) x++; +#endif } return x; } @@ -873,13 +881,13 @@ void FullConnectUser(userrec* user, CullList* Goners) if (FindMatchingLocal(user) > a.maxlocal) { Goners->AddItem(user,"No more connections allowed from your host via this connect class (local)"); - WriteOpers("*** WARNING: maximum LOCAL connections (%ld) exceeded for IP %s",a.maxlocal,inet_ntoa(user->ip4)); + WriteOpers("*** WARNING: maximum LOCAL connections (%ld) exceeded for IP %s",a.maxlocal,insp_ntoa(user->ip4)); return; } else if (FindMatchingGlobal(user) > a.maxglobal) { Goners->AddItem(user,"No more connections allowed from your host via this connect class (global)"); - WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s",a.maxglobal,inet_ntoa(user->ip4)); + WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s",a.maxglobal,insp_ntoa(user->ip4)); return; } @@ -947,7 +955,7 @@ void FullConnectUser(userrec* user, CullList* Goners) FOREACH_MOD(I_OnUserConnect,OnUserConnect(user)); FOREACH_MOD(I_OnGlobalConnect,OnGlobalConnect(user)); user->registered = REG_ALL; - WriteOpers("*** Client connecting on port %lu: %s!%s@%s [%s]",(unsigned long)user->port,user->nick,user->ident,user->host,inet_ntoa(user->ip4)); + WriteOpers("*** Client connecting on port %lu: %s!%s@%s [%s]",(unsigned long)user->port,user->nick,user->ident,user->host,insp_ntoa(user->ip4)); } /** ReHashNick() diff --git a/src/xline.cpp b/src/xline.cpp index 3401ca441..740f9cb49 100644 --- a/src/xline.cpp +++ b/src/xline.cpp @@ -703,7 +703,7 @@ void apply_lines(const int What) } if ((What & APPLY_ZLINES) && (zlines.size() || pzlines.size())) { - if ((check = matches_zline((char*)inet_ntoa(u->ip4)))) + if ((check = matches_zline(insp_ntoa(u->ip4)))) { snprintf(reason,MAXBUF,"Z-Lined: %s",check); Goners->AddItem(u,reason); |