[OpenAFS-devel] fixed host addr logging patch

nneul@umr.edu nneul@umr.edu
Fri, 1 Jun 2001 10:45:59 -0500


Index: util/afsutil.h
===================================================================
RCS file: /cvs/openafs/src/util/afsutil.h,v
retrieving revision 1.8
diff -u -r1.8 afsutil.h
--- util/afsutil.h	2001/04/30 07:05:30	1.8
+++ util/afsutil.h	2001/06/01 15:44:55
@@ -58,6 +58,7 @@
 
 /* Convert a 4 byte integer to a text string. */
 extern char*	afs_inet_ntoa(afs_uint32 addr);
+extern char*	afs_inet_ntoa_r(afs_uint32 addr);
 
 
 /* copy strings, converting case along the way. */
Index: util/hostparse.c
===================================================================
RCS file: /cvs/openafs/src/util/hostparse.c,v
retrieving revision 1.3
diff -u -r1.3 hostparse.c
--- util/hostparse.c	2001/04/04 20:36:19	1.3
+++ util/hostparse.c	2001/06/01 15:44:55
@@ -229,6 +231,24 @@
     struct in_addr temp;
     temp.s_addr = addr;
     return (char *) inet_ntoa(temp);
+}
+
+/* same as above, but to a non-static buffer, must be freed by called */
+char* afs_inet_ntoa_r(afs_uint32 addr)
+{
+    char *buf;
+    int temp;
+
+    temp = ntohl(addr);
+    buf = (char *) malloc(16); /* length of xxx.xxx.xxx.xxx\0 */
+    buf[15] = 0;
+
+    sprintf(buf, "%d.%d.%d.%d", 
+	(temp >> 24 ) & 0xff,
+	(temp >> 16 ) & 0xff, 
+	(temp >> 8  ) & 0xff,
+	(temp       ) & 0xff);
+    return buf;
 }
 
 /*
Index: tviced/Makefile
===================================================================
RCS file: /cvs/openafs/src/tviced/Makefile,v
retrieving revision 1.7
diff -u -r1.7 Makefile
--- tviced/Makefile	2001/05/18 01:22:16	1.7
+++ tviced/Makefile	2001/06/01 15:44:55
@@ -45,7 +45,8 @@
 	 ${UTILOBJS} ${DIROBJS} ${VOLOBJS} ${FSINTOBJS}
 
 LIBS=	${SRCDIR}lib/libafsauthent.a	\
-	${SRCDIR}lib/libafsrpc.a
+	${SRCDIR}lib/libafsrpc.a \
+	${SRCDIR}lib/afs/util.a
 
 include ../config/Makefile.version
 
Index: viced/host.c
===================================================================
RCS file: /cvs/openafs/src/viced/host.c,v
retrieving revision 1.2
diff -u -r1.2 host.c
--- viced/host.c	2000/11/04 10:06:16	1.2
+++ viced/host.c	2001/06/01 15:44:55
@@ -986,9 +986,11 @@
 		    goto retry;
 		}
 	} else {
-	   	ViceLog(0,("CB: WhoAreYou failed for %x.%d, error %d\n", 
-			host->host, host->port, code));
+		char *hoststr = afs_inet_ntoa_r(host->host);
+	   	ViceLog(0,("CB: WhoAreYou failed for %s:%d, error %d\n", 
+			hoststr, ntohs(host->port), code));
 	        host->hostFlags |= VENUSDOWN;
+		free(hoststr);
 	}
 	host->hostFlags |= ALTADDR;
 	h_Unlock_r(host);
@@ -1085,9 +1087,11 @@
 		}
 	   }
 	   if (code) {
-	   	ViceLog(0,("CB: RCallBackConnectBack failed for %x.%d\n", 
-			host->host, host->port));
+		char *hoststr = afs_inet_ntoa_r(host->host);
+	   	ViceLog(0,("CB: RCallBackConnectBack failed for %s:%d\n", 
+			hoststr, ntohs(host->port)));
 	        host->hostFlags |= VENUSDOWN;
+		free(hoststr);
 	    }
 	    else
 		host->hostFlags |= RESETDONE;
@@ -1905,10 +1909,12 @@
 		    host->hostFlags |= ALTADDR; /* alternate addresses valid */
 		    if ( code )
 		    {
+			char *hoststr = afs_inet_ntoa_r(host->host);
 		    	ViceLog(0,
-			    ("CB: RCallBackConnectBack (host.c) failed for host %x.%d\n",
-			    host->host, host->port));
+			    ("CB: RCallBackConnectBack (host.c) failed for host %s:%d\n",
+			    hoststr, ntohs(host->port)));
 		    	host->hostFlags |= VENUSDOWN;
+			free(hoststr);
 		     }
 		    /* Note:  it's safe to delete hosts even if they have call
 		     * back state, because break delayed callbacks (called when a
@@ -1927,10 +1933,12 @@
 			H_LOCK
 			if(code) {
 			    if ( MultiProbeAlternateAddress_r(host) ) {
+				char *hoststr = afs_inet_ntoa_r(host->host);
 		    		ViceLog(0,
-					("ProbeUuid failed for host %x.%d\n",
-					 host->host, host->port));
+					("ProbeUuid failed for host %s:%d\n",
+					 hoststr, ntohs(host->port)));
 		        	host->hostFlags |= VENUSDOWN;
+				free(hoststr);
 			    }
 			}
 		    } else {
@@ -1938,9 +1946,11 @@
 			code = RXAFSCB_Probe(host->callback_rxcon);
 			H_LOCK
 			if (code) {
-		    	    ViceLog(0, ("ProbeUuid failed for host %x.%d\n",
-				    host->host, host->port));
+			    char *hoststr = afs_inet_ntoa_r(host->host);
+		    	    ViceLog(0, ("ProbeUuid failed for host %s:%d\n",
+				    hoststr, ntohs(host->port)));
 		            host->hostFlags |= VENUSDOWN;
+			    free(hoststr);
 			}
 		    }
 		}
Index: viced/viced.c
===================================================================
RCS file: /cvs/openafs/src/viced/viced.c,v
retrieving revision 1.5
diff -u -r1.5 viced.c
--- viced/viced.c	2001/05/14 21:41:12	1.5
+++ viced/viced.c	2001/06/01 15:44:55
@@ -599,10 +599,13 @@
 	ViceLog(0, ("Can't find address for FileServer '%s'\n",	FS_HostName));
     }
     else {
+      char *hoststr;
       bcopy(he->h_addr, &FS_HostAddr_NBO, 4);
+      hoststr = afs_inet_ntoa_r(FS_HostAddr_NBO);
       FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
-      ViceLog(0,("FileServer %s has address 0x%x (0x%x in host byte order)\n",
-		 FS_HostName, FS_HostAddr_NBO, FS_HostAddr_HBO));
+      ViceLog(0,("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
+		 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
+      free(hoststr);
     }
 
     /* Install handler to catch the shutdown signal */