Author: Isomer <isomer@coders.net>
[ircu2.10.12-pk.git] / ircd / s_bsd.c
index 7860bc97f39b0610b4ca2ad39a4dac300c9b99b9..c9d6f76a4361f1496093867e9b83b07065ad68f7 100644 (file)
 #include "hash.h"
 #include "ircd_log.h"
 #include "ircd_osdep.h"
+#include "ircd_reply.h"
 #include "ircd_string.h"
 #include "ircd.h"
 #include "list.h"
 #include "listener.h"
+#include "msg.h"
+#include "msgq.h"
 #include "numeric.h"
 #include "numnicks.h"
 #include "packet.h"
@@ -47,6 +50,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;
 
 /*
  * report_error text constants
@@ -98,10 +97,8 @@ const char* const REUSEADDR_ERROR_MSG = "error setting SO_REUSEADDR for %s: %s";
 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";
+const char* const TOS_ERROR_MSG              = "error setting TOS for %s: %s";
 
-#ifdef VIRTUAL_HOST
-struct sockaddr_in vserv;
-#endif
 
 #ifdef GODMODE
 #ifndef NODNS
@@ -156,24 +153,21 @@ void report_error(const char* text, const char* who, int err)
   static time_t last_notice = 0;
   int           errtmp = errno;   /* debug may change 'errno' */
   const char*   errmsg = (err) ? strerror(err) : "";
-  
-  if (!who)
+
+  if (!errmsg)
+    errmsg = "Unknown error"; 
+
+  if (EmptyString(who))
     who = "unknown";
 
   if (last_notice + 20 < CurrentTime) {
     /*
      * pace error messages so opers don't get flooded by transients
      */
-    sendto_ops(text, who, errmsg);
+    sendto_opmask_butone(0, SNO_OLDSNO, text, who, errmsg);
     last_notice = CurrentTime;
   }
-
-  ircd_log(L_ERROR, text, who, errmsg);
-
-  if (!running_in_background) {
-    fprintf(stderr, text, who, errmsg);
-    fprintf(stderr, "\n");
-  }
+  log_write(LS_SOCKET, L_ERROR, 0, text, who, errmsg);
   errno = errtmp;
 }
 
@@ -193,9 +187,44 @@ static void connect_dns_callback(void* vptr, struct DNSReply* reply)
     connect_server(aconf, 0, reply);
   }
   else
-    sendto_ops("Connect to %s failed: host lookup", aconf->name);
+    sendto_opmask_butone(0, SNO_OLDSNO, "Connect to %s failed: host lookup",
+                         aconf->name);
 }
 
+/*
+ * close_connections - closes all connections
+ * close stderr if specified
+ */
+void close_connections(int close_stderr)
+{
+  int i;
+  close(0);
+  close(1);
+  if (close_stderr)
+    close(2);
+  for (i = 3; i < MAXCONNECTIONS; ++i)
+    close(i);
+}
+
+/*
+ * init_connection_limits - initialize process fd limit to
+ * MAXCONNECTIONS
+ */
+int init_connection_limits(void)
+{
+  int limit = os_set_fdlimit(MAXCONNECTIONS);
+  if (0 == limit)
+    return 1;
+  if (limit < 0) {
+    fprintf(stderr, "error setting max fd's to %d\n", limit);
+  }
+  else if (limit > 0) {
+    fprintf(stderr, "ircd fd table too big\nHard Limit: %d IRC max: %d\n",
+            limit, MAXCONNECTIONS);
+    fprintf(stderr, "set MAXCONNECTIONS to a smaller value");
+  }
+  return 0;
+}
 
 /*
  * connect_inet - set up address and port and make a connection
@@ -209,16 +238,16 @@ static int connect_inet(struct ConfItem* aconf, struct Client* cptr)
    * Might as well get sockhost from here, the connection is attempted
    * with it so if it fails its useless.
    */
-  cptr->fd = socket(AF_INET, SOCK_STREAM, 0);
-  if (-1 == cptr->fd) {
-    cptr->error = errno;
-    report_error(SOCKET_ERROR_MSG, cptr->name, errno);
+  cli_fd(cptr) = socket(AF_INET, SOCK_STREAM, 0);
+  if (-1 == cli_fd(cptr)) {
+    cli_error(cptr) = errno;
+    report_error(SOCKET_ERROR_MSG, cli_name(cptr), errno);
     return 0;
   }
-  if (cptr->fd >= MAXCLIENTS) {
-    report_error(CONNLIMIT_ERROR_MSG, cptr->name, 0);
-    close(cptr->fd);
-    cptr->fd = -1;
+  if (cli_fd(cptr) >= MAXCLIENTS) {
+    report_error(CONNLIMIT_ERROR_MSG, cli_name(cptr), 0);
+    close(cli_fd(cptr));
+    cli_fd(cptr) = -1;
     return 0;
   }
   /*
@@ -237,8 +266,8 @@ 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))) {
-    report_error(BIND_ERROR_MSG, cptr->name, errno);
+  if (bind(cli_fd(cptr), (struct sockaddr*) &VirtualHost, sizeof(VirtualHost))) {
+    report_error(BIND_ERROR_MSG, cli_name(cptr), errno);
     return 0;
   }
 #endif
@@ -250,28 +279,28 @@ static int connect_inet(struct ConfItem* aconf, struct Client* cptr)
   /*
    * save connection info in client
    */
-  cptr->ip.s_addr = aconf->ipnum.s_addr;
-  cptr->port      = aconf->port;
-  ircd_ntoa_r(cptr->sock_ip, (const char*) &cptr->ip);
+  (cli_ip(cptr)).s_addr = aconf->ipnum.s_addr;
+  cli_port(cptr)        = aconf->port;
+  ircd_ntoa_r(cli_sock_ip(cptr), (const char*) &(cli_ip(cptr)));
   /*
    * we want a big buffer for server connections
    */
-  if (!os_set_sockbufs(cptr->fd, SERVER_TCP_WINDOW)) {
-    cptr->error = errno;
-    report_error(SETBUFS_ERROR_MSG, cptr->name, errno);
+  if (!os_set_sockbufs(cli_fd(cptr), SERVER_TCP_WINDOW)) {
+    cli_error(cptr) = errno;
+    report_error(SETBUFS_ERROR_MSG, cli_name(cptr), errno);
     return 0;
   }
   /*
    * ALWAYS set sockets non-blocking
    */
-  if (!os_set_nonblocking(cptr->fd)) {
-    cptr->error = errno;
-    report_error(NONB_ERROR_MSG, cptr->name, errno);
+  if (!os_set_nonblocking(cli_fd(cptr))) {
+    cli_error(cptr) = errno;
+    report_error(NONB_ERROR_MSG, cli_name(cptr), errno);
     return 0;
   }
-  if (!os_connect_nonb(cptr->fd, &sin)) {
-    cptr->error = errno;
-    report_error(CONNECT_ERROR_MSG, cptr->name, errno);
+  if (!os_connect_nonb(cli_fd(cptr), &sin)) {
+    cli_error(cptr) = errno;
+    report_error(CONNECT_ERROR_MSG, cli_name(cptr), errno);
     return 0;
   }
   return 1;
@@ -300,98 +329,54 @@ static int connect_inet(struct ConfItem* aconf, struct Client* cptr)
  *      net.loads today anyway. Commented out the alarms to save cpu.
  *      --Run
  */
-size_t deliver_it(struct Client *cptr, const char *str, size_t len)
+unsigned int deliver_it(struct Client *cptr, struct MsgQ *buf)
 {
-  size_t bytes_written = 0;
+  unsigned int bytes_written = 0;
+  unsigned int bytes_count = 0;
   assert(0 != cptr);
 
-  switch (os_send_nonb(cptr->fd, str, len, &bytes_written)) {
+  switch (os_sendv_nonb(cli_fd(cptr), buf, &bytes_count, &bytes_written)) {
   case IO_SUCCESS:
-    cptr->flags &= ~FLAGS_BLOCKED;
+    cli_flags(cptr) &= ~FLAGS_BLOCKED;
 
-    cptr->sendB += bytes_written;
-    me.sendB    += bytes_written;
-    if (cptr->sendB > 1023) {
-      cptr->sendK += (cptr->sendB >> 10);
-      cptr->sendB &= 0x03ff;    /* 2^10 = 1024, 3ff = 1023 */
+    cli_sendB(cptr) += bytes_written;
+    cli_sendB(&me)  += bytes_written;
+    if (cli_sendB(cptr) > 1023) {
+      cli_sendK(cptr) += (cli_sendB(cptr) >> 10);
+      cli_sendB(cptr) &= 0x03ff;    /* 2^10 = 1024, 3ff = 1023 */
     }
-    if (me.sendB > 1023) {
-      me.sendK += (me.sendB >> 10);
-      me.sendB &= 0x03ff;
+    if (cli_sendB(&me) > 1023) {
+      cli_sendK(&me) += (cli_sendB(&me) >> 10);
+      cli_sendB(&me) &= 0x03ff;
     }
-    if (bytes_written < len)
-      cptr->flags |= FLAGS_BLOCKED;
+    /*
+     * XXX - hrmm.. set blocked here? the socket didn't
+     * say it was blocked
+     */
+    if (bytes_written < bytes_count)
+      cli_flags(cptr) |= FLAGS_BLOCKED;
     break;
   case IO_BLOCKED:
-    cptr->flags |= FLAGS_BLOCKED;
+    cli_flags(cptr) |= FLAGS_BLOCKED;
     break;
   case IO_FAILURE:
-    cptr->error = errno;
-    cptr->flags |= FLAGS_DEADSOCKET;
+    cli_error(cptr) = errno;
+    cli_flags(cptr) |= FLAGS_DEADSOCKET;
     break;
   }
   return bytes_written;
 }
 
-/*
- * init_sys
- */
-void init_sys(void)
-{
-  int fd;
-  int limit = os_set_fdlimit(MAXCONNECTIONS);
-  if (limit < 0) {
-    fprintf(stderr, "error setting max fd's to %d\n", limit);
-    exit(2);
-  }
-  else if (limit > 0) {
-    fprintf(stderr, "ircd fd table too big\nHard Limit: %d IRC max: %d\n",
-            limit, MAXCONNECTIONS);
-    fprintf(stderr, "set MAXCONNECTIONS to a smaller value");
-    exit(2);
-  }
-
-  for (fd = 3; fd < MAXCONNECTIONS; ++fd)
-  {
-    close(fd);
-    LocalClientArray[fd] = NULL;
-  }
-  LocalClientArray[2] = 0;
-  LocalClientArray[1] = 0;
-  LocalClientArray[0] = 0;
-  close(1);
-  close(0);
-
-  if (bootopt & BOOT_TTY) {
-    /* debugging is going to a tty */
-    init_resolver();
-    return;
-  }
-  if (!(bootopt & BOOT_DEBUG))
-    close(2);
-
-  if (fork())
-    exit(0);
-  running_in_background = 1;
-#ifdef TIOCNOTTY
-  if ((fd = open("/dev/tty", O_RDWR)) > -1) {
-    ioctl(fd, TIOCNOTTY, 0);
-    close(fd);
-  }
-#endif
-  setsid();
-  init_resolver();
-}
 
 void release_dns_reply(struct Client* cptr)
 {
   assert(0 != cptr);
   assert(MyConnect(cptr));
 
-  if (cptr->dns_reply) {
-    assert(0 < cptr->dns_reply->ref_count);
-    --cptr->dns_reply->ref_count;
-    cptr->dns_reply = 0;
+  if (cli_dns_reply(cptr)) {
+    assert(0 < cli_dns_reply(cptr)->ref_count);
+    --(cli_dns_reply(cptr))->ref_count;
+    cli_dns_reply(cptr) = 0;
   }
 }
 
@@ -417,22 +402,22 @@ static int completed_connection(struct Client* cptr)
    * get the socket status from the fd first to check if
    * connection actually succeeded
    */
-  if ((cptr->error = os_get_sockerr(cptr->fd))) {
-    sendto_ops("Connection failed to %s: %s", cptr->name,
-               strerror(cptr->error));
+  if ((cli_error(cptr) = os_get_sockerr(cli_fd(cptr)))) {
+    const char* msg = strerror(cli_error(cptr));
+    if (!msg)
+      msg = "Unknown error";
+    sendto_opmask_butone(0, SNO_OLDSNO, "Connection failed to %s: %s",
+                         cli_name(cptr), msg);
     return 0;
   }
-  if (!(aconf = find_conf_byname(cptr->confs, cptr->name, CONF_SERVER))) {
-    sendto_ops("Lost Server Line for %s", cptr->name);
+  if (!(aconf = find_conf_byname(cli_confs(cptr), cli_name(cptr), CONF_SERVER))) {
+    sendto_opmask_butone(0, SNO_OLDSNO, "Lost Server Line for %s", cli_name(cptr));
     return 0;
   }
+
   if (!EmptyString(aconf->passwd))
-    sendto_one(cptr, "PASS :%s", aconf->passwd);
+    sendrawto_one(cptr, MSG_PASS " :%s", aconf->passwd);
 
-#if 0 
-  /* dead code, already done in connect_server */
-  make_server(cptr);
-#endif
   /*
    * Create a unique timestamp
    */
@@ -440,22 +425,23 @@ static int completed_connection(struct Client* cptr)
   for (i = HighestFd; i > -1; --i) {
     if ((acptr = LocalClientArray[i]) && 
         (IsServer(acptr) || IsHandshake(acptr))) {
-      if (acptr->serv->timestamp >= newts)
-        newts = acptr->serv->timestamp + 1;
+      if (cli_serv(acptr)->timestamp >= newts)
+        newts = cli_serv(acptr)->timestamp + 1;
     }
   }
-  assert(0 != cptr->serv);
+  assert(0 != cli_serv(cptr));
 
-  cptr->serv->timestamp = newts;
+  cli_serv(cptr)->timestamp = newts;
   SetHandshake(cptr);
   /*
    * Make us timeout after twice the timeout for DNS look ups
    */
-  cptr->lasttime = CurrentTime;
-  cptr->flags |= FLAGS_PINGSENT;
-  sendto_one(cptr, "SERVER %s 1 " TIME_T_FMT " " TIME_T_FMT " J%s %s%s :%s",
-             me.name, me.serv->timestamp, newts, MAJOR_PROTOCOL, 
-             NumServCap(&me), me.info);
+  cli_lasttime(cptr) = CurrentTime;
+  cli_flags(cptr) |= FLAGS_PINGSENT;
+
+  sendrawto_one(cptr, MSG_SERVER " %s 1 %Tu %Tu J%s %s%s :%s",
+                cli_name(&me), cli_serv(&me)->timestamp, newts, MAJOR_PROTOCOL, 
+                NumServCap(&me), cli_info(&me));
 
   return (IsDead(cptr)) ? 0 : 1;
 }
@@ -472,11 +458,11 @@ void close_connection(struct Client *cptr)
 
   if (IsServer(cptr)) {
     ServerStats->is_sv++;
-    ServerStats->is_sbs += cptr->sendB;
-    ServerStats->is_sbr += cptr->receiveB;
-    ServerStats->is_sks += cptr->sendK;
-    ServerStats->is_skr += cptr->receiveK;
-    ServerStats->is_sti += CurrentTime - cptr->firsttime;
+    ServerStats->is_sbs += cli_sendB(cptr);
+    ServerStats->is_sbr += cli_receiveB(cptr);
+    ServerStats->is_sks += cli_sendK(cptr);
+    ServerStats->is_skr += cli_receiveK(cptr);
+    ServerStats->is_sti += CurrentTime - cli_firsttime(cptr);
     if (ServerStats->is_sbs > 1023) {
       ServerStats->is_sks += (ServerStats->is_sbs >> 10);
       ServerStats->is_sbs &= 0x3ff;
@@ -489,7 +475,7 @@ void close_connection(struct Client *cptr)
      * If the connection has been up for a long amount of time, schedule
      * a 'quick' reconnect, else reset the next-connect cycle.
      */
-    if ((aconf = find_conf_exact(cptr->name, 0, cptr->sockhost, CONF_SERVER))) {
+    if ((aconf = find_conf_exact(cli_name(cptr), 0, cli_sockhost(cptr), CONF_SERVER))) {
       /*
        * Reschedule a faster reconnect, if this was a automaticly
        * connected configuration entry. (Note that if we have had
@@ -497,7 +483,7 @@ void close_connection(struct Client *cptr)
        * CONF_ILLEGAL). But only do this if it was a "good" link.
        */
       aconf->hold = CurrentTime;
-      aconf->hold += (aconf->hold - cptr->since > HANGONGOODLINK) ?
+      aconf->hold += (aconf->hold - cli_since(cptr) > HANGONGOODLINK) ?
                      HANGONRETRYDELAY : ConfConFreq(aconf);
       if (nextconnect > aconf->hold)
         nextconnect = aconf->hold;
@@ -505,11 +491,11 @@ void close_connection(struct Client *cptr)
   }
   else if (IsUser(cptr)) {
     ServerStats->is_cl++;
-    ServerStats->is_cbs += cptr->sendB;
-    ServerStats->is_cbr += cptr->receiveB;
-    ServerStats->is_cks += cptr->sendK;
-    ServerStats->is_ckr += cptr->receiveK;
-    ServerStats->is_cti += CurrentTime - cptr->firsttime;
+    ServerStats->is_cbs += cli_sendB(cptr);
+    ServerStats->is_cbr += cli_receiveB(cptr);
+    ServerStats->is_cks += cli_sendK(cptr);
+    ServerStats->is_ckr += cli_receiveK(cptr);
+    ServerStats->is_cti += CurrentTime - cli_firsttime(cptr);
     if (ServerStats->is_cbs > 1023) {
       ServerStats->is_cks += (ServerStats->is_cbs >> 10);
       ServerStats->is_cbs &= 0x3ff;
@@ -522,24 +508,25 @@ void close_connection(struct Client *cptr)
   else
     ServerStats->is_ni++;
 
-  if (-1 < cptr->fd) {
+  if (-1 < cli_fd(cptr)) {
     flush_connections(cptr);
-    LocalClientArray[cptr->fd] = 0;
-    close(cptr->fd);
-    cptr->fd = -1;
+    LocalClientArray[cli_fd(cptr)] = 0;
+    close(cli_fd(cptr));
+    cli_fd(cptr) = -1;
   }
-  cptr->flags |= FLAGS_DEADSOCKET;
+  cli_flags(cptr) |= FLAGS_DEADSOCKET;
 
-  DBufClear(&cptr->sendQ);
-  DBufClear(&cptr->recvQ);
-  memset(cptr->passwd, 0, sizeof(cptr->passwd));
+  MsgQClear(&(cli_sendQ(cptr)));
+  client_drop_sendq(cli_connect(cptr));
+  DBufClear(&(cli_recvQ(cptr)));
+  memset(cli_passwd(cptr), 0, sizeof(cli_passwd(cptr)));
   set_snomask(cptr, 0, SNO_SET);
 
   det_confs_butmask(cptr, 0);
 
-  if (cptr->listener) {
-    release_listener(cptr->listener);
-    cptr->listener = 0;
+  if (cli_listener(cptr)) {
+    release_listener(cli_listener(cptr));
+    cli_listener(cptr) = 0;
   }
 
   for ( ; HighestFd > 0; --HighestFd) {
@@ -557,8 +544,7 @@ int net_close_unregistered_connections(struct Client* source)
 
   for (i = HighestFd; i > 0; --i) {
     if ((cptr = LocalClientArray[i]) && !IsRegistered(cptr)) {
-      sendto_one(source, rpl_str(RPL_CLOSING), me.name, source->name,
-                 get_client_name(source, HIDE_IP), cptr->status);
+      send_reply(source, RPL_CLOSING, get_client_name(source, HIDE_IP));
       exit_client(source, cptr, &me, "Oper Closing");
       ++count;
     }
@@ -566,80 +552,74 @@ int net_close_unregistered_connections(struct Client* source)
   return count;
 }
 
-/*
+/*----------------------------------------------------------------------------
+ * add_connection
+ *
  * Creates a client which has just connected to us on the given fd.
  * The sockhost field is initialized with the ip# of the host.
  * The client is not added to the linked list of clients, it is
  * passed off to the auth handler for dns and ident queries.
- */
-void add_connection(struct Listener* listener, int fd)
-{
+ *--------------------------------------------------------------------------*/
+void add_connection(struct Listener* listener, int fd) {
   struct sockaddr_in addr;
-  struct Client*     new_client;
+  struct Client      *new_client;
   time_t             next_target = 0;
+
   const char* const throttle_message =
-         "ERRORYour host is trying to (re)connect too fast -- throttled\r\n";
+         "ERROR :Your host is trying to (re)connect too fast -- throttled\r\n";
        /* 12345678901234567890123456789012345679012345678901234567890123456 */
   
   assert(0 != listener);
+
   /*
-   * Removed preliminary access check. Full check is performed in
-   * m_server and m_user instead. Also connection time out help to
-   * get rid of unwanted connections.
+   * Removed preliminary access check. Full check is performed in m_server and
+   * m_user instead. Also connection time out help to get rid of unwanted
+   * connections.  
    */
   if (!os_get_peername(fd, &addr) || !os_set_nonblocking(fd)) {
     ++ServerStats->is_ref;
     close(fd);
     return;
   }
-  /*
-   * XXX - do we really want to do this? is it needed?
-   */
-  os_disable_options(fd);
 
   /*
    * Add this local client to the IPcheck registry.
-   * If it is a connection to a user port and if the site has been throttled,
-   * reject the user.
+   *
+   * If they're throttled, murder them, but tell them why first.
    */
   if (!IPcheck_local_connect(addr.sin_addr, &next_target) && !listener->server) {
     ++ServerStats->is_ref;
-    /*
-     * strlen(throttle_message) == 66
-     */
-    send(fd, throttle_message, 66, 0);
-    close(fd);
-    return;
+     write(fd, throttle_message, strlen(throttle_message));
+     close(fd);
+     return;
   }
 
-  new_client = make_client(NULL,
-      (listener->server) ? STAT_UNKNOWN_SERVER : STAT_UNKNOWN_USER);
+  new_client = make_client(0, ((listener->server) ? 
+                               STAT_UNKNOWN_SERVER : STAT_UNKNOWN_USER));
+
   /*
-   * Copy ascii address to 'sockhost' just in case. Then we
-   * have something valid to put into error messages...
+   * Copy ascii address to 'sockhost' just in case. Then we have something
+   * valid to put into error messages...  
    */
-  ircd_ntoa_r(new_client->sock_ip, (const char*) &addr.sin_addr);   
-  strcpy(new_client->sockhost, new_client->sock_ip);
-  new_client->ip.s_addr = addr.sin_addr.s_addr;
-  new_client->port      = ntohs(addr.sin_port);
+  ircd_ntoa_r(cli_sock_ip(new_client), (const char*) &addr.sin_addr);   
+  strcpy(cli_sockhost(new_client), cli_sock_ip(new_client));
+  (cli_ip(new_client)).s_addr = addr.sin_addr.s_addr;
+  cli_port(new_client)        = ntohs(addr.sin_port);
 
   if (next_target)
-    new_client->nexttarget = next_target;
-
-  new_client->fd = fd;
+    cli_nexttarget(new_client) = next_target;
 
-  if (!listener->server)
-    SetIPChecked(new_client);
-  new_client->listener = listener;
+  cli_fd(new_client) = fd;
+  cli_listener(new_client) = listener;
   ++listener->ref_count;
 
   Count_newunknown(UserStats);
-  /*
-   * if we've made it this far we can put the client on the auth query pile
-   */
+  /* if we've made it this far we can put the client on the auth query pile */
   start_auth(new_client);
 }
 
+
 /*
  * read_packet
  *
@@ -650,23 +630,23 @@ void add_connection(struct Listener* listener, int fd)
  */
 static int read_packet(struct Client *cptr, int socket_ready)
 {
-  size_t dolen = 0;
-  size_t length = 0;
+  unsigned int dolen = 0;
+  unsigned int length = 0;
 
-  if (socket_ready && !(IsUser(cptr) && DBufLength(&cptr->recvQ) > CLIENT_FLOOD)) {
-    switch (os_recv_nonb(cptr->fd, readbuf, sizeof(readbuf), &length)) {
+  if (socket_ready && !(IsUser(cptr) && DBufLength(&(cli_recvQ(cptr))) > CLIENT_FLOOD)) {
+    switch (os_recv_nonb(cli_fd(cptr), readbuf, sizeof(readbuf), &length)) {
     case IO_SUCCESS:
       if (length) {
-        cptr->lasttime = CurrentTime;
-        if (cptr->lasttime > cptr->since)
-          cptr->since = cptr->lasttime;
-        cptr->flags &= ~(FLAGS_PINGSENT | FLAGS_NONL);
+        cli_lasttime(cptr) = CurrentTime;
+        if (cli_lasttime(cptr) > cli_since(cptr))
+          cli_since(cptr) = cli_lasttime(cptr);
+        cli_flags(cptr) &= ~(FLAGS_PINGSENT | FLAGS_NONL);
       }
       break;
     case IO_BLOCKED:
       break;
     case IO_FAILURE:
-      cptr->error = errno;
+      cli_error(cptr) = errno;
       /* cptr->flags |= FLAGS_DEADSOCKET; */
       return 0;
     }
@@ -685,20 +665,20 @@ static int read_packet(struct Client *cptr, int socket_ready)
      * it on the end of the receive queue and do it when its
      * turn comes around.
      */
-    if (length > 0 && 0 == dbuf_put(&cptr->recvQ, readbuf, length)) {
+    if (length > 0 && 0 == dbuf_put(&(cli_recvQ(cptr)), readbuf, length)) {
       return exit_client(cptr, cptr, &me, "dbuf_put fail");
     }
 #ifndef NOFLOODCONTROL
     /*
      * XXX - cptr will always be a user or unregistered
      */
-    if (IsUser(cptr) && DBufLength(&cptr->recvQ) > CLIENT_FLOOD)
+    if (IsUser(cptr) && DBufLength(&(cli_recvQ(cptr))) > CLIENT_FLOOD)
       return exit_client(cptr, cptr, &me, "Excess Flood");
 
-    while (DBufLength(&cptr->recvQ) && !NoNewLine(cptr) && 
-           (IsTrusted(cptr) || cptr->since - CurrentTime < 10))
+    while (DBufLength(&(cli_recvQ(cptr))) && !NoNewLine(cptr) && 
+           (IsTrusted(cptr) || cli_since(cptr) - CurrentTime < 10))
 #else
-    while (DBufLength(&cptr->recvQ) && !NoNewLine(cptr))
+    while (DBufLength(&(cli_recvQ(cptr))) && !NoNewLine(cptr))
 #endif
     {
       /*
@@ -706,10 +686,10 @@ static int read_packet(struct Client *cptr, int socket_ready)
        * then skip the per-message parsing below.
        */
       if (IsServer(cptr)) {
-        dolen = dbuf_get(&cptr->recvQ, readbuf, sizeof(readbuf));
+        dolen = dbuf_get(&(cli_recvQ(cptr)), readbuf, sizeof(readbuf));
         return (dolen) ? server_dopacket(cptr, readbuf, dolen) : 1;
       }
-      dolen = dbuf_getmsg(&cptr->recvQ, cptr->buffer, BUFSIZE);
+      dolen = dbuf_getmsg(&(cli_recvQ(cptr)), cli_buffer(cptr), BUFSIZE);
       /*
        * Devious looking...whats it do ? well..if a client
        * sends a *long* message without any CR or LF, then
@@ -719,10 +699,10 @@ static int read_packet(struct Client *cptr, int socket_ready)
        * -avalon
        */
       if (0 == dolen) {
-        if (DBufLength(&cptr->recvQ) < 510)
-          cptr->flags |= FLAGS_NONL;
+        if (DBufLength(&(cli_recvQ(cptr))) < 510)
+          cli_flags(cptr) |= FLAGS_NONL;
         else
-          DBufClear(&cptr->recvQ);
+          DBufClear(&(cli_recvQ(cptr)));
       }
       else if (CPTR_KILLED == client_dopacket(cptr, dolen))
         return CPTR_KILLED;
@@ -736,12 +716,12 @@ static int on_write_unblocked(struct Client* cptr)
   /*
    *  ...room for writing, empty some queue then...
    */
-  cptr->flags &= ~FLAGS_BLOCKED;
+  cli_flags(cptr) &= ~FLAGS_BLOCKED;
   if (IsConnecting(cptr)) {
     if (!completed_connection(cptr))
       return 0;
   }
-  else if (cptr->listing && DBufLength(&cptr->sendQ) < 2048)
+  else if (cli_listing(cptr) && MsgQLength(&(cli_sendQ(cptr))) < 2048)
     list_next_channels(cptr, 64);
   send_queued(cptr);
   return 1;
@@ -842,33 +822,56 @@ 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;
 
-  unsigned long timeout;
+  unsigned int timeout;
 
   for ( ; ; ) {
     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
      */
@@ -896,13 +899,13 @@ int read_message(time_t delay)
     for (i = HighestFd; -1 < i; --i) {
       if ((cptr = LocalClientArray[i])) {
 
-        if (DBufLength(&cptr->recvQ))
+        if (DBufLength(&(cli_recvQ(cptr))))
           delay2 = 1;
-        if (DBufLength(&cptr->recvQ) < 4088 || IsServer(cptr)) {
+        if (DBufLength(&(cli_recvQ(cptr))) < 4088 || IsServer(cptr)) {
           PFD_SETR(i);
         }
-        if (DBufLength(&cptr->sendQ) || IsConnecting(cptr) ||
-            (cptr->listing && DBufLength(&cptr->sendQ) < 2048)) {
+        if (MsgQLength(&(cli_sendQ(cptr))) || IsConnecting(cptr) ||
+            (cli_listing(cptr) && MsgQLength(&(cli_sendQ(cptr))) < 2048)) {
           PFD_SETW(i);
         }
       }
@@ -920,7 +923,7 @@ int read_message(time_t delay)
 
     if (EINTR == errno)
       return -1;
-    report_error(POLL_ERROR_MSG, me.name, errno);
+    report_error(POLL_ERROR_MSG, cli_name(&me), errno);
     ++res;
     if (res > 5)
       server_restart("too many poll errors");
@@ -928,6 +931,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;
@@ -988,8 +1014,10 @@ int read_message(time_t delay)
     }
     if (write_ready) {
       if (!on_write_unblocked(cptr) || IsDead(cptr)) {
-        exit_client(cptr, cptr, &me,
-                    cptr->error ? strerror(cptr->error) : LastDeadComment(cptr));
+        const char* msg = (cli_error(cptr)) ? strerror(cli_error(cptr)) : cli_info(cptr);
+        if (!msg)
+          msg = "Unknown error";
+        exit_client(cptr, cptr, &me, msg);
         continue;
       }
     }
@@ -1005,13 +1033,15 @@ int read_message(time_t delay)
       flush_connections(poll_cptr[i]);
 #endif
     if (IsDead(cptr)) {
-      exit_client(cptr, cptr, &me,
-         cptr->error ? strerror(cptr->error) : LastDeadComment(cptr));
+      const char* msg = (cli_error(cptr)) ? strerror(cli_error(cptr)) : cli_info(cptr);
+      if (!msg)
+        msg = "Unknown error";
+      exit_client(cptr, cptr, &me, (char*) msg);
       continue;
     }
     if (length > 0)
       continue;
-    cptr->flags |= FLAGS_DEADSOCKET;
+    cli_flags(cptr) |= FLAGS_DEADSOCKET;
     /*
      * ...hmm, with non-blocking sockets we might get
      * here from quite valid reasons, although.. why
@@ -1023,13 +1053,15 @@ int read_message(time_t delay)
      */
     Debug((DEBUG_ERROR, "READ ERROR: fd = %d %d %d", pfd->fd, errno, length));
 
-    if ((IsServer(cptr) || IsHandshake(cptr)) && cptr->error == 0 && length == 0)
+    if ((IsServer(cptr) || IsHandshake(cptr)) && cli_error(cptr) == 0 && length == 0)
       exit_client_msg(cptr, cptr, &me, "Server %s closed the connection (%s)",
-                      cptr->name, cptr->serv->last_error_msg);
-    else
-      exit_client_msg(cptr, cptr, &me, "Read error to %s: %s",
-                      get_client_name(cptr, HIDE_IP), 
-                      (cptr->error) ?  strerror(cptr->error) : "EOF from client");
+                      cli_name(cptr), cli_serv(cptr)->last_error_msg);
+    else {
+      const char* msg = (cli_error(cptr)) ? strerror(cli_error(cptr)) : "EOF from client";
+      if (!msg)
+        msg = "Unknown error";
+      exit_client_msg(cptr, cptr, &me, "Read error: %s", msg);
+    }
   }
   return 0;
 }
@@ -1047,15 +1079,17 @@ 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;
-  unsigned long    usec = 0;
+  unsigned int     usec = 0;
   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;
@@ -1067,6 +1101,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 > uping->timeout) {
+          uping_end(uping);
+          continue;
+        }
+        assert(-1 < uping->fd);
+        FD_SET(uping->fd, &read_set);
+      }
+    }
     /*
      * set auth file descriptors
      */
@@ -1087,12 +1138,12 @@ int read_message(time_t delay)
 
     for (i = HighestFd; i > -1; --i) {
       if ((cptr = LocalClientArray[i])) {
-        if (DBufLength(&cptr->recvQ))
+        if (DBufLength(&(cli_recvQ(cptr))))
           delay2 = 1;
-        if (DBufLength(&cptr->recvQ) < 4088 || IsServer(cptr))
+        if (DBufLength(&(cli_recvq(cptr))) < 4088 || IsServer(cptr))
           FD_SET(i, &read_set);
-        if (DBufLength(&cptr->sendQ) || IsConnecting(cptr) ||
-            (cptr->listing && DBufLength(&cptr->sendQ) < 2048))
+        if (MsgQLength(&(cli_sendq(cptr))) || IsConnecting(cptr) ||
+            (cli_listing(cptr) && MsgQLength(&(cli_sendQ(cptr))) < 2048))
           FD_SET(i, &write_set);
       }
     }
@@ -1111,15 +1162,33 @@ int read_message(time_t delay)
 
     if (errno == EINTR)
       return -1;
-    report_error(SELECT_ERROR_MSG, me.name, errno);
+    report_error(SELECT_ERROR_MSG, cli_name(&me), errno);
     if (++res > 5)
       server_restart("too many select errors");
     sleep(1);
     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;
   }
@@ -1159,10 +1228,12 @@ int read_message(time_t delay)
       if (FD_ISSET(i, &write_set)) {
         --nfds;
         if (!on_write_unblocked(cptr) || IsDead(cptr)) {
+          const char* msg = (cli_error(cptr)) ? strerror(cli_error(cptr)) : cli_info(cptr);
+          if (!msg)
+            msg = "Unknown error";
           if (FD_ISSET(i, &read_set))
             --nfds;
-          exit_client(cptr, cptr, &me,
-                      cptr->error ? strerror(cptr->error) : LastDeadComment(cptr));
+          exit_client(cptr, cptr, &me, msg);
           continue;
         }
       }
@@ -1174,15 +1245,11 @@ int read_message(time_t delay)
       if (CPTR_KILLED == (length = read_packet(cptr, read_ready)))
         continue;
     }
-#if 0
-    /* Bullshit, why would we want to flush sockets while using non-blocking?
-     * This uses > 4% cpu! --Run */
-    if (length > 0)
-      flush_connections(LocalClientArray[i]);
-#endif
     if (IsDead(cptr)) {
-      exit_client(cptr, cptr, &me,
-              cptr->error ? strerror(cptr->error) : LastDeadComment(cptr));
+      const char* msg = (cli_error(cptr)) ? strerror(cli_error(cptr)) : cli_info(cptr);
+      if (!msg)
+        msg = "Unknown error";
+      exit_client(cptr, cptr, &me, msg);
       continue;
     }
     if (length > 0)
@@ -1197,15 +1264,17 @@ int read_message(time_t delay)
      * in due course, select() returns that fd as ready
      * for reading even though it ends up being an EOF. -avalon
      */
-    Debug((DEBUG_ERROR, "READ ERROR: fd = %d %d %d", i, cptr->error, length));
+    Debug((DEBUG_ERROR, "READ ERROR: fd = %d %d %d", i, cli_error(cptr), length));
 
-    if ((IsServer(cptr) || IsHandshake(cptr)) && cptr->error == 0 && length == 0)
+    if ((IsServer(cptr) || IsHandshake(cptr)) && cli_error(cptr) == 0 && length == 0)
       exit_client_msg(cptr, cptr, &me, "Server %s closed the connection (%s)",
-                      cptr->name, cptr->serv->last_error_msg);
-    else
-      exit_client_msg(cptr, cptr, &me, "Read error to %s: %s",
-                      get_client_name(cptr, HIDE_IP),
-                      cptr->error ? strerror(cptr->error) : "EOF from client");
+                      cli_name(cptr), cli_serv(cptr)->last_error_msg);
+    else {
+      const char* msg = (cli_error(cptr)) ? strerror(cli_error(cptr)) : "EOF from client";
+      if (!msg)
+        msg = "Unknown error";
+      exit_client_msg(cptr, cptr, &me, "Read error: %s", msg);
+    }
   }
   return 0;
 }
@@ -1232,7 +1301,8 @@ int connect_server(struct ConfItem* aconf, struct Client* by,
   assert(0 != aconf);
 
   if (aconf->dns_pending) {
-    sendto_ops("Server %s connect DNS pending");
+    sendto_opmask_butone(0, SNO_OLDSNO, "Server %s connect DNS pending",
+                         aconf->name);
     return 0;
   }
   Debug((DEBUG_NOTICE, "Connect to %s[@%s]", aconf->name,
@@ -1240,22 +1310,18 @@ int connect_server(struct ConfItem* aconf, struct Client* by,
 
   if ((cptr = FindClient(aconf->name))) {
     if (IsServer(cptr) || IsMe(cptr)) {
-      sendto_ops("Server %s already present from %s", 
-                 aconf->name, cptr->from->name);
+      sendto_opmask_butone(0, SNO_OLDSNO, "Server %s already present from %s", 
+                           aconf->name, cli_name(cli_from(cptr)));
       if (by && IsUser(by) && !MyUser(by)) {
-        sendto_one(by, "%s NOTICE %s%s :Server %s already present from %s",
-                     NumServ(&me), NumNick(by), aconf->name, cptr->from->name);
+        sendcmdto_one(&me, CMD_NOTICE, by, "%C :Server %s already present "
+                      "from %s", by, aconf->name, cli_name(cli_from(cptr)));
       }
       return 0;
     }
     else if (IsHandshake(cptr) || IsConnecting(cptr)) {
       if (by && IsUser(by)) {
-        if (MyUser(by))
-          sendto_one(by, ":%s NOTICE %s :Connection to %s already in progress",
-                     me.name, by->name, cptr->name);
-        else
-          sendto_one(by, "%s NOTICE %s%s :Connection to %s already in progress",
-                     NumServ(&me), NumNick(by), cptr->name);
+        sendcmdto_one(&me, CMD_NOTICE, by, "%C :Connection to %s already in "
+                      "progress", by, cli_name(cptr));
       }
       return 0;
     }
@@ -1287,13 +1353,13 @@ int connect_server(struct ConfItem* aconf, struct Client* by,
   cptr = make_client(NULL, STAT_UNKNOWN_SERVER);
   if (reply)
     ++reply->ref_count;
-  cptr->dns_reply = reply;
+  cli_dns_reply(cptr) = reply;
 
   /*
    * Copy these in so we have something for error detection.
    */
-  ircd_strncpy(cptr->name, aconf->name, HOSTLEN);
-  ircd_strncpy(cptr->sockhost, aconf->host, HOSTLEN);
+  ircd_strncpy(cli_name(cptr), aconf->name, HOSTLEN);
+  ircd_strncpy(cli_sockhost(cptr), aconf->host, HOSTLEN);
 
   /*
    * Attach config entries to client here rather than in
@@ -1301,11 +1367,12 @@ int connect_server(struct ConfItem* aconf, struct Client* by,
    */
   attach_confs_byhost(cptr, aconf->host, CONF_SERVER);
 
-  if (!find_conf_byhost(cptr->confs, aconf->host, CONF_SERVER)) {
-    sendto_ops("Host %s is not enabled for connecting: no C-line", aconf->name);
+  if (!find_conf_byhost(cli_confs(cptr), aconf->host, CONF_SERVER)) {
+    sendto_opmask_butone(0, SNO_OLDSNO, "Host %s is not enabled for "
+                         "connecting: no C-line", aconf->name);
     if (by && IsUser(by) && !MyUser(by)) {
-      sendto_one(by, "%s NOTICE %s%s :Connect to host %s failed: no C-line",
-                 NumServ(&me), NumNick(by), aconf->name);
+      sendcmdto_one(&me, CMD_NOTICE, by, "%C :Connect to host %s failed: no "
+                    "C-line", by, aconf->name);
     }
     det_confs_butmask(cptr, 0);
     free_client(cptr);
@@ -1316,8 +1383,8 @@ int connect_server(struct ConfItem* aconf, struct Client* by,
    */
   if (!connect_inet(aconf, cptr)) {
     if (by && IsUser(by) && !MyUser(by)) {
-      sendto_one(by, "%s NOTICE %s%s :Couldn't connect to %s",
-                 NumServ(&me), NumNick(by), cptr->name);
+      sendcmdto_one(&me, CMD_NOTICE, by, "%C :Couldn't connect to %s", by,
+                    cli_name(cptr));
     }
     det_confs_butmask(cptr, 0);
     free_client(cptr);
@@ -1332,23 +1399,29 @@ int connect_server(struct ConfItem* aconf, struct Client* by,
    */
   make_server(cptr);
   if (by && IsUser(by)) {
-    sprintf_irc(cptr->serv->by, "%s%s", NumNick(by));
-    assert(0 == cptr->serv->user);
-    cptr->serv->user = by->user;
-    by->user->refcnt++;
+    sprintf_irc(cli_serv(cptr)->by, "%s%s", NumNick(by));
+    assert(0 == cli_serv(cptr)->user);
+    cli_serv(cptr)->user = cli_user(by);
+    cli_user(by)->refcnt++;
   }
   else {
-    *cptr->serv->by = '\0';
+    *(cli_serv(cptr))->by = '\0';
     /* strcpy(cptr->serv->by, "Auto"); */
   }
-  cptr->serv->up = &me;
+  cli_serv(cptr)->up = &me;
   SetConnecting(cptr);
 
-  if (cptr->fd > HighestFd)
-    HighestFd = cptr->fd;
-  LocalClientArray[cptr->fd] = cptr;
+  if (cli_fd(cptr) > HighestFd)
+    HighestFd = cli_fd(cptr);
+
+  
+  LocalClientArray[cli_fd(cptr)] = cptr;
 
   Count_newunknown(UserStats);
+  /* Actually we lie, the connect hasn't succeeded yet, but we have a valid
+   * cptr, so we register it now.
+   * Maybe these two calls should be merged.
+   */
   add_client_to_list(cptr);
   hAddClient(cptr);
   nextping = CurrentTime;
@@ -1359,20 +1432,11 @@ int connect_server(struct ConfItem* aconf, struct Client* by,
 /*
  * Setup local socket structure to use for binding to.
  */
-void init_virtual_host(const struct ConfItem* conf)
+void set_virtual_host(struct in_addr addr)
 {
-  assert(0 != conf);
-
-  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);
-
-  if (INADDR_NONE == virtualHost.sin_addr.s_addr)
-    virtualHost.sin_addr.s_addr = INADDR_ANY;
+  memset(&VirtualHost, 0, sizeof(VirtualHost));
+  VirtualHost.sin_family = AF_INET;
+  VirtualHost.sin_addr.s_addr = addr.s_addr;
 }  
 
 /*
@@ -1380,17 +1444,13 @@ void init_virtual_host(const struct ConfItem* conf)
  * matches the server's name) and its primary IP#.  Hostname is stored
  * in the client structure passed as a pointer.
  */
-int init_server_identity()
+void init_server_identity(void)
 {
-  struct ConfItem* conf = find_me();
-
-  if (!conf || EmptyString(conf->host))
-    return 0;
-
-  ircd_strncpy(me.name, conf->host, HOSTLEN);
+  const struct LocalConf* conf = conf_get_local();
+  assert(0 != conf);
 
-  init_virtual_host(conf);
-  return 1;
+  ircd_strncpy(cli_name(&me), conf->name, HOSTLEN);
+  SetYXXServerName(&me, conf->numeric);
 }