BSD 4_3_Tahoe release
[unix-history] / usr / src / lib / libc / inet / inet_addr.c
index 3a1070c..6d97c1b 100644 (file)
@@ -1,12 +1,23 @@
 /*
  * Copyright (c) 1983 Regents of the University of California.
 /*
  * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)inet_addr.c        5.2 (Berkeley) 3/9/86";
-#endif LIBC_SCCS and not lint
+static char sccsid[] = "@(#)inet_addr.c        5.6 (Berkeley) 6/27/88";
+#endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
 #include <ctype.h>
 
 #include <sys/types.h>
 #include <ctype.h>
@@ -34,10 +45,12 @@ again:
         * 0x=hex, 0=octal, other=decimal.
         */
        val = 0; base = 10;
         * 0x=hex, 0=octal, other=decimal.
         */
        val = 0; base = 10;
-       if (*cp == '0')
-               base = 8, cp++;
-       if (*cp == 'x' || *cp == 'X')
-               base = 16, cp++;
+       if (*cp == '0') {
+               if (*++cp == 'x' || *cp == 'X')
+                       base = 16, cp++;
+               else
+                       base = 8;
+       }
        while (c = *cp) {
                if (isdigit(c)) {
                        val = (val * base) + (c - '0');
        while (c = *cp) {
                if (isdigit(c)) {
                        val = (val * base) + (c - '0');
@@ -59,7 +72,7 @@ again:
                 *      a.b     (with b treated as 24 bits)
                 */
                if (pp >= parts + 4)
                 *      a.b     (with b treated as 24 bits)
                 */
                if (pp >= parts + 4)
-                       return (-1);
+                       return (INADDR_NONE);
                *pp++ = val, cp++;
                goto again;
        }
                *pp++ = val, cp++;
                goto again;
        }
@@ -67,7 +80,7 @@ again:
         * Check for trailing characters.
         */
        if (*cp && !isspace(*cp))
         * Check for trailing characters.
         */
        if (*cp && !isspace(*cp))
-               return (-1);
+               return (INADDR_NONE);
        *pp++ = val;
        /*
         * Concoct the address according to
        *pp++ = val;
        /*
         * Concoct the address according to
@@ -95,7 +108,7 @@ again:
                break;
 
        default:
                break;
 
        default:
-               return (-1);
+               return (INADDR_NONE);
        }
        val = htonl(val);
        return (val);
        }
        val = htonl(val);
        return (val);