
This function allows us to avoid using touching the raw IP address for an client when all we really want is the string version. Also increase HOSTIPLEN to 45 characters, which will allow an IPv6 address to fit. Based on the function from mamikk's old patch. --- include/h.h | 1 + include/struct.h | 2 +- src/m_server.c | 4 ++-- src/s_bsd.c | 4 ++-- src/s_misc.c | 10 +++++----- src/s_user.c | 8 ++++---- src/support.c | 9 +++++++++ src/userban.c | 4 ++-- 8 files changed, 26 insertions(+), 16 deletions(-) diff --git a/include/h.h b/include/h.h index 467fadb..137fcba 100644 --- a/include/h.h +++ b/include/h.h @@ -180,6 +180,7 @@ extern char *getreply(int); extern char *strerror(int); extern int dgets(int, char *, int); extern char *inetntoa(char *); +extern char *cipntoa(aClient *); extern int dbufalloc, dbufblocks, debuglevel, errno; extern int highest_fd, debuglevel, portnum, debugtty, maxusersperchannel; diff --git a/include/struct.h b/include/struct.h index 307826c..523b61d 100644 --- a/include/struct.h +++ b/include/struct.h @@ -112,7 +112,7 @@ typedef struct SAliasInfo AliasInfo; /* comply with RFC1123 */ -#define HOSTIPLEN 15 /* Length of dotted quad form of IP */ +#define HOSTIPLEN 45 /* Length of an IPv4 or IPv6 address */ #define NICKLEN 30 diff --git a/src/m_server.c b/src/m_server.c index 76dfab3..f4ce52e 100644 --- a/src/m_server.c +++ b/src/m_server.c @@ -54,7 +54,7 @@ static void sendnick_TS(aClient *cptr, aClient *acptr) acptr->name, acptr->hopcount + 1, acptr->tsinfo, ubuf, acptr->user->username, acptr->user->host, acptr->user->server, acptr->user->servicestamp, - inetntoa((char *)&acptr->ip), acptr->info); + cipntoa(acptr), acptr->info); } else { @@ -456,7 +456,7 @@ m_server_estab(aClient *cptr) cptr->serv->up = me.name; cptr->serv->aconn = aconn; - throttle_remove(inetntoa((char *)&cptr->ip)); + throttle_remove(cipntoa(cptr)); #ifdef HAVE_ENCRYPTION_ON if(!CanDoDKEY(cptr) || !WantDKEY(cptr)) diff --git a/src/s_bsd.c b/src/s_bsd.c index 7b021dc..10243ef 100644 --- a/src/s_bsd.c +++ b/src/s_bsd.c @@ -608,7 +608,7 @@ int check_client(aClient *cptr) int i; Debug((DEBUG_DNS, "ch_cl: check access for %s[%s]", - cptr->name, inetntoa((char *) &cptr->ip))); + cptr->name, cipntoa(cptr))); if (check_init(cptr, sockname)) return -2; @@ -716,7 +716,7 @@ int check_server_init(aClient * cptr) { sendto_realops_lev(ADMIN_LEV, "Server IP# Mismatch: %s != %s[%08lx]", - inetntoa((char *) &cptr->ip), hp->h_name, + cipntoa(cptr), hp->h_name, *((unsigned long *) hp->h_addr)); hp = NULL; } diff --git a/src/s_misc.c b/src/s_misc.c index 4114fd5..04adf46 100644 --- a/src/s_misc.c +++ b/src/s_misc.c @@ -194,7 +194,7 @@ get_client_name(aClient *sptr, int showip) if (IsServer(sptr)) { if (showip == TRUE) - s += ircsprintf(s, "[%s]", inetntoa((char *)&sptr->ip)); + s += ircsprintf(s, "[%s]", cipntoa(sptr)); else if (showip != HIDEME) s += ircsprintf(s, "[%s]", sptr->sockhost); } @@ -202,7 +202,7 @@ get_client_name(aClient *sptr, int showip) { if (showip == TRUE) s += ircsprintf(s, "!%s@%s", sptr->user->username, - inetntoa((char *)&sptr->ip)); + cipntoa(sptr)); else if (showip != HIDEME) s += ircsprintf(s, "!%s@%s", sptr->user->username, sptr->user->host); @@ -222,7 +222,7 @@ get_client_name(aClient *sptr, int showip) if (showip == TRUE) s += ircsprintf(s, "]%s@%s)", sptr->username, - inetntoa((char *)&sptr->ip)); + cipntoa(sptr)); else s += ircsprintf(s, "]%s@%s)", sptr->username, sptr->sockhost); @@ -850,14 +850,14 @@ exit_banned_client(aClient *cptr, int loc, char type, char *banmsg, int fast) sendto_one(cptr, "NOTICE %s :*** Reason: %s", target, reason); sendto_one(cptr, "NOTICE %s :*** Connection info: %s [%s]", target, get_client_name(cptr, FALSE), - inetntoa((char *)&cptr->ip.s_addr)); + cipntoa(cptr)); sendto_one(cptr, "NOTICE %s :*** Ban contact: %s", target, loc ? Local_Kline_Address : Network_Kline_Address); sendto_one(cptr, "NOTICE %s :*** When contacting %s, please include " "all of the information shown above", target, Network_Name); sendto_one(cptr, err_str(ERR_YOUREBANNEDCREEP), me.name, target, rbuf); - throttle_force(inetntoa((char *)&cptr->ip.s_addr)); + throttle_force(cipntoa(cptr)); } return exit_client(cptr, cptr, &me, rbuf); diff --git a/src/s_user.c b/src/s_user.c index 3d3cf34..84cb6c4 100644 --- a/src/s_user.c +++ b/src/s_user.c @@ -413,7 +413,7 @@ static int reject_proxy(aClient *cptr, char *cmd, char *args) { sendto_realops_lev(REJ_LEV, "proxy attempt from %s: %s %s", - inetntoa((char *)&cptr->ip), cmd, args ? args : ""); + cipntoa(cptr), cmd, args ? args : ""); return exit_client(cptr, cptr, &me, "relay connection"); } @@ -465,7 +465,7 @@ register_user(aClient *cptr, aClient *sptr, char *nick, char *username) parv[0] = sptr->name; parv[1] = parv[2] = NULL; - p = inetntoa((char *) &sptr->ip); + p = cipntoa(sptr); strncpyzt(sptr->hostip, p, HOSTIPLEN + 1); if (MyConnect(sptr)) { @@ -1073,7 +1073,7 @@ register_user(aClient *cptr, aClient *sptr, char *nick, char *username) nick, sptr->hopcount + 1, sptr->tsinfo, ubuf, user->username, user->host, user->server, sptr->user->servicestamp, - inetntoa((char *)&sptr->ip), sptr->info); + cipntoa(sptr), sptr->info); } else { @@ -2155,7 +2155,7 @@ do_user(char *nick, aClient *cptr, aClient *sptr, char *username, char *host, * elsewhere for the locals! -wd */ #ifdef THROTTLE_ENABLE if (sptr->ip.s_addr != 0) - throttle_check(inetntoa((char *)&sptr->ip), -1, sptr->tsinfo); + throttle_check(cipntoa(sptr), -1, sptr->tsinfo); #endif } if(MyConnect(sptr)) diff --git a/src/support.c b/src/support.c index 30f8130..280f7d0 100644 --- a/src/support.c +++ b/src/support.c @@ -130,6 +130,15 @@ char *inetntoa(char *in) return buf; } +/* cipntoa - Return the client IP address as a string. */ +char *cipntoa(aClient *cptr) +{ + if (cptr->hostip[0] != '\0') + return cptr->hostip; + else + return inetntoa((char *)&cptr->ip); +} + #if !defined( HAVE_INET_NETOF ) /* inet_netof -- return the net portion of an internet number */ diff --git a/src/userban.c b/src/userban.c index 7b35c98..02430f1 100644 --- a/src/userban.c +++ b/src/userban.c @@ -174,7 +174,7 @@ int user_match_ban(aClient *cptr, struct userBan *ban) { char iptmp[HOSTIPLEN + 1]; - strncpyzt(iptmp, inetntoa((char *)&cptr->ip), HOSTIPLEN + 1); + strncpyzt(iptmp, cipntoa(cptr), HOSTIPLEN + 1); if(ban->flags & UBAN_WILD) { if(match(ban->h, iptmp) == 0) @@ -218,7 +218,7 @@ struct userBan *check_userbanned(aClient *cptr, unsigned int yflags, unsigned in char iptmp[HOSTIPLEN + 1]; uBanEnt *bl; - strncpyzt(iptmp, inetntoa((char *)&cptr->ip), HOSTIPLEN + 1); + strncpyzt(iptmp, cipntoa(cptr), HOSTIPLEN + 1); if(yflags & UBAN_IP) { -- 1.7.2.3