rename library routines so as not conflict with gethostname
[unix-history] / usr / src / lib / libc / net / SCCS / hosttable / gethostent.c
index 06bc216..f3dfc59 100644 (file)
@@ -1,19 +1,24 @@
-/*     gethostent.c    4.1     82/08/25        */
+/*     gethostent.c    4.2     82/10/05        */
 
 #include <stdio.h>
 
 #include <stdio.h>
+#include <sys/types.h>
 #include <sys/socket.h>
 #include <netdb.h>
 #include <ctype.h>
 
 #include <sys/socket.h>
 #include <netdb.h>
 #include <ctype.h>
 
+/*
+ * Internet version.
+ */
 #define        MAXALIASES      35
 #define        MAXALIASES      35
+#define        MAXADDRSIZE     14
 
 static char HOSTDB[] = "/usr/lib/hosts";
 static FILE *hostf = NULL;
 static char line[BUFSIZ+1];
 
 static char HOSTDB[] = "/usr/lib/hosts";
 static FILE *hostf = NULL;
 static char line[BUFSIZ+1];
+static char hostaddr[MAXADDRSIZE];
 static struct hostent host;
 static char *host_aliases[MAXALIASES];
 static int stayopen = 0;
 static struct hostent host;
 static char *host_aliases[MAXALIASES];
 static int stayopen = 0;
-static unsigned long value();
 static char *any();
 
 sethostent(f)
 static char *any();
 
 sethostent(f)
@@ -55,11 +60,14 @@ again:
        if (cp == NULL)
                goto again;
        *cp++ = '\0';
        if (cp == NULL)
                goto again;
        *cp++ = '\0';
-       host.h_addr = value(p);
+       /* THIS STUFF IS INTERNET SPECIFIC */
+       host.h_addr = hostaddr;
+       *((u_long *)host.h_addr) = inet_addr(p);
+       host.h_length = sizeof (u_long);
+       host.h_addrtype = AF_INET;
        while (*cp == ' ' || *cp == '\t')
                cp++;
        host.h_name = cp;
        while (*cp == ' ' || *cp == '\t')
                cp++;
        host.h_name = cp;
-       host.h_addrtype = AF_INET;
        host.h_aliases = host_aliases;
        cp = any(cp, " \t");
        if (cp != NULL)
        host.h_aliases = host_aliases;
        cp = any(cp, " \t");
        if (cp != NULL)
@@ -80,68 +88,6 @@ again:
        return (&host);
 }
 
        return (&host);
 }
 
-static unsigned long
-value(cp)
-       register char *cp;
-{
-       register unsigned long val, base, n;
-       register char c;
-       unsigned long parts[4], *pp = parts;
-
-again:
-       val = 0; base = 10;
-       if (*cp == '0')
-               base = 8, cp++;
-       if (*cp == 'x' || *cp == 'X')
-               base = 16, cp++;
-       while (c = *cp) {
-               if (isdigit(c)) {
-                       val = (val * base) + (c - '0');
-                       cp++;
-                       continue;
-               }
-               if (base == 16 && isxdigit(c)) {
-                       val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A'));
-                       cp++;
-                       continue;
-               }
-               break;
-       }
-       if (*cp == '.') {
-               /*
-                * Internet format:
-                *      a.b.c.d
-                *      a.b.c   (with c treated as 16-bits)
-                *      a.b     (with b treated as 24 bits)
-                */
-               if (pp >= parts + 4)
-                       return (-1);
-               *pp++ = val, cp++;
-               goto again;
-       }
-       if (*cp && !isspace(*cp))
-               return (-1);
-       n = pp - parts;
-       if (n > 0) {
-               if (n > 4)
-                       return (-1);
-               *pp++ = val; n++;
-               val = parts[0];
-               if (n > 1)
-                       val <<= 24;
-               if (n > 2)
-                       val |= (parts[1] & 0xff) << 16;
-               if (n > 3)
-                       val |= (parts[2] & 0xff) << 8;
-               if (n > 1)
-                       val |= parts[n - 1];
-#if vax || pdp11
-               val = htonl(val);
-#endif
-       }
-       return (val);
-}
-
 static char *
 any(cp, match)
        register char *cp;
 static char *
 any(cp, match)
        register char *cp;