Author: Bleep <tomh@inxpress.net>
authorBleep <twhelvey1@home.com>
Mon, 27 Mar 2000 03:33:25 +0000 (03:33 +0000)
committerBleep <twhelvey1@home.com>
Mon, 27 Mar 2000 03:33:25 +0000 (03:33 +0000)
Log message:
Sync with ircu2.10.10

git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@64 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

14 files changed:
ChangeLog.10
include/handlers.h
include/msg.h
include/patchlevel.h
include/s_bsd.h
include/uping.h
ircd/Makefile.in
ircd/ircd.c
ircd/m_uping.c [new file with mode: 0644]
ircd/parse.c
ircd/s_bsd.c
ircd/s_conf.c
ircd/s_misc.c
ircd/uping.c

index f5674edf1dea1ab0f1ec62de4a7bad512e7a2381..6bf2630134b0fc98cc230fa00ae87881fcd917d0 100644 (file)
@@ -1,10 +1,13 @@
 #
 # ChangeLog for ircu2.10.10
 #
-# $Id: ChangeLog.10,v 1.4 2000-03-24 10:14:20 bleep Exp $
+# $Id: ChangeLog.10,v 1.5 2000-03-27 03:33:25 bleep Exp $
 #
 # Insert new changes at beginning of the change list.
 #
+* Hookup UPING code again, cleanups --Bleep
+* Convert numerics back to mask and shift extended numerics
+  follow same mechanism --Bleep
 * Fixed bogus errno return on Solaris --Bleep
 * Fixed core on RPING bug, tokenized RPING --Bleep
 * Remove add_local_domain entirely, unused --Bleep
index 5ad4e64ac9a74ea50eb060619d31f3fa6691d18d..dac14ed29e0a3bf73699ca30462626bf365a01b6 100644 (file)
@@ -149,6 +149,7 @@ extern int mo_settime(struct Client*, struct Client*, int, char*[]);
 extern int mo_squit(struct Client*, struct Client*, int, char*[]);
 extern int mo_stats(struct Client*, struct Client*, int, char*[]);
 extern int mo_trace(struct Client*, struct Client*, int, char*[]);
+extern int mo_uping(struct Client*, struct Client*, int, char*[]);
 extern int mo_wallops(struct Client*, struct Client*, int, char*[]);
 extern int mr_error(struct Client*, struct Client*, int, char*[]);
 extern int mr_pong(struct Client*, struct Client*, int, char*[]);
@@ -192,6 +193,7 @@ extern int ms_squit(struct Client*, struct Client*, int, char*[]);
 extern int ms_stats(struct Client*, struct Client*, int, char*[]);
 extern int ms_topic(struct Client*, struct Client*, int, char*[]);
 extern int ms_trace(struct Client*, struct Client*, int, char*[]);
+extern int ms_uping(struct Client*, struct Client*, int, char*[]);
 extern int ms_version(struct Client*, struct Client*, int, char*[]);
 extern int ms_wallchops(struct Client*, struct Client*, int, char*[]);
 extern int ms_wallops(struct Client*, struct Client*, int, char*[]);
index f33a0f7d8156857037957c81484c213039ed65bc..1941d2e9e888dfce5d8df845d64ac91e113412da 100644 (file)
@@ -226,6 +226,9 @@ struct Client;
 #define MSG_BURST               "BURST"         /* BURS */
 #define TOK_BURST               "B"
 
+#define MSG_UPING               "UPING"         /* UPIN */
+#define TOK_UPING               "UP"
+
 #define MSG_CREATE              "CREATE"        /* CREA */
 #define TOK_CREATE              "C"
 
index 14a56fd53074c736451d5a4a31656d2043749ce3..919c966ef6c27c8e7f310b83603d709d84ef6ffc 100644 (file)
@@ -22,7 +22,6 @@
 
 #define RELEASE ".11.alpha."
 
-
 /* Do NOT edit those: */
 
 #ifndef BASE_VERSION
index 3b39f16ed6099b919292f13e1ac527f372d07a6f..581df926f25ce6d5905ca4230de6b444902a28f1 100644 (file)
@@ -49,9 +49,7 @@ extern int            HighestFd;
 extern struct Client* LocalClientArray[MAXCONNECTIONS];
 extern int            OpenFileDescriptorCount;
 
-#ifdef VIRTUAL_HOST
-extern struct sockaddr_in vserv;
-#endif
+extern struct sockaddr_in VirtualHost;
 
 enum PollType {
   PT_NONE,
index a9b3eea263ad763b99a58b3be621595762916ed8..db0984c7a45f690abc7d4cdda31623a5170d1c3c 100644 (file)
@@ -33,6 +33,7 @@
 #endif
 
 struct Client;
+struct ConfItem;
 
 struct UPing
 {
@@ -54,22 +55,16 @@ struct UPing
   char               buf[BUFSIZE];      /* buffer to hold ping times */
 };
 
+extern int UPingFileDescriptor;
 
-/*=============================================================================
- * Proto types
- */
-
-extern int  setup_ping(void);
-extern void polludp(int fd);
-extern void send_ping(struct UPing* pptr);
-extern void read_ping(struct UPing* pptr);
-extern int  m_uping(struct Client *cptr, struct Client *sptr, int parc, char* parv[]);
-extern void end_ping(struct UPing* pptr);
-extern void cancel_ping(struct Client *sptr, struct Client *acptr);
-extern struct UPing* pings_begin(void);
+extern int  uping_init(void);
+extern void uping_send(struct UPing* pptr);
+extern void uping_read(struct UPing* pptr);
+extern void uping_end(struct UPing* pptr);
+extern void uping_cancel(struct Client *sptr, struct Client *acptr);
+extern void uping_echo(void);
+extern struct UPing* uping_begin(void);
+extern int uping_server(struct Client* sptr, struct ConfItem* aconf, int port, int count);
 
-#ifdef DEBUG
-extern void uping_mark_blocks(void);
-#endif
 
 #endif /* INCLUDED_uping_h */
index 26016cb6765c25713a05204172ffa915493303f3..a5e52c1305bcf1453bde93d51d371b31224a29b1 100644 (file)
@@ -132,6 +132,7 @@ SRC = \
        m_time.c \
        m_topic.c \
        m_trace.c \
+       m_uping.c \
        m_user.c \
        m_userhost.c \
        m_userip.c \
@@ -327,13 +328,14 @@ ircd.o: ircd.c ../include/ircd.h ../config/config.h ../config/setup.h \
  ../include/client.h ../include/dbuf.h ../include/ircd_handler.h \
  ../include/crule.h ../include/hash.h ../include/ircd_alloc.h \
  ../include/fda.h ../include/ircd_log.h ../include/ircd_signal.h \
- ../include/ircd_string.h ../include/ircd_chattr.h ../include/list.h \
- ../include/listener.h ../include/match.h ../include/numeric.h \
- ../include/numnicks.h ../include/parse.h ../include/res.h \
- ../include/s_auth.h ../include/s_bsd.h ../include/s_conf.h \
- ../include/s_debug.h ../include/s_misc.h ../include/send.h \
- ../include/sys.h ../include/userload.h ../include/version.h \
- ../include/whowas.h ../include/msg.h
+ ../include/ircd_string.h ../include/ircd_chattr.h ../include/jupe.h \
+ ../include/list.h ../include/listener.h ../include/match.h \
+ ../include/numeric.h ../include/numnicks.h ../include/parse.h \
+ ../include/res.h ../include/s_auth.h ../include/s_bsd.h \
+ ../include/s_conf.h ../include/s_debug.h ../include/s_misc.h \
+ ../include/send.h ../include/sys.h ../include/uping.h \
+ ../include/userload.h ../include/version.h ../include/whowas.h \
+ ../include/msg.h
 ircd_alloc.o: ircd_alloc.c ../include/ircd_alloc.h ../include/fda.h \
  ../include/ircd_string.h ../config/config.h ../config/setup.h \
  ../include/ircd_chattr.h ../include/s_debug.h ../include/ircd_defs.h
@@ -661,8 +663,8 @@ m_rpong.o: m_rpong.c ../include/client.h ../include/dbuf.h \
  ../include/ircd_defs.h ../include/ircd_handler.h ../include/hash.h \
  ../include/ircd.h ../config/config.h ../config/setup.h \
  ../include/struct.h ../include/ircd_reply.h ../include/ircd_string.h \
- ../include/ircd_chattr.h ../include/numeric.h ../include/numnicks.h \
- ../include/opercmds.h ../include/send.h
+ ../include/ircd_chattr.h ../include/msg.h ../include/numeric.h \
+ ../include/numnicks.h ../include/opercmds.h ../include/send.h
 m_server.o: m_server.c ../include/client.h ../include/dbuf.h \
  ../include/ircd_defs.h ../include/ircd_handler.h ../include/crule.h \
  ../include/hash.h ../include/ircd.h ../config/config.h \
@@ -727,6 +729,13 @@ m_trace.o: m_trace.c ../include/class.h ../include/client.h \
  ../include/msg.h ../include/numeric.h ../include/numnicks.h \
  ../include/s_bsd.h ../include/s_conf.h ../include/s_user.h \
  ../include/send.h ../include/version.h
+m_uping.o: m_uping.c ../include/client.h ../include/dbuf.h \
+ ../include/ircd_defs.h ../include/ircd_handler.h ../include/hash.h \
+ ../include/ircd.h ../config/config.h ../config/setup.h \
+ ../include/struct.h ../include/ircd_reply.h ../include/ircd_string.h \
+ ../include/ircd_chattr.h ../include/match.h ../include/msg.h \
+ ../include/numeric.h ../include/numnicks.h ../include/s_conf.h \
+ ../include/s_user.h ../include/send.h ../include/uping.h
 m_user.o: m_user.c ../include/client.h ../include/dbuf.h \
  ../include/ircd_defs.h ../include/ircd_handler.h ../include/ircd.h \
  ../config/config.h ../config/setup.h ../include/struct.h \
@@ -854,7 +863,7 @@ s_bsd.o: s_bsd.c ../include/s_bsd.h ../config/config.h \
  ../include/s_auth.h ../include/s_conf.h ../include/s_debug.h \
  ../include/s_misc.h ../include/s_user.h ../include/send.h \
  ../include/sprintf_irc.h ../include/support.h ../include/sys.h \
- ../include/version.h
+ ../include/uping.h ../include/version.h
 s_conf.o: s_conf.c ../include/s_conf.h ../include/IPcheck.h \
  ../include/class.h ../include/client.h ../include/dbuf.h \
  ../include/ircd_defs.h ../include/ircd_handler.h ../include/crule.h \
@@ -891,7 +900,8 @@ s_misc.o: s_misc.c ../include/s_misc.h ../include/IPcheck.h \
  ../include/parse.h ../include/querycmds.h ../include/res.h \
  ../include/s_bsd.h ../include/s_conf.h ../include/s_debug.h \
  ../include/s_user.h ../include/send.h ../include/sprintf_irc.h \
- ../include/support.h ../include/sys.h ../include/userload.h
+ ../include/support.h ../include/sys.h ../include/uping.h \
+ ../include/userload.h
 s_numeric.o: s_numeric.c ../include/s_numeric.h ../include/channel.h \
  ../config/config.h ../config/setup.h ../include/ircd_defs.h \
  ../include/client.h ../include/dbuf.h ../include/ircd_handler.h \
@@ -945,7 +955,7 @@ uping.o: uping.c ../include/uping.h ../include/ircd_defs.h \
  ../include/struct.h ../include/ircd_alloc.h ../include/fda.h \
  ../include/ircd_log.h ../include/ircd_osdep.h \
  ../include/ircd_string.h ../include/ircd_chattr.h ../include/match.h \
- ../include/numeric.h ../include/numnicks.h ../include/res.h \
+ ../include/msg.h ../include/numeric.h ../include/numnicks.h \
  ../include/s_bsd.h ../include/s_conf.h ../include/s_debug.h \
  ../include/s_misc.h ../include/s_user.h ../include/send.h \
  ../include/sys.h
index 019e856aee6dd96e269c4a2464f4edd7f8fb7c17..59dcbfda92f18611d3c5020e6ac501508b56da89 100644 (file)
@@ -44,6 +44,7 @@
 #include "send.h"
 #include "struct.h"
 #include "sys.h"
+#include "uping.h"
 #include "userload.h"
 #include "version.h"
 #include "whowas.h"
@@ -639,6 +640,7 @@ int main(int argc, char *argv[])
     Debug((DEBUG_FATAL, "Failed to initialize server identity"));
     exit(2);
   }
+  uping_init();
   read_tlines();
   rmotd = read_motd(RPATH);
   motd = read_motd(MPATH);
diff --git a/ircd/m_uping.c b/ircd/m_uping.c
new file mode 100644 (file)
index 0000000..132eef0
--- /dev/null
@@ -0,0 +1,432 @@
+/*
+ * IRC - Internet Relay Chat, ircd/m_uping.c
+ * Copyright (C) 1990 Jarkko Oikarinen and
+ *                    University of Oulu, Computing Center
+ *
+ * See file AUTHORS in IRC package for additional names of
+ * the programmers.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 1, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ */
+
+/*
+ * m_functions execute protocol messages on this server:
+ *
+ *    cptr    is always NON-NULL, pointing to a *LOCAL* client
+ *            structure (with an open socket connected!). This
+ *            identifies the physical socket where the message
+ *            originated (or which caused the m_function to be
+ *            executed--some m_functions may call others...).
+ *
+ *    sptr    is the source of the message, defined by the
+ *            prefix part of the message if present. If not
+ *            or prefix not found, then sptr==cptr.
+ *
+ *            (!IsServer(cptr)) => (cptr == sptr), because
+ *            prefixes are taken *only* from servers...
+ *
+ *            (IsServer(cptr))
+ *                    (sptr == cptr) => the message didn't
+ *                    have the prefix.
+ *
+ *                    (sptr != cptr && IsServer(sptr) means
+ *                    the prefix specified servername. (?)
+ *
+ *                    (sptr != cptr && !IsServer(sptr) means
+ *                    that message originated from a remote
+ *                    user (not local).
+ *
+ *            combining
+ *
+ *            (!IsServer(sptr)) means that, sptr can safely
+ *            taken as defining the target structure of the
+ *            message in this server.
+ *
+ *    *Always* true (if 'parse' and others are working correct):
+ *
+ *    1)      sptr->from == cptr  (note: cptr->from == cptr)
+ *
+ *    2)      MyConnect(sptr) <=> sptr == cptr (e.g. sptr
+ *            *cannot* be a local connection, unless it's
+ *            actually cptr!). [MyConnect(x) should probably
+ *            be defined as (x == x->from) --msa ]
+ *
+ *    parc    number of variable parameter strings (if zero,
+ *            parv is allowed to be NULL)
+ *
+ *    parv    a NULL terminated list of parameter pointers,
+ *
+ *                    parv[0], sender (prefix string), if not present
+ *                            this points to an empty string.
+ *                    parv[1]...parv[parc-1]
+ *                            pointers to additional parameters
+ *                    parv[parc] == NULL, *always*
+ *
+ *            note:   it is guaranteed that parv[0]..parv[parc-1] are all
+ *                    non-NULL pointers.
+ */
+#if 0
+/*
+ * No need to include handlers.h here the signatures must match
+ * and we don't need to force a rebuild of all the handlers everytime
+ * we add a new one to the list. --Bleep
+ */
+#include "handlers.h"
+#endif /* 0 */
+#include "client.h"
+#include "hash.h"
+#include "ircd.h"
+#include "ircd_reply.h"
+#include "ircd_string.h"
+#include "match.h"
+#include "msg.h"
+#include "numeric.h"
+#include "numnicks.h"
+#include "s_conf.h"
+#include "s_user.h"
+#include "send.h"
+#include "uping.h"
+
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+/*
+ * ms_uping - server message handler
+ *
+ * m_uping  -- by Run
+ *
+ * parv[0] = sender prefix
+ * parv[1] = pinged server
+ * parv[2] = port
+ * parv[3] = hunted server
+ * parv[4] = number of requested pings
+ */
+int ms_uping(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
+{
+  struct ConfItem *aconf;
+  int port;
+  int count;
+
+  assert(0 != cptr);
+  assert(0 != sptr);
+
+  if (!IsAnOper(sptr)) {
+    sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]);
+    return 0;
+  }
+
+  if (parc < 5) {
+    sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), me.name, parv[0], "UPING");
+    return 0;
+  }
+
+  if (hunt_server(1, cptr, sptr, "%s%s " TOK_UPING " %s %s %s %s", 3, parc, parv) != HUNTED_ISME)
+    return 0;
+  /*
+   * Determine port: First user supplied, then default : 7007
+   */
+  if (EmptyString(parv[2]) || (port = atoi(parv[2])) <= 0)
+    port = atoi(UDP_PORT);
+
+  if (EmptyString(parv[4]) || (count = atoi(parv[4])) <= 0)
+  {
+    if (MyUser(sptr))
+      sendto_one(sptr, ":%s NOTICE %s :UPING: Illegal number of packets: %s",
+                me.name, parv[0], parv[4]);
+    else
+      sendto_one(sptr, "%s " TOK_NOTICE " %s%s :UPING: Illegal number of packets: %s",
+                NumServ(&me), NumNick(sptr), parv[4]);
+    return 0;
+  }
+  /* 
+   * Check if a CONNECT would be possible at all (adapted from m_connect)
+   */
+  if ((aconf = conf_find_server(parv[1])))
+    uping_server(sptr, aconf, port, count);
+  else {
+    if (MyUser(sptr))
+      sendto_one(sptr, ":%s NOTICE %s :UPING: Host %s not listed in ircd.conf",
+                me.name, parv[0], parv[1]);
+    else
+      sendto_one(sptr, "%s " TOK_NOTICE " %s%s :UPING: Host %s not listed in ircd.conf",
+                NumServ(&me), NumNick(sptr), parv[1]);
+  }
+  return 0;
+}
+
+/*
+ * mo_uping - oper message handler
+ *
+ * m_uping  -- by Run
+ *
+ * parv[0] = sender prefix
+ * parv[1] = pinged server
+ * parv[2] = port
+ * parv[3] = hunted server
+ * parv[4] = number of requested pings
+ */
+int mo_uping(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
+{
+  struct ConfItem *aconf;
+  int port;
+  int count;
+
+  assert(0 != cptr);
+  assert(0 != sptr);
+  assert(cptr == sptr);
+
+  assert(IsAnOper(sptr));
+
+  if (parc < 2) {
+    sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), me.name, parv[0], "UPING");
+    return 0;
+  }
+
+  if (parc == 2) {
+    parv[parc++] = UDP_PORT;
+    parv[parc++] = me.name;
+    parv[parc++] = "5";
+  }
+  else if (parc == 3) {
+    if (IsDigit(*parv[2]))
+      parv[parc++] = me.name;
+    else {
+      parv[parc++] = parv[2];
+      parv[2] = UDP_PORT;
+    }
+    parv[parc++] = "5";
+  }
+  else if (parc == 4) {
+    if (IsDigit(*parv[2])) {
+      if (IsDigit(*parv[3])) {
+        parv[parc++] = parv[3];
+        parv[3] = me.name;
+      }
+      else
+        parv[parc++] = "5";
+    }
+    else {
+      parv[parc++] = parv[3];
+      parv[3] = parv[2];
+      parv[2] = UDP_PORT;
+    }
+  }
+  if (hunt_server(1, cptr, sptr, "%s%s " TOK_UPING " %s %s %s %s", 3, parc, parv) != HUNTED_ISME)
+    return 0;
+  /*
+   * Determine port: First user supplied, then default : 7007
+   */
+  if (EmptyString(parv[2]) || (port = atoi(parv[2])) <= 0)
+    port = atoi(UDP_PORT);
+
+  if (EmptyString(parv[4]) || (count = atoi(parv[4])) <= 0)
+  {
+    if (MyUser(sptr))
+      sendto_one(sptr, ":%s NOTICE %s :UPING: Illegal number of packets: %s",
+                me.name, parv[0], parv[4]);
+    else
+      sendto_one(sptr, "%s " TOK_NOTICE " %s%s :UPING: Illegal number of packets: %s",
+                NumServ(&me), NumNick(sptr), parv[4]);
+    return 0;
+  }
+  /* 
+   * Check if a CONNECT would be possible at all (adapted from m_connect)
+   */
+  if ((aconf = conf_find_server(parv[1])))
+    uping_server(sptr, aconf, port, count);
+  else {
+    if (MyUser(sptr))
+      sendto_one(sptr, ":%s NOTICE %s :UPING: Host %s not listed in ircd.conf",
+                me.name, parv[0], parv[1]);
+    else
+      sendto_one(sptr, "%s " TOK_NOTICE " %s%s :UPING: Host %s not listed in ircd.conf",
+                NumServ(&me), NumNick(sptr), parv[1]);
+  }
+  return 0;
+}
+
+
+#if 0
+/*
+ * m_uping  -- by Run
+ *
+ * parv[0] = sender prefix
+ * parv[1] = pinged server
+ * parv[2] = port
+ * parv[3] = hunted server
+ * parv[4] = number of requested pings
+ */
+int m_uping(struct Client* cptr, struct Client *sptr, int parc, char *parv[])
+{
+  struct ConfItem *aconf;
+  int port;
+  int fd;
+  struct UPing* pptr = 0;
+
+  if (!IsPrivileged(sptr))
+  {
+    sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]);
+    return -1;
+  }
+
+  if (parc < 2)
+  {
+    sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), me.name, parv[0], "UPING");
+    return 0;
+  }
+
+  if (MyUser(sptr))
+  {
+    if (parc == 2)
+    {
+      parv[parc++] = UDP_PORT;
+      parv[parc++] = me.name;
+      parv[parc++] = "5";
+    }
+    else if (parc == 3)
+    {
+      if (IsDigit(*parv[2]))
+       parv[parc++] = me.name;
+      else
+      {
+       parv[parc++] = parv[2];
+       parv[2] = UDP_PORT;
+      }
+      parv[parc++] = "5";
+    }
+    else if (parc == 4)
+    {
+      if (IsDigit(*parv[2]))
+      {
+       if (IsDigit(*parv[3]))
+       {
+         parv[parc++] = parv[3];
+         parv[3] = me.name;
+       }
+       else
+         parv[parc++] = "5";
+      }
+      else
+      {
+       parv[parc++] = parv[3];
+       parv[3] = parv[2];
+       parv[2] = UDP_PORT;
+      }
+    }
+  }
+  if (hunt_server(1, cptr, sptr, ":%s UPING %s %s %s %s", 3, parc, parv) != HUNTED_ISME)
+    return 0;
+
+  if (BadPtr(parv[4]) || atoi(parv[4]) <= 0)
+  {
+    if (MyUser(sptr) || Protocol(cptr) < 10)
+      sendto_one(sptr, ":%s NOTICE %s :UPING: Illegal number of packets: %s",
+         me.name, parv[0], parv[4]);
+    else
+      sendto_one(sptr, "%s NOTICE %s%s :UPING: Illegal number of packets: %s",
+         NumServ(&me), NumNick(sptr), parv[4]);
+    return 0;
+  }
+
+  /* Check if a CONNECT would be possible at all (adapted from m_connect) */
+  for (aconf = GlobalConfList; aconf; aconf = aconf->next)
+  {
+    if (aconf->status == CONF_SERVER &&
+       match(parv[1], aconf->name) == 0)
+      break;
+  }
+  if (!aconf)
+  {
+    for (aconf = GlobalConfList; aconf; aconf = aconf->next)
+    {
+      if (aconf->status == CONF_SERVER &&
+         (match(parv[1], aconf->host) == 0 ||
+          match(parv[1], strchr(aconf->host, '@') + 1) == 0))
+       break;
+    }
+  }
+  if (!aconf)
+  {
+    if (MyUser(sptr) || Protocol(cptr) < 10)
+      sendto_one(sptr, ":%s NOTICE %s :UPING: Host %s not listed in ircd.conf",
+         me.name, parv[0], parv[1]);
+    else
+      sendto_one(sptr,
+         "%s NOTICE %s%s :UPING: Host %s not listed in ircd.conf",
+         NumServ(&me), NumNick(sptr), parv[1]);
+    return 0;
+  }
+
+  if (IsUPing(sptr))
+    cancel_ping(sptr, sptr);  /* Cancel previous ping request */
+
+  /*
+   * Determine port: First user supplied, then default : 7007
+   */
+  if (BadPtr(parv[2]) || (port = atoi(parv[2])) <= 0)
+    port = atoi(UDP_PORT);
+
+  if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
+    int err = errno;
+    sendto_ops("m_uping: socket: %s", (err != EMFILE) 
+                ? ((strerror(err)) ? strerror(err) : "Unknown error") : "No more sockets");
+    if (MyUser(sptr) || Protocol(cptr) < 10)
+      sendto_one(sptr, 
+                 ":%s NOTICE %s :UPING: Unable to create udp ping socket",
+                 me.name, parv[0]);
+    else
+      sendto_one(sptr,
+                 "%s NOTICE %s%s :UPING: Unable to create udp ping socket",
+                 NumServ(&me), NumNick(sptr));
+    ircd_log(L_ERROR, "UPING: Unable to create UDP socket");
+    return 0;
+  }
+
+  if (!os_set_nonblocking(fd)) {
+    if (MyUser(sptr) || Protocol(cptr) < 10)
+      sendto_one(sptr, ":%s NOTICE %s :UPING: Can't set fd non-blocking",
+            me.name, parv[0]);
+    else
+      sendto_one(sptr, "%s NOTICE %s%s :UPING: Can't set fd non-blocking",
+            NumServ(&me), NumNick(sptr));
+    close(fd);
+    return 0;
+  }
+  pptr = (struct UPing*) MyMalloc(sizeof(struct UPing));
+  assert(0 != pptr);
+  memset(pptr, 0, sizeof(struct UPing));
+
+  pptr->fd = fd;
+  pptr->sin.sin_port = htons(port);
+  pptr->sin.sin_addr.s_addr = aconf->ipnum.s_addr;
+  pptr->sin.sin_family = AF_INET;
+  pptr->count = IRCD_MIN(20, atoi(parv[4]));
+  strcpy(pptr->name, aconf->host);
+  pptr->client = sptr;
+  pptr->index = -1;
+
+  pptr->next = pingList;
+  pingList = pptr;
+
+  SetUPing(sptr);
+  ping_server(pptr);
+  return 0;
+}
+#endif /* 0 */
+
index a11ecb8085a889ceceabbb89af5499153ab957df..a3b59ed77fb02a6be9e72bcb3f7f71fcb337d11d 100644 (file)
@@ -446,6 +446,13 @@ struct Message msgtab[] = {
     /* UNREG, CLIENT, SERVER, OPER, SERVICE */
     { m_unregistered, m_jupe, ms_jupe, mo_jupe, m_ignore }
   },
+  {
+    MSG_UPING,
+    TOK_UPING,
+    0, MAXPARA, MFLG_SLOW, 0,
+    /* UNREG, CLIENT, SERVER, OPER, SERVICE */
+    { m_unregistered, m_not_oper, ms_uping, mo_uping, m_ignore }
+  },
   {
     MSG_END_OF_BURST,
     TOK_END_OF_BURST,
index ff963e206fe1375aa6667bb54848ce7db685e3a8..2bd8cb8ff8960a31d12c85f69f10720735a6650f 100644 (file)
@@ -47,6 +47,7 @@
 #include "struct.h"
 #include "support.h"
 #include "sys.h"
+#include "uping.h"
 #include "version.h"
 
 #include <arpa/inet.h>
 #include <sys/poll.h>
 #endif /* USE_POLL */
 
-#ifndef IN_LOOPBACKNET
-#define IN_LOOPBACKNET  0x7f
-#endif
-
 #ifndef INADDR_NONE
 #define INADDR_NONE 0xffffffff
 #endif
 
 struct Client*            LocalClientArray[MAXCONNECTIONS];
 int                       HighestFd = -1;
-static struct sockaddr_in virtualHost;
+struct sockaddr_in        VirtualHost;
 static char               readbuf[SERVER_TCP_WINDOW];
 static int                running_in_background;
 
@@ -99,9 +96,6 @@ const char* const SELECT_ERROR_MSG    = "select error for %s: %s";
 const char* const SETBUFS_ERROR_MSG   = "error setting buffer size for %s: %s";
 const char* const SOCKET_ERROR_MSG    = "error creating socket for %s: %s";
 
-#ifdef VIRTUAL_HOST
-struct sockaddr_in vserv;
-#endif
 
 #ifdef GODMODE
 #ifndef NODNS
@@ -239,7 +233,7 @@ static int connect_inet(struct ConfItem* aconf, struct Client* cptr)
    * explicitly bind it, it will default to IN_ADDR_ANY and we lose
    * due to the other server not allowing our base IP --smg
    */
-  if (bind(cptr->fd, (struct sockaddr*) &virtualHost, sizeof(virtualHost))) {
+  if (bind(cptr->fd, (struct sockaddr*) &VirtualHost, sizeof(VirtualHost))) {
     report_error(BIND_ERROR_MSG, cptr->name, errno);
     return 0;
   }
@@ -846,18 +840,21 @@ static int on_write_unblocked(struct Client* cptr)
 int read_message(time_t delay)
 {
   struct pollfd poll_fds[MAXCONNECTIONS + 1];
-  struct Client*    cptr;
-  struct Listener*    listener  = 0;
-  struct AuthRequest* auth      = 0;
-  struct AuthRequest* auth_next = 0;
-  int nfds;
+  struct Client*      cptr;
+  struct Listener*    listener   = 0;
+  struct AuthRequest* auth       = 0;
+  struct AuthRequest* auth_next  = 0;
+  struct UPing*       uping      = 0;
+  struct UPing*       uping_next = 0;
   time_t delay2 = delay;
+  int nfds;
   int length;
   int i;
   int res = 0;
-  int pfd_count = 0;
-  struct pollfd* pfd = 0;
-  struct pollfd* res_pfd = 0;
+  int pfd_count;
+  struct pollfd* pfd;
+  struct pollfd* res_pfd;
+  struct pollfd* uping_pfd;
   int read_ready;
   int write_ready;
 
@@ -867,12 +864,32 @@ int read_message(time_t delay)
     pfd_count = 0;
     pfd = poll_fds;
     res_pfd = 0;
+    uping_pfd = 0;
     pfd->fd = -1;
 
     if (-1 < ResolverFileDescriptor) {
       PFD_SETR(ResolverFileDescriptor);
       res_pfd = pfd;
     }
+    if (-1 < UPingFileDescriptor) {
+      PFD_SETR(UPingFileDescriptor);
+      uping_pfd = pfd;
+    }
+    /*
+     * add uping descriptors
+     */
+    for (uping = uping_begin(); uping; uping = uping_next) {
+      uping_next = uping->next;
+      if (uping->active) {
+        delay2 = 1;
+       if (uping->lastsent && CurrentTime > uping->timeout) {
+          uping_end(uping);
+          continue;
+        }
+        uping->index = pfd_count;
+        PFD_SETR(uping->fd);
+      }
+    }
     /*
      * add auth file descriptors
      */
@@ -932,6 +949,29 @@ int read_message(time_t delay)
     CurrentTime = time(0);
   }
 
+  if (uping_pfd && (uping_pfd->revents & (POLLREADFLAGS | POLLERRORS))) {
+    uping_echo();
+    --nfds;
+  }
+  /*
+   * check uping replies
+   */
+  for (uping = uping_begin(); uping; uping = uping_next) {
+    uping_next = uping->next;
+    if (uping->active) {
+      assert(-1 < uping->index);
+      if (poll_fds[uping->index].revents) {
+        uping_read(uping);
+        if (0 == --nfds)
+          break;
+      }
+      else if (CurrentTime > uping->lastsent) {
+        uping->lastsent = CurrentTime;
+        uping_send(uping);
+      }
+    }
+  }
+
   if (res_pfd && (res_pfd->revents & (POLLREADFLAGS | POLLERRORS))) {
     resolver_read();
     --nfds;
@@ -1058,6 +1098,10 @@ int read_message(time_t delay)
 {
   struct Client*   cptr;
   struct Listener* listener;
+  struct AuthRequest* auth = 0;
+  struct AuthRequest* auth_next = 0;
+  struct UPing*       uping;
+  struct UPing*       uping_next;
   int              nfds;
   struct timeval   wait;
   time_t           delay2 = delay;
@@ -1065,8 +1109,6 @@ int read_message(time_t delay)
   int              res = 0;
   int              length;
   int              i;
-  struct AuthRequest* auth = 0;
-  struct AuthRequest* auth_next = 0;
   int              read_ready;
   fd_set           read_set;
   fd_set           write_set;
@@ -1078,6 +1120,23 @@ int read_message(time_t delay)
 
     if (-1 < ResolverFileDescriptor)
       FD_SET(ResolverFileDescriptor, &read_set);
+    if (-1 < UPingFileDescriptor)
+      FD_SET(UPingFileDescriptor, &read_set);
+    /*
+     * set up uping file descriptors
+     */
+    for (uping = uping_begin(); uping; uping = uping_next) {
+      uping_next = uping->next;
+      if (uping->active) {
+        delay2 = 1;
+        if (uping->lastsent && CurrentTime > ping->timeout) {
+          uping_end(uping);
+          continue;
+        }
+        assert(-1 < uping->fd);
+        FD_SET(uping->fd, &read_set);
+      }
+    }
     /*
      * set auth file descriptors
      */
@@ -1129,8 +1188,26 @@ int read_message(time_t delay)
     CurrentTime = time(0);
   }
 
-  if (-1 < ResolverFileDescriptor && 
-      FD_ISSET(ResolverFileDescriptor, &read_set)) {
+  if (-1 < UPingFileDescriptor && FD_ISSET(UPingFileDescriptor, &read_set)) {
+    uping_echo();
+    --nfds;
+  }
+  for (uping = uping_begin(); uping; uping = uping_next) {
+    uping_next = uping->next;
+    if (uping->active) {
+      assert(-1 < uping->fd);
+      if (FD_ISSET(uping->fd, &read_set)) {
+        uping_read(uping);
+        if (0 == --nfds)
+          break;
+      }
+      else if (CurrentTime > uping->lastsent) {
+        uping->lastsent = CurrentTime;
+        uping_send(uping);
+      }
+    }
+  }
+  if (-1 < ResolverFileDescriptor && FD_ISSET(ResolverFileDescriptor, &read_set)) {
     resolver_read();
     --nfds;
   }
@@ -1381,16 +1458,16 @@ void init_virtual_host(const struct ConfItem* conf)
 {
   assert(0 != conf);
 
-  memset(&virtualHost, 0, sizeof(virtualHost));
-  virtualHost.sin_family = AF_INET;
-  virtualHost.sin_addr.s_addr = INADDR_ANY;
+  memset(&VirtualHost, 0, sizeof(VirtualHost));
+  VirtualHost.sin_family = AF_INET;
+  VirtualHost.sin_addr.s_addr = INADDR_ANY;
 
   if (EmptyString(conf->passwd) || 0 == strcmp(conf->passwd, "*"))
     return;
-  virtualHost.sin_addr.s_addr = inet_addr(conf->passwd);
+  VirtualHost.sin_addr.s_addr = inet_addr(conf->passwd);
 
-  if (INADDR_NONE == virtualHost.sin_addr.s_addr)
-    virtualHost.sin_addr.s_addr = INADDR_ANY;
+  if (INADDR_NONE == VirtualHost.sin_addr.s_addr)
+    VirtualHost.sin_addr.s_addr = INADDR_ANY;
 }  
 
 /*
index 53baa8e8ba99f7bc6f753678a59ca219b0ce931c..a512dd7aedc8bad0aee80069b455fed69e9bdbf4 100644 (file)
@@ -301,6 +301,7 @@ static void lookup_confhost(struct ConfItem *aconf)
   if (IsDigit(*aconf->host)) {
     /*
      * rfc 1035 sez host names may not start with a digit
+     * XXX - this has changed code needs to be updated
      */
     aconf->ipnum.s_addr = inet_addr(aconf->host);
     if (INADDR_NONE == aconf->ipnum.s_addr) {
index 4cb82723d4f1c5ac2ef781c69a2f44c7d457c227..9d600b6e2b8cba6fbc457b1a1e1ec75b3dde5ffe 100644 (file)
@@ -48,6 +48,7 @@
 #include "struct.h"
 #include "support.h"
 #include "sys.h"
+#include "uping.h"
 #include "userload.h"
 
 #include <assert.h>
@@ -452,6 +453,11 @@ static void exit_one_client(struct Client *bcptr, char *comment)
   if (bcptr->serv && bcptr->serv->client_list)  /* Was SetServerYXX called ? */
     ClearServerYXX(bcptr);      /* Removes server from server_list[] */
   if (IsUser(bcptr)) {
+    /*
+     * clear out uping requests
+     */
+    if (IsUPing(bcptr))
+      uping_cancel(bcptr, 0);
     /*
      * Stop a running /LIST clean
      */
index 68a8121a9f504fdc122808bc3bf39863782d5ba3..fcbda296a94eafda3c80cc583e27e311c6b195c2 100644 (file)
@@ -26,9 +26,9 @@
 #include "ircd_osdep.h"
 #include "ircd_string.h"
 #include "match.h"
+#include "msg.h"
 #include "numeric.h"
 #include "numnicks.h"
-#include "res.h"
 #include "s_bsd.h"    /* vserv */
 #include "s_conf.h"
 #include "s_debug.h"
 #define INADDR_NONE 0xffffffff
 #endif
 
-static void ping_server(struct UPing*);
-
 static struct UPing* pingList = 0;
-int UPingListener = -1; /* UDP listener socket for upings */
+int UPingFileDescriptor       = -1; /* UDP listener socket for upings */
 
 /*
  * pings_begin - iterator function for ping list 
@@ -77,7 +75,7 @@ static void uping_erase(struct UPing* p)
 
   assert(0 != p);
   
-  for (it = pingList; it; last = it = it->next) {
+  for (it = pingList; it; last = it, it = it->next) {
     if (p == it) {
       if (last)
         last->next = p->next;
@@ -88,43 +86,16 @@ static void uping_erase(struct UPing* p)
   }
 }
 
-/*
- * uping_dns_callback - this gets called when the resolver either
- * succeeds or fails to locate the servers address.
- * If the dns query failed hp will be 0, otherwise it
- * will contain the stuff a hostent normally contains.
- */
-static void uping_dns_callback(void* v, struct DNSReply* r)
-{
-  struct UPing* ping = (struct UPing*) v;
-  assert(valid_ptr((void*)ping, sizeof(struct UPing)));
-
-  if (r) {
-    memcpy(&ping->sin.sin_addr, r->hp->h_addr, sizeof(struct in_addr));
-    ping_server(ping);
-  }
-  else
-  {
-    sendto_ops("UDP ping to %s failed: host lookup", ping->name);
-    end_ping(ping);
-  }
-}
-
-
 /*
  * Setup a UDP socket and listen for incoming packets
  */
 int uping_init(void)
 {
-  struct sockaddr_in from;
+  struct sockaddr_in from = { 0 };
   int fd;
 
   memset(&from, 0, sizeof(from));
-#ifdef VIRTUAL_HOST
-  from.sin_addr = vserv.sin_addr;
-#else
-  from.sin_addr.s_addr = htonl(INADDR_ANY);
-#endif
+  from.sin_addr = VirtualHost.sin_addr;
   from.sin_port = htons(atoi(UDP_PORT));
   from.sin_family = AF_INET;
 
@@ -153,6 +124,7 @@ int uping_init(void)
     close(fd);
     return -1;
   }
+  UPingFileDescriptor = fd;
   return fd;
 }
 
@@ -160,17 +132,17 @@ int uping_init(void)
 /*
  * max # of pings set to 15/sec.
  */
-void polludp(int udpfd)
+void uping_echo()
 {
-  struct sockaddr_in from;
+  struct sockaddr_in from = { 0 };
   unsigned int       len = 0;
   static time_t      last = 0;
   static int         counter = 0;
   char               buf[BUFSIZE + 1];
 
-  Debug((DEBUG_DEBUG, "UPING: poll"));
+  Debug((DEBUG_DEBUG, "UPING: uping_echo"));
 
-  if (IO_SUCCESS != os_recvfrom_nonb(udpfd, buf, BUFSIZE, &len, &from))
+  if (IO_SUCCESS != os_recvfrom_nonb(UPingFileDescriptor, buf, BUFSIZE, &len, &from))
     return;
   /*
    * count em even if we're getting flooded so we can tell we're getting
@@ -187,70 +159,38 @@ void polludp(int udpfd)
   }
   if (len < 19)
     return;
-  sendto(udpfd, buf, len, 0, (struct sockaddr *)&from, sizeof(from));
+  sendto(UPingFileDescriptor, buf, len, 0, (struct sockaddr*) &from, sizeof(from));
 }
 
 
 /*
  * start_ping
  */
-static void start_ping(struct UPing* pptr)
+static void uping_start(struct UPing* pptr)
 {
-  assert(valid_ptr((void*) pptr, sizeof(struct UPing)));
+  assert(0 != pptr);
 
-  if (MyUser(pptr->client) || Protocol(pptr->client->from) < 10) {
+  if (MyUser(pptr->client)) {
     sendto_one(pptr->client,
-       ":%s NOTICE %s :Sending %d ping%s to %s[%s] port %d",
-       me.name, pptr->client->name, pptr->count,
-       (pptr->count == 1) ? "" : "s", pptr->name,
-       ircd_ntoa((const char*) &pptr->sin.sin_addr), ntohs(pptr->sin.sin_port));
+              ":%s NOTICE %s :Sending %d ping%s to %s",
+              me.name, pptr->client->name, pptr->count,
+              (pptr->count == 1) ? "" : "s", pptr->name);
   }
-  else
-  {
+  else {
     sendto_one(pptr->client,
-       "%s NOTICE %s%s :Sending %d ping%s to %s[%s] port %d",
-       NumServ(&me), NumNick(pptr->client), pptr->count,
-       (pptr->count == 1) ? "" : "s", pptr->name,
-       ircd_ntoa((const char*) &pptr->sin.sin_addr), ntohs(pptr->sin.sin_port));
+              "%s NOTICE %s%s :Sending %d ping%s to %s",
+              NumServ(&me), NumNick(pptr->client), pptr->count,
+              (pptr->count == 1) ? "" : "s", pptr->name);
   }
   pptr->timeout = CurrentTime + UPINGTIMEOUT;
   pptr->active = 1;
 }
 
 /*
- * ping_server - get the server host address if not valid
- * then call start_ping
- */
-static void ping_server(struct UPing* pptr)
-{
-  if (INADDR_NONE == pptr->sin.sin_addr.s_addr) {
-    char *s;
-
-    if ((s = strchr(pptr->name, '@')))
-      ++s;                     
-    else
-      s = pptr->name;
-
-    if (INADDR_NONE == (pptr->sin.sin_addr.s_addr = inet_addr(s))) {
-      struct DNSQuery query;
-      struct DNSReply* rpl;
-
-      query.vptr = (void*) pptr;
-      query.callback = uping_dns_callback;
-      if (0 == (rpl = gethost_byname(s, &query)))
-       return;
-      memcpy(&pptr->sin.sin_addr, rpl->hp->h_addr, sizeof(struct in_addr));
-    }
-  }
-  start_ping(pptr);
-}
-
-
-/*
- * send_ping
+ * uping_send
  *
  */
-void send_ping(struct UPing* pptr)
+void uping_send(struct UPing* pptr)
 {
   struct timeval tv;
   char buf[BUFSIZE + 1];
@@ -263,31 +203,25 @@ void send_ping(struct UPing* pptr)
 
   Debug((DEBUG_SEND, "send_ping: sending [%s %s] to %s.%d on %d",
          buf, &buf[12],
-         ircd_ntoa((const char*) &pptr->sin.sin_addr), ntohs(pptr->sin.sin_port),
+          ircd_ntoa((const char*) &pptr->sin.sin_addr), ntohs(pptr->sin.sin_port),
          pptr->fd));
 
   if (sendto(pptr->fd, buf, BUFSIZE, 0, (struct sockaddr*) &pptr->sin,
              sizeof(struct sockaddr_in)) != BUFSIZE)
   {
-    int err = errno;
-    if (pptr->client)
-    {
-      if (MyUser(pptr->client)
-#ifndef NO_PROTOCOL9
-         || (IsServer(pptr->client->from) && Protocol(pptr->client->from) < 10)
-#endif
-         )
-       sendto_one(pptr->client, ":%s NOTICE %s :UPING: sendto() failed: %s",
-                  me.name, pptr->client->name,
-                   (strerror(err)) ? strerror(err) : "Unknown error");
+    const char* msg = strerror(errno);
+    if (!msg)
+      msg = "Unknown error";
+    if (pptr->client) {
+      if (MyUser(pptr->client))
+       sendto_one(pptr->client, ":%s NOTICE %s :UPING: send failed: %s",
+                  me.name, pptr->client->name, msg);
       else
        sendto_one(pptr->client, "%s NOTICE %s%s :UPING: sendto() failed: %s",
-                  NumServ(&me), NumNick(pptr->client),
-                   (strerror(err)) ? strerror(err) : "Unknown error");
+                  NumServ(&me), NumNick(pptr->client), msg);
     }
-    Debug((DEBUG_DEBUG, "UPING: send_ping: sendto failed on %d: %s", pptr->fd,
-           (strerror(err)) ? strerror(err) : "Unknown error"));
-    end_ping(pptr);
+    Debug((DEBUG_DEBUG, "UPING: send_ping: sendto failed on %d: %s", pptr->fd, msg));
+    uping_end(pptr);
     return;
   }
   ++pptr->sent;
@@ -296,7 +230,7 @@ void send_ping(struct UPing* pptr)
 /*
  * read_ping
  */
-void read_ping(struct UPing* pptr)
+void uping_read(struct UPing* pptr)
 {
   struct sockaddr_in sin;
   struct timeval     tv;
@@ -314,33 +248,30 @@ void read_ping(struct UPing* pptr)
   if (IO_BLOCKED == ior)
     return;
   else if (IO_FAILURE == ior) {
-    int err = errno;
-    if (MyUser(pptr->client)
-#ifndef NO_PROTOCOL9
-        || (IsServer(pptr->client->from) && Protocol(pptr->client->from) < 10)
-#endif
-        )
-      sendto_one(pptr->client, ":%s NOTICE %s :UPING: recvfrom: %s",
-                 me.name, pptr->client->name, 
-                 (strerror(err)) ? strerror(err) : "Unknown error");
+    const char* msg = strerror(errno);
+    if (!msg)
+      msg = "Unknown error";
+    if (MyUser(pptr->client))
+      sendto_one(pptr->client, ":%s NOTICE %s :UPING: receive error: %s",
+                 me.name, pptr->client->name, msg);
     else
-      sendto_one(pptr->client, "%s NOTICE %s%s :UPING: recvfrom: %s",
-                 NumServ(&me), NumNick(pptr->client),
-                 (strerror(err)) ? strerror(err) : "Unknown error");
-    Debug((DEBUG_SEND, "UPING: read_ping: recvfrom: %d", err));
-    end_ping(pptr);
+      sendto_one(pptr->client, "%s NOTICE %s%s :UPING: receive error: %s",
+                 NumServ(&me), NumNick(pptr->client), msg);
+    uping_end(pptr);
     return;
   }    
 
   if (len < 19)
     return;                    /* Broken packet */
-
+   
   ++pptr->received;
+
+  buf[len] = 0;
   pingtime = (tv.tv_sec - atol(&buf[1])) * 1000
              + (tv.tv_usec - atol(buf + strlen(buf) + 1)) / 1000;
 
   pptr->ms_ave += pingtime;
-  if (!(pptr->ms_min) || (pptr->ms_min > pingtime))
+  if (!pptr->ms_min || pptr->ms_min > pingtime)
     pptr->ms_min = pingtime;
   if (pingtime > pptr->ms_max)
     pptr->ms_max = pingtime;
@@ -348,160 +279,53 @@ void read_ping(struct UPing* pptr)
   pptr->timeout = CurrentTime + UPINGTIMEOUT;
 
   Debug((DEBUG_SEND, "read_ping: %d bytes, ti %lu: [%s %s] %lu ms",
-      len, pptr->timeout, buf, (buf + strlen(buf) + 1), pingtime));
+         len, pptr->timeout, buf, (buf + strlen(buf) + 1), pingtime));
 
   s = pptr->buf + strlen(pptr->buf);
   sprintf(s, " %u", pingtime);
 
   if (pptr->received == pptr->count)
-    end_ping(pptr);
+    uping_end(pptr);
   return;
 }
 
-
-/*
- * m_uping  -- by Run
- *
- * parv[0] = sender prefix
- * parv[1] = pinged server
- * parv[2] = port
- * parv[3] = hunted server
- * parv[4] = number of requested pings
- */
-int m_uping(struct Client* cptr, struct Client *sptr, int parc, char *parv[])
+int uping_server(struct Client* sptr, struct ConfItem* aconf, int port, int count)
 {
-  struct ConfItem *aconf;
-  int port;
   int fd;
-  struct UPing* pptr = 0;
+  struct UPing* pptr;
 
-  if (!IsPrivileged(sptr))
-  {
-    sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]);
-    return -1;
-  }
+  assert(0 != sptr);
+  assert(0 != aconf);
 
-  if (parc < 2)
-  {
-    sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), me.name, parv[0], "UPING");
-    return 0;
-  }
-
-  if (MyUser(sptr))
-  {
-    if (parc == 2)
-    {
-      parv[parc++] = UDP_PORT;
-      parv[parc++] = me.name;
-      parv[parc++] = "5";
-    }
-    else if (parc == 3)
-    {
-      if (IsDigit(*parv[2]))
-       parv[parc++] = me.name;
-      else
-      {
-       parv[parc++] = parv[2];
-       parv[2] = UDP_PORT;
-      }
-      parv[parc++] = "5";
-    }
-    else if (parc == 4)
-    {
-      if (IsDigit(*parv[2]))
-      {
-       if (IsDigit(*parv[3]))
-       {
-         parv[parc++] = parv[3];
-         parv[3] = me.name;
-       }
-       else
-         parv[parc++] = "5";
-      }
-      else
-      {
-       parv[parc++] = parv[3];
-       parv[3] = parv[2];
-       parv[2] = UDP_PORT;
-      }
-    }
-  }
-  if (hunt_server(1, cptr, sptr,
-      ":%s UPING %s %s %s %s", 3, parc, parv) != HUNTED_ISME)
-    return 0;
-
-  if (BadPtr(parv[4]) || atoi(parv[4]) <= 0)
-  {
-    if (MyUser(sptr) || Protocol(cptr) < 10)
-      sendto_one(sptr, ":%s NOTICE %s :UPING: Illegal number of packets: %s",
-         me.name, parv[0], parv[4]);
+  if (INADDR_NONE == aconf->ipnum.s_addr) {
+    if (MyUser(sptr))
+      sendto_one(sptr, ":%s NOTICE %s :UPING: Host lookup failed for %s",
+                 me.name, sptr->name, aconf->name);
     else
-      sendto_one(sptr, "%s NOTICE %s%s :UPING: Illegal number of packets: %s",
-         NumServ(&me), NumNick(sptr), parv[4]);
-    return 0;
-  }
-
-  /* Check if a CONNECT would be possible at all (adapted from m_connect) */
-  for (aconf = GlobalConfList; aconf; aconf = aconf->next)
-  {
-    if (aconf->status == CONF_SERVER &&
-       match(parv[1], aconf->name) == 0)
-      break;
-  }
-  if (!aconf)
-  {
-    for (aconf = GlobalConfList; aconf; aconf = aconf->next)
-    {
-      if (aconf->status == CONF_SERVER &&
-         (match(parv[1], aconf->host) == 0 ||
-          match(parv[1], strchr(aconf->host, '@') + 1) == 0))
-       break;
-    }
-  }
-  if (!aconf)
-  {
-    if (MyUser(sptr) || Protocol(cptr) < 10)
-      sendto_one(sptr, ":%s NOTICE %s :UPING: Host %s not listed in ircd.conf",
-         me.name, parv[0], parv[1]);
-    else
-      sendto_one(sptr,
-         "%s NOTICE %s%s :UPING: Host %s not listed in ircd.conf",
-         NumServ(&me), NumNick(sptr), parv[1]);
-    return 0;
+      sendto_one(sptr, "%s " TOK_NOTICE " %s%s :UPING: Host lookup failed for %s",
+                 NumServ(&me), NumNick(sptr), aconf->name);
   }
 
   if (IsUPing(sptr))
-    cancel_ping(sptr, sptr);  /* Cancel previous ping request */
-
-  /*
-   * Determine port: First user supplied, then default : 7007
-   */
-  if (BadPtr(parv[2]) || (port = atoi(parv[2])) <= 0)
-    port = atoi(UDP_PORT);
+    uping_cancel(sptr, sptr);  /* Cancel previous ping request */
 
   if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
-    int err = errno;
-    sendto_ops("m_uping: socket: %s", (err != EMFILE) 
-                ? ((strerror(err)) ? strerror(err) : "Unknown error") : "No more sockets");
-    if (MyUser(sptr) || Protocol(cptr) < 10)
-      sendto_one(sptr, 
-                 ":%s NOTICE %s :UPING: Unable to create udp ping socket",
-                 me.name, parv[0]);
+    if (MyUser(sptr))
+      sendto_one(sptr, ":%s NOTICE %s :UPING: Unable to create udp ping socket",
+                 me.name, sptr->name);
     else
-      sendto_one(sptr,
-                 "%s NOTICE %s%s :UPING: Unable to create udp ping socket",
+      sendto_one(sptr, "%s " TOK_NOTICE " %s%s :UPING: Unable to create udp ping socket",
                  NumServ(&me), NumNick(sptr));
-    ircd_log(L_ERROR, "UPING: Unable to create UDP socket");
     return 0;
   }
 
   if (!os_set_nonblocking(fd)) {
-    if (MyUser(sptr) || Protocol(cptr) < 10)
+    if (MyUser(sptr))
       sendto_one(sptr, ":%s NOTICE %s :UPING: Can't set fd non-blocking",
-            me.name, parv[0]);
+                 me.name, sptr->name);
     else
-      sendto_one(sptr, "%s NOTICE %s%s :UPING: Can't set fd non-blocking",
-            NumServ(&me), NumNick(sptr));
+      sendto_one(sptr, "%s " TOK_NOTICE " %s%s :UPING: Can't set fd non-blocking",
+                 NumServ(&me), NumNick(sptr));
     close(fd);
     return 0;
   }
@@ -509,86 +333,79 @@ int m_uping(struct Client* cptr, struct Client *sptr, int parc, char *parv[])
   assert(0 != pptr);
   memset(pptr, 0, sizeof(struct UPing));
 
-  pptr->fd = fd;
-  pptr->sin.sin_port = htons(port);
+  pptr->fd                  = fd;
+  pptr->sin.sin_port        = htons(port);
   pptr->sin.sin_addr.s_addr = aconf->ipnum.s_addr;
-  pptr->sin.sin_family = AF_INET;
-  pptr->count = IRCD_MIN(20, atoi(parv[4]));
-  strcpy(pptr->name, aconf->host);
-  pptr->client = sptr;
-  pptr->index = -1;
+  pptr->sin.sin_family      = AF_INET;
+  pptr->count               = IRCD_MIN(20, count);
+  pptr->client              = sptr;
+  pptr->index               = -1;
+  strcpy(pptr->name, aconf->name);
 
   pptr->next = pingList;
-  pingList = pptr;
+  pingList   = pptr;
 
   SetUPing(sptr);
-  ping_server(pptr);
+  uping_start(pptr);
   return 0;
 }
 
-void end_ping(struct UPing* pptr)
+
+void uping_end(struct UPing* pptr)
 {
-  Debug((DEBUG_DEBUG, "end_ping: %p", pptr));
-  delete_resolver_queries((void*) pptr);
-  if (pptr->client)
-  {
-    if (MyUser(pptr->client)
-        || (IsServer(pptr->client->from) && Protocol(pptr->client->from) < 10))
-    {
-      if (pptr->lastsent)      /* Started at all ? */
-      {
-       if (0 < pptr->received) /* Received any pings at all? */
-       {
+  Debug((DEBUG_DEBUG, "uping_end: %p", pptr));
+
+  if (pptr->client) {
+    if (MyUser(pptr->client)) {
+      if (pptr->lastsent) { 
+       if (0 < pptr->received) {
          sendto_one(pptr->client, ":%s NOTICE %s :UPING %s%s",
-             me.name, pptr->client->name, pptr->name, pptr->buf);
-          /* XXX - warning long unsigned int format, unsigned int arg (7, 8, 9) */
+                    me.name, pptr->client->name, pptr->name, pptr->buf);
+          /*
+           * XXX - warning long unsigned int format, unsigned int arg (7, 8, 9)
+           */
          sendto_one(pptr->client,
-             ":%s NOTICE %s :UPING Stats: sent %d recvd %d ; "
-             "min/avg/max = %1lu/%1lu/%1lu ms",
-             me.name, pptr->client->name, pptr->sent,
-             pptr->received, pptr->ms_min,
-             (2 * pptr->ms_ave) / (2 * pptr->received), 
-              pptr->ms_max);
+                    ":%s NOTICE %s :UPING Stats: sent %d recvd %d ; "
+                    "min/avg/max = %1lu/%1lu/%1lu ms",
+                    me.name, pptr->client->name, pptr->sent,
+                    pptr->received, pptr->ms_min,
+                    (2 * pptr->ms_ave) / (2 * pptr->received), 
+                     pptr->ms_max);
        }
        else
          sendto_one(pptr->client,
-             ":%s NOTICE %s :UPING: no response from %s within %d seconds",
-             me.name, pptr->client->name, pptr->name,
-             UPINGTIMEOUT);
+                    ":%s NOTICE %s :UPING: no response from %s within %d seconds",
+                    me.name, pptr->client->name, pptr->name,
+                    UPINGTIMEOUT);
       }
       else
        sendto_one(pptr->client,
-           ":%s NOTICE %s :UPING: Could not start ping to %s %d",
-           me.name, pptr->client->name, pptr->name, ntohs(pptr->sin.sin_port));
+                  ":%s NOTICE %s :UPING: Could not start ping to %s",
+                  me.name, pptr->client->name, pptr->name);
     }
-    else
-    {
-      if (pptr->lastsent)      /* Started at all ? */
-      {
-       if (0 < pptr->received) /* Received any pings at all? */
-       {
+    else {
+      if (pptr->lastsent) {
+       if (0 < pptr->received) {
          sendto_one(pptr->client, "%s NOTICE %s%s :UPING %s%s",
-             NumServ(&me), NumNick(pptr->client), pptr->name, pptr->buf);
+                    NumServ(&me), NumNick(pptr->client), pptr->name, pptr->buf);
           /* XXX - warning: long unsigned int format, unsigned int arg(9, 10, 11) */
          sendto_one(pptr->client,
-             "%s NOTICE %s%s :UPING Stats: sent %d recvd %d ; "
-             "min/avg/max = %1lu/%1lu/%1lu ms",
-             NumServ(&me), NumNick(pptr->client), pptr->sent,
-             pptr->received, pptr->ms_min,
-             (2 * pptr->ms_ave) / (2 * pptr->received), 
-              pptr->ms_max);
+                    "%s " TOK_NOTICE " %s%s :UPING Stats: sent %d recvd %d ; "
+                    "min/avg/max = %1lu/%1lu/%1lu ms",
+                    NumServ(&me), NumNick(pptr->client), pptr->sent,
+                    pptr->received, pptr->ms_min,
+                    (2 * pptr->ms_ave) / (2 * pptr->received), 
+                     pptr->ms_max);
        }
        else
          sendto_one(pptr->client,
-             "%s NOTICE %s%s :UPING: no response from %s within %d seconds",
-             NumServ(&me), NumNick(pptr->client), pptr->name,
-             UPINGTIMEOUT);
+                    "%s " TOK_NOTICE " %s%s :UPING: no response from %s within %d seconds",
+                    NumServ(&me), NumNick(pptr->client), pptr->name, UPINGTIMEOUT);
       }
       else
        sendto_one(pptr->client,
-           "%s NOTICE %s%s :UPING: Could not start ping to %s %d",
-           NumServ(&me), NumNick(pptr->client), pptr->name, 
-            ntohs(pptr->sin.sin_port));
+                  "%s " TOK_NOTICE " %s%s :UPING: Could not start ping to %s",
+                  NumServ(&me), NumNick(pptr->client), pptr->name);
     }
   }
   close(pptr->fd);
@@ -599,7 +416,7 @@ void end_ping(struct UPing* pptr)
   MyFree(pptr);
 }
 
-void cancel_ping(struct Client *sptr, struct Client* acptr)
+void uping_cancel(struct Client *sptr, struct Client* acptr)
 {
   struct UPing* ping;
   struct UPing* ping_next;
@@ -609,9 +426,10 @@ void cancel_ping(struct Client *sptr, struct Client* acptr)
     ping_next = ping->next;
     if (sptr == ping->client) {
       ping->client = acptr;
-      end_ping(ping);
+      uping_end(ping);
     }
   }
   ClearUPing(sptr);
 }
 
+