From 429c2eb913b225a8a4e3fd2bc597005770e080bd Mon Sep 17 00:00:00 2001 From: Nathan Neulinger Date: Fri, 1 Jun 2001 20:14:58 +0000 Subject: [PATCH] log-host-addrs-as-dotted-quad-not-hex-in-viced-20010601 so you get a dotted quad and byte-correct port instead of a hex ip and a potentially byteswapped port number from viced log messages --- src/tviced/Makefile | 3 ++- src/util/afsutil.h | 2 +- src/util/hostparse.c | 18 ++++++++++++++++++ src/viced/host.c | 30 ++++++++++++++++++++---------- src/viced/viced.c | 7 +++++-- 5 files changed, 46 insertions(+), 14 deletions(-) diff --git a/src/tviced/Makefile b/src/tviced/Makefile index 5049e950f..83bab934b 100644 --- a/src/tviced/Makefile +++ b/src/tviced/Makefile @@ -45,7 +45,8 @@ objects= ${VICEDOBJS} ${VLSERVEROBJS} ${LWPOBJS} ${LIBACLOBJS} \ ${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 diff --git a/src/util/afsutil.h b/src/util/afsutil.h index d2ff8c419..35fb5c4c3 100644 --- a/src/util/afsutil.h +++ b/src/util/afsutil.h @@ -58,7 +58,7 @@ extern char *vctime(const time_t *atime); /* 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. */ extern char *lcstring(char *d, char *s, int n); diff --git a/src/util/hostparse.c b/src/util/hostparse.c index f0ba15769..a49f9b199 100644 --- a/src/util/hostparse.c +++ b/src/util/hostparse.c @@ -231,6 +231,24 @@ char* afs_inet_ntoa(afs_uint32 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; +} + /* * gettmpdir() -- Returns pointer to global temporary directory string. * Always succeeds. Never attempt to deallocate directory string. diff --git a/src/viced/host.c b/src/viced/host.c index 19e3bd38c..bba7bbc33 100644 --- a/src/viced/host.c +++ b/src/viced/host.c @@ -986,9 +986,11 @@ retry: 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 @@ retry: } } 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 @@ int CheckHost(host, held) 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 @@ int CheckHost(host, held) 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 @@ int CheckHost(host, held) 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); } } } diff --git a/src/viced/viced.c b/src/viced/viced.c index d6da4ba77..221f51676 100644 --- a/src/viced/viced.c +++ b/src/viced/viced.c @@ -599,10 +599,13 @@ main(argc, argv) 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 */ -- 2.39.5