util-warnings-cleanup-20010705
[openafs.git] / src / util / hostparse.c
index f0ba157..2ba60eb 100644 (file)
 #else /* UKERNEL */
 #include <stdio.h>
 #include <sys/types.h>
+#include <stdlib.h>
 #ifdef AFS_NT40_ENV
 #include <winsock2.h>
-#include <stdlib.h>
 #include <direct.h>
 #else
 #include <netinet/in.h>
 #include <sys/socket.h>
 #include <arpa/inet.h>
 #include <netdb.h>
+#include <ctype.h>
+#endif
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#else
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
 #endif
 #include <errno.h>
 #include "afsutil.h"
@@ -47,7 +55,7 @@ register char *ahost; {
     tc = *ahost;    /* look at the first char */
     if (tc >= '0' && tc <= '9') {
        numeric = 1;
-       while (tc = *ptr++) {
+       while ((tc = *ptr++)) {
            if (tc == '.') {
                if (dots >= 3) {
                    numeric = 0;
@@ -66,7 +74,7 @@ register char *ahost; {
        tval = 0;
        dots = 0;
        bzero(addr, sizeof(addr));
-       while (tc = *ahost++) {
+       while ((tc = *ahost++)) {
            if (tc == '.') {
                if (dots >= 3) return (struct hostent *) 0; /* too many dots */
                addr[dots++] = tval;
@@ -118,8 +126,8 @@ char *hostutil_GetNameByINet(addr)
   } else {
      addr = ntohl(addr);
      sprintf(tbuffer, "%d.%d.%d.%d", 
-            ((addr>>24) & 0xff), ((addr>>16) & 0xff),
-            ((addr>>8)  & 0xff), ( addr      & 0xff));
+            (int)((addr>>24) & 0xff), (int)((addr>>16) & 0xff),
+            (int)((addr>>8)  & 0xff), (int)( addr      & 0xff));
   }
   
     return tbuffer;
@@ -231,6 +239,20 @@ 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);
+    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.