Previously, the IP address for a client was sent to other servers as a
32-bit number.
This patch adds a new capability that indicates that a server is capable
of handling the IP address being sent as a string.
---
include/inet.h | 4 ++++
include/struct.h | 3 +++
src/m_nick.c | 9 +++++----
src/m_server.c | 27 +++++++++++++++++++--------
src/s_serv.c | 2 ++
src/s_user.c | 35 ++++++++++++++++++++++++-----------
6 files changed, 57 insertions(+), 23 deletions(-)
diff --git a/include/inet.h b/include/inet.h
index 7c93613..a0960f7 100644
--- a/include/inet.h
+++ b/include/inet.h
@@ -36,6 +36,8 @@ extern __u_l inet_makeaddr(int, int);
extern __u_l inet_network(char *);
extern __u_l inet_lnaof(struct in_addr);
extern __u_l inet_netof(struct in_addr);
+extern int inet_pton(int, const char *, void *);
+extern const char *inet_ntop(int, const void *, char *, socklen_t);
#else
extern __u_l inet_addr();
@@ -47,5 +49,7 @@ extern __u_l inet_makeaddr();
extern __u_l inet_network();
extern __u_l inet_lnaof();
extern __u_l inet_netof();
+extern int inet_pton();
+extern const char *inet_ntop();
#undef __u_l
diff --git a/include/struct.h b/include/struct.h
index 255c112..307826c 100644
--- a/include/struct.h
+++ b/include/struct.h
@@ -251,6 +251,7 @@ typedef struct SAliasInfo AliasInfo;
#ifdef NOQUIT
#define CAPAB_NOQUIT 0x0040 /* noquit support */
#endif
+#define CAPAB_NICKIPSTR 0x0080 /* Nick IP as a string support */
#define SetDKEY(x) ((x)->capabilities |= CAPAB_DKEY)
@@ -275,6 +276,8 @@ typedef struct SAliasInfo AliasInfo;
#define IsNoquit(x) ((x)->capabilities & CAPAB_NOQUIT)
#endif
+#define SetNickIPStr(x) ((x)->capabilities |= CAPAB_NICKIPSTR)
+#define IsNickIPStr(x) ((x)->capabilities & CAPAB_NICKIPSTR)
/* flag macros. */
#define IsULine(x) ((x)->flags & FLAGS_ULINE)
diff --git a/src/m_nick.c b/src/m_nick.c
index cfa0250..2e2ad07 100644
--- a/src/m_nick.c
+++ b/src/m_nick.c
@@ -34,7 +34,7 @@
#include "hooks.h"
extern int do_user(char *, aClient *, aClient *, char *, char *, char *,
- unsigned long, unsigned int, char *);
+ unsigned long, char *, char *);
extern int register_user(aClient *, aClient *, char *, char *);
extern int del_dccallow(aClient *, aClient *, int);
@@ -431,12 +431,13 @@ int m_nick(aClient *cptr, aClient *sptr, int parc, char *parv[])
if (parc==10)
{
return do_user(nick, cptr, sptr, parv[5], parv[6],
- parv[7], strtoul(parv[8], NULL, 0), 0, parv[9]);
+ parv[7], strtoul(parv[8], NULL, 0),
+ "0.0.0.0", parv[9]);
} else if (parc==11)
{
return do_user(nick, cptr, sptr, parv[5], parv[6], parv[7],
- strtoul(parv[8], NULL, 0),
- strtoul(parv[9], NULL, 0), parv[10]);
+ strtoul(parv[8], NULL, 0),
+ parv[9], parv[10]);
}
}
}
diff --git a/src/m_server.c b/src/m_server.c
index 85e89bf..76dfab3 100644
--- a/src/m_server.c
+++ b/src/m_server.c
@@ -48,11 +48,22 @@ static void sendnick_TS(aClient *cptr, aClient *acptr)
ubuf[0] = '+';
ubuf[1] = '\0';
}
- sendto_one(cptr, "NICK %s %d %ld %s %s %s %s %lu %u :%s",
- acptr->name, acptr->hopcount + 1, acptr->tsinfo, ubuf,
- acptr->user->username, acptr->user->host,
- acptr->user->server, acptr->user->servicestamp,
- htonl(acptr->ip.s_addr), acptr->info);
+ if (IsNickIPStr(cptr))
+ {
+ sendto_one(cptr, "NICK %s %d %ld %s %s %s %s %lu %s :%s",
+ 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);
+ }
+ else
+ {
+ sendto_one(cptr, "NICK %s %d %ld %s %s %s %s %lu %u :%s",
+ acptr->name, acptr->hopcount + 1, acptr->tsinfo, ubuf,
+ acptr->user->username, acptr->user->host,
+ acptr->user->server, acptr->user->servicestamp,
+ htonl(acptr->ip.s_addr), acptr->info);
+ }
}
}
@@ -378,12 +389,12 @@ m_server_estab(aClient *cptr)
#ifdef HAVE_ENCRYPTION_ON
if(!WantDKEY(cptr))
sendto_one(cptr, "CAPAB SSJOIN NOQUIT BURST UNCONNECT ZIP "
- "NICKIP TSMODE");
+ "NICKIP NICKIPSTR TSMODE");
else
sendto_one(cptr, "CAPAB SSJOIN NOQUIT BURST UNCONNECT DKEY "
- "ZIP NICKIP TSMODE");
+ "ZIP NICKIP NICKIPSTR TSMODE");
#else
- sendto_one(cptr, "CAPAB SSJOIN NOQUIT BURST UNCONNECT ZIP NICKIP TSMODE");
+ sendto_one(cptr, "CAPAB SSJOIN NOQUIT BURST UNCONNECT ZIP NICKIP NICKIPSTR TSMODE");
#endif
sendto_one(cptr, "SERVER %s 1 :%s",
diff --git a/src/s_serv.c b/src/s_serv.c
index 22c0cef..c8de173 100644
--- a/src/s_serv.c
+++ b/src/s_serv.c
@@ -2399,6 +2399,8 @@ m_capab(aClient *cptr, aClient *sptr, int parc, char *parv[])
else if (strcmp(parv[i], "NOQUIT") == 0)
SetNoquit(cptr);
#endif
+ else if (strcmp(parv[i], "NICKIPSTR") == 0)
+ SetNickIPStr(cptr);
}
return 0;
diff --git a/src/s_user.c b/src/s_user.c
index 7c59d41..06b246e 100644
--- a/src/s_user.c
+++ b/src/s_user.c
@@ -39,6 +39,7 @@
#include "userban.h"
#include "hooks.h"
#include "memcount.h"
+#include "inet.h"
#if defined( HAVE_STRING_H)
#include <string.h>
@@ -47,7 +48,7 @@
#endif
int do_user(char *, aClient *, aClient *, char *, char *, char *,
- unsigned long, unsigned int, char *);
+ unsigned long, char *, char *);
extern char motd_last_changed_date[];
extern int send_motd(aClient *, aClient *, int, char **);
extern void send_topic_burst(aClient *);
@@ -1068,12 +1069,23 @@ register_user(aClient *cptr, aClient *sptr, char *nick, char *username)
ubuf[1] = '\0';
}
hash_check_watch(sptr, RPL_LOGON);
- sendto_serv_butone(cptr, "NICK %s %d %ld %s %s %s %s %lu %u :%s",
- nick, sptr->hopcount + 1, sptr->tsinfo, ubuf,
- user->username, user->host, user->server,
- sptr->user->servicestamp,
- htonl(sptr->ip.s_addr), sptr->info);
-
+ if (IsNickIPStr(cptr))
+ {
+ sendto_serv_butone(cptr, "NICK %s %d %ld %s %s %s %s %lu %s :%s",
+ nick, sptr->hopcount + 1, sptr->tsinfo, ubuf,
+ user->username, user->host, user->server,
+ sptr->user->servicestamp,
+ inetntoa((char *)&sptr->ip), sptr->info);
+ }
+ else
+ {
+ sendto_serv_butone(cptr, "NICK %s %d %ld %s %s %s %s %lu %u :%s",
+ nick, sptr->hopcount + 1, sptr->tsinfo, ubuf,
+ user->username, user->host, user->server,
+ sptr->user->servicestamp,
+ htonl(sptr->ip.s_addr), sptr->info);
+ }
+
if(MyClient(sptr))
{
/* if the I:line doesn't have a password and the user does
@@ -2088,7 +2100,7 @@ m_user(aClient *cptr, aClient *sptr, int parc, char *parv[])
/* do_user */
int
do_user(char *nick, aClient *cptr, aClient *sptr, char *username, char *host,
- char *server, unsigned long serviceid, unsigned int ip, char *realname)
+ char *server, unsigned long serviceid, char *ip, char *realname)
{
anUser *user;
@@ -2137,13 +2149,14 @@ do_user(char *nick, aClient *cptr, aClient *sptr, char *username, char *host,
sptr->user->servicestamp = serviceid;
if (!MyConnect(sptr))
{
- sptr->ip.s_addr=ntohl(ip);
-
+ if (inet_pton(AF_INET, ip, &sptr->ip) == 0)
+ sptr->ip.s_addr = ntohl(strtoul(ip, NULL, 10));
+
/* add non-local clients to the throttle checker. obviously, we only
* do this for REMOTE clients!@$$@! throttle_check() is called
* elsewhere for the locals! -wd */
#ifdef THROTTLE_ENABLE
- if (ip != 0)
+ if (sptr->ip.s_addr != 0)
throttle_check(inetntoa((char *)&sptr->ip), -1, sptr->tsinfo);
#endif
}
--
1.7.2.3