[eggheads-patches] PATCH1.4: hostbyteorder_1.4.patch

Fabian Knittel fknittel at gmx.de
Sun Oct 10 17:11:21 CST 1999


[ hostbyteorder_1.4.patch ]

This patch cleans up the byte order used for ip addresses in
several places.

Fabian
-------------- next part --------------
diff -urN eggdrop1.4~/doc/UPDATES1.4 eggdrop1.4/doc/UPDATES1.4
--- eggdrop1.4~/doc/UPDATES1.4	Sun Oct 10 21:41:47 1999
+++ eggdrop1.4/doc/UPDATES1.4	Sun Oct 10 23:28:46 1999
@@ -5,5 +5,7 @@
 
 1.4.0
 Foundby   Fixedby   What....
+arthur2	  Fabian    the dcc[].addr is now consistently host byte order and
+		    all async dns lookup functions accept host byte order IPs
 	  Fabian    added an asynchronous DNS request module which prevents
 		    the bot from hanging on dns lookups.
diff -urN eggdrop1.4~/src/botnet.c eggdrop1.4/src/botnet.c
--- eggdrop1.4~/src/botnet.c	Sun Oct 10 21:41:47 1999
+++ eggdrop1.4/src/botnet.c	Sun Oct 10 22:15:29 1999
@@ -961,7 +961,7 @@
   dcc[i].u.bot->numver = idx;
   dcc[i].u.bot->port = dcc[i].port;		/* remember where i started */
   dcc[i].sock = getsock(SOCK_STRONGCONN);
-  if (open_telnet_raw(dcc[i].sock, iptostr(my_ntohl(dcc[i].addr)),
+  if (open_telnet_raw(dcc[i].sock, iptostr(my_htonl(dcc[i].addr)),
 		      dcc[i].port) < 0)
     failed_link(i);
 }
@@ -1000,7 +1000,7 @@
   dcc[idx].port++;
   dcc[idx].timeval = now;
   if (open_telnet_raw(dcc[idx].sock, dcc[idx].addr ?
-				     iptostr(my_ntohl(dcc[idx].addr)) :
+				     iptostr(my_htonl(dcc[idx].addr)) :
 				     dcc[idx].host, dcc[idx].port) < 0)
     failed_tandem_relay(idx);
 }
@@ -1118,7 +1118,7 @@
   dcc[i].u.relay->chat->line_count = 0;
   dcc[i].u.relay->chat->current_lines = 0;
   dcc[i].timeval = now;
-  if (open_telnet_raw(dcc[i].sock, iptostr(my_ntohl(dcc[i].addr)),
+  if (open_telnet_raw(dcc[i].sock, iptostr(my_htonl(dcc[i].addr)),
 		      dcc[i].port) < 0)
     failed_tandem_relay(i);
 }
diff -urN eggdrop1.4~/src/dcc.c eggdrop1.4/src/dcc.c
--- eggdrop1.4~/src/dcc.c	Sun Oct 10 21:41:47 1999
+++ eggdrop1.4/src/dcc.c	Sun Oct 10 22:15:50 1999
@@ -210,7 +210,7 @@
   dcc[idx].port++;
   dcc[idx].timeval = now;
   if (open_telnet_raw(dcc[idx].sock, dcc[idx].addr ?
-		      iptostr(my_ntohl(dcc[idx].addr)) : dcc[idx].host,
+		      iptostr(my_htonl(dcc[idx].addr)) : dcc[idx].host,
 		      dcc[idx].port) < 0) {
     failed_link(idx);
   }
diff -urN eggdrop1.4~/src/dns.c eggdrop1.4/src/dns.c
--- eggdrop1.4~/src/dns.c	Sun Oct 10 21:41:47 1999
+++ eggdrop1.4/src/dns.c	Sun Oct 10 23:18:24 1999
@@ -6,18 +6,12 @@
  * This file is part of the eggdrop source code.
  *
  * Copyright (C) 1999  Eggheads
- * Copyright (C) 1997  Robey Pointer
+ * Written by Fabian Knittel
  *
  * Distributed according to the GNU General Public License. For full
  * details, read the top of 'main.c' or the file called COPYING that
  * was distributed with this code.
  */
-/*
- * Mon Oct 04 22:24:51 1999  Fabian Knittel
- *     * minor fixes
- * Sun Oct 03 18:34:41 1999  Fabian Knittel
- *     * Initial release
- */
 
 
 #include "main.h"
@@ -101,6 +95,7 @@
 {
   int idx;
   
+  ip = my_ntohl(ip);
   for (idx = 0; idx < dcc_total; idx++) {
     if ((dcc[idx].type == &DCC_DNSWAIT) &&
         (dcc[idx].u.dns->dns_type == RES_HOSTBYIP) &&
@@ -123,6 +118,7 @@
 {
   int idx;
   
+  ip = my_ntohl(ip);
   for (idx = 0; idx < dcc_total; idx++) {
     if ((dcc[idx].type == &DCC_DNSWAIT) &&
         (dcc[idx].u.dns->dns_type == RES_IPBYHOST) &&
@@ -144,31 +140,21 @@
 void block_dns_hostbyip(IP ip)
 {
   struct hostent *hp;
-  unsigned long addr = htonl(ip);
-  unsigned char *p;
+  unsigned long addr = my_htonl(ip);
   static char s[UHOSTLEN];
 
-  /*
-   * This actually copies hostnamefromip(), which is ugly, but there
-   * is no way to determine if the lookup was successful or not, using
-   * that interface.
-   */
   if (!setjmp(alarmret)) {
     alarm(resolve_timeout);
     hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET);
     alarm(0);
-  } else {
-    hp = NULL;
-  }
-  if (hp == NULL) {
-    p = (unsigned char *) &addr;
-    sprintf(s, "%u.%u.%u.%u", p[0], p[1], p[2], p[3]);
-  } else {
     strncpy(s, hp->h_name, UHOSTLEN - 1);
     s[UHOSTLEN - 1] = 0;
+  } else {
+    hp = NULL;
+    strcpy(s, iptostr(addr));
   }
   /* call hooks */
-  call_hostbyip(ip, s, hp ? 1 : 0);
+  call_hostbyip(addr, s, hp ? 1 : 0);
 }
 
 void block_dns_ipbyhost(char *host)
diff -urN eggdrop1.4~/src/eggdrop.h eggdrop1.4/src/eggdrop.h
--- eggdrop1.4~/src/eggdrop.h	Sun Oct 10 21:41:47 1999
+++ eggdrop1.4/src/eggdrop.h	Sun Oct 10 23:24:07 1999
@@ -200,8 +200,9 @@
 struct userrec;
 
 struct dcc_t {
-  long sock;			/* this should be a long to keep 64-bit machines sane */
-  IP addr;
+  long sock;			/* this should be a long to keep 64-bit
+				 * machines sane */
+  IP addr;			/* IP address in host byte order */
   unsigned int port;
   struct userrec *user;
   char nick[NICKLEN];
@@ -209,8 +210,8 @@
   struct dcc_table *type;
   time_t timeval;		/* use for any timing stuff 
 				 * - this is used for timeout checking */
-  unsigned long status;		/* A LOT of dcc types have status thingos, this
-				 * makes it more avaliabe */
+  unsigned long status;		/* A LOT of dcc types have status thingos,
+				 * this makes it more avaliabe */
   union {
     struct chat_info *chat;
     struct file_info *file;
diff -urN eggdrop1.4~/src/mod/server.mod/servmsg.c eggdrop1.4/src/mod/server.mod/servmsg.c
--- eggdrop1.4~/src/mod/server.mod/servmsg.c	Sun Oct 10 21:41:47 1999
+++ eggdrop1.4/src/mod/server.mod/servmsg.c	Sun Oct 10 22:18:12 1999
@@ -1088,7 +1088,9 @@
     dcc[servidx].u.dns->dns_failure = (Function) server_resolve_failure;
     dcc[servidx].u.dns->dns_type = RES_IPBYHOST;
 
+    /* I'm resolving... don't start another server connect request */
     resolvserv = 1;
+    /* resolve the hostname */
     dns_ipbyhost(dcc[servidx].host);
     if (server_cycle_wait)
       /* back to 1st server & set wait time */
@@ -1115,29 +1117,28 @@
   dcc[servidx].addr = dcc[servidx].u.dns->ip;
   strcpy(pass, dcc[servidx].u.dns->cbuf);
   changeover_dcc(servidx, &SERVER_SOCKET, 0);
-  serv = open_telnet(iptostr(my_ntohl(dcc[servidx].addr)),
-				    dcc[servidx].port);
-    if (serv < 0) {
-	neterror(s);
+  serv = open_telnet(iptostr(my_htonl(dcc[servidx].addr)), dcc[servidx].port);
+  if (serv < 0) {
+    neterror(s);
     putlog(LOG_SERV, "*", "%s %s (%s)", IRC_FAILEDCONNECT, dcc[servidx].host,
 	   s);
     lostdcc(servidx);
       if ((oldserv == curserv) && !(never_give_up))
 	fatal("NO SERVERS WILL ACCEPT MY CONNECTION.", 0);
-    } else {
-      dcc[servidx].sock = serv;
+  } else {
+    dcc[servidx].sock = serv;
     /* queue standard login */
-      dcc[servidx].timeval = now;
-      SERVER_SOCKET.timeout_val = &server_timeout;
-      strcpy(botname, origbotname);
-      /* another server may have truncated it :/ */
-      dprintf(DP_MODE, "NICK %s\n", botname);
-      if (pass[0])
-	dprintf(DP_MODE, "PASS %s\n", pass);
-      dprintf(DP_MODE, "USER %s %s %s :%s\n",
+    dcc[servidx].timeval = now;
+    SERVER_SOCKET.timeout_val = &server_timeout;
+    strcpy(botname, origbotname);
+    /* another server may have truncated it :/ */
+    dprintf(DP_MODE, "NICK %s\n", botname);
+    if (pass[0])
+      dprintf(DP_MODE, "PASS %s\n", pass);
+    dprintf(DP_MODE, "USER %s %s %s :%s\n",
 	    botuser, bothost, dcc[servidx].host, botrealname);
-      cycle_time = 0;
-      /* We join channels AFTER getting the 001 -Wild */
-      /* wait for async result now */
+    cycle_time = 0;
+    /* We join channels AFTER getting the 001 -Wild */
+    /* wait for async result now */
   }
 }
diff -urN eggdrop1.4~/src/net.c eggdrop1.4/src/net.c
--- eggdrop1.4~/src/net.c	Sun Oct 10 21:41:47 1999
+++ eggdrop1.4/src/net.c	Sun Oct 10 23:22:48 1999
@@ -487,8 +487,8 @@
   return s;
 }
 
-/* returns a given network-style IP address as a string in the
- * "##.##.##.##" format */
+/* Returns the given network byte order IP address in the
+ * dotted format - "##.##.##.##" */
 char *iptostr(IP ip)
 {
   struct in_addr a;


More information about the Patches mailing list