Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/net synchronize better with BIND 8.2.2P5 (actually, ...



details:   https://anonhg.NetBSD.org/src/rev/2eb54f5417a6
branches:  trunk
changeset: 485262:2eb54f5417a6
user:      itojun <itojun%NetBSD.org@localhost>
date:      Sun Apr 23 16:59:12 2000 +0000

description:
synchronize better with BIND 8.2.2P5 (actually, src/dist/bind).
inet_net_pton() becomes more strict on hexadecimals/octals.

diffstat:

 lib/libc/net/inet_net_ntop.c |   9 +++++----
 lib/libc/net/inet_net_pton.c |  38 +++++++++++++++++++++-----------------
 lib/libc/net/inet_network.c  |  24 ++++++++++++++++--------
 lib/libc/net/inet_ntoa.c     |  43 ++++++++++++++++++++-----------------------
 4 files changed, 62 insertions(+), 52 deletions(-)

diffs (258 lines):

diff -r b3bcdaf46a72 -r 2eb54f5417a6 lib/libc/net/inet_net_ntop.c
--- a/lib/libc/net/inet_net_ntop.c      Sun Apr 23 16:47:45 2000 +0000
+++ b/lib/libc/net/inet_net_ntop.c      Sun Apr 23 16:59:12 2000 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: inet_net_ntop.c,v 1.10 2000/01/22 22:19:15 mycroft Exp $       */
+/*     $NetBSD: inet_net_ntop.c,v 1.11 2000/04/23 16:59:12 itojun Exp $        */
 
 /*
- * Copyright (c) 1996 by Internet Software Consortium.
+ * Copyright (c) 1996,1999 by Internet Software Consortium.
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -22,7 +22,7 @@
 #if 0
 static const char rcsid[] = "Id: inet_net_ntop.c,v 8.2 1996/08/08 06:54:44 vixie Exp ";
 #else
-__RCSID("$NetBSD: inet_net_ntop.c,v 1.10 2000/01/22 22:19:15 mycroft Exp $");
+__RCSID("$NetBSD: inet_net_ntop.c,v 1.11 2000/04/23 16:59:12 itojun Exp $");
 #endif
 #endif
 
@@ -91,7 +91,7 @@
  *     pointer to dst, or NULL if an error occurred (check errno).
  * note:
  *     network byte order assumed.  this means 192.5.5.240/28 has
- *     0x11110000 in its fourth octet.
+ *     0b11110000 in its fourth octet.
  * author:
  *     Paul Vixie (ISC), July 1996
  */
@@ -118,6 +118,7 @@
                if (size < sizeof "0")
                        goto emsgsize;
                *dst++ = '0';
+               size--;
                *dst = '\0';
        }
 
diff -r b3bcdaf46a72 -r 2eb54f5417a6 lib/libc/net/inet_net_pton.c
--- a/lib/libc/net/inet_net_pton.c      Sun Apr 23 16:47:45 2000 +0000
+++ b/lib/libc/net/inet_net_pton.c      Sun Apr 23 16:59:12 2000 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: inet_net_pton.c,v 1.11 2000/01/22 22:19:15 mycroft Exp $       */
+/*     $NetBSD: inet_net_pton.c,v 1.12 2000/04/23 16:59:12 itojun Exp $        */
 
 /*
- * Copyright (c) 1996 by Internet Software Consortium.
+ * Copyright (c) 1996,1999 by Internet Software Consortium.
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -22,7 +22,7 @@
 #if 0
 static const char rcsid[] = "Id: inet_net_pton.c,v 8.3 1996/11/11 06:36:52 vixie Exp ";
 #else
-__RCSID("$NetBSD: inet_net_pton.c,v 1.11 2000/01/22 22:19:15 mycroft Exp $");
+__RCSID("$NetBSD: inet_net_pton.c,v 1.12 2000/04/23 16:59:12 itojun Exp $");
 #endif
 #endif
 
@@ -97,7 +97,7 @@
  *     not an IPv4 network specification.
  * note:
  *     network byte order assumed.  this means 192.5.5.240/28 has
- *     0x11110000 in its fourth octet.
+ *     0b11110000 in its fourth octet.
  * author:
  *     Paul Vixie (ISC), June 1996
  */
@@ -123,24 +123,29 @@
                /* size is unsigned */
                if (size == 0)
                        goto emsgsize;
-               *dst = 0, dirty = 0;
+               dirty = 0;
                src++;  /* skip x or X. */
-               while ((ch = *src++) != '\0' &&
-                      isascii(ch) && isxdigit(ch)) {
+               while ((ch = *src++) != '\0' && isascii(ch) && isxdigit(ch)) {
                        if (isupper(ch))
                                ch = tolower(ch);
                        n = strchr(xdigits, ch) - xdigits;
                        assert(n >= 0 && n <= 15);
-                       *dst |= n;
-                       if (!dirty++)
-                               *dst <<= 4;
-                       else if (size-- > 0)
-                               *++dst = 0, dirty = 0;
+                       if (dirty == 0)
+                               tmp = n;
                        else
-                               goto emsgsize;
+                               tmp = (tmp << 4) | n;
+                       if (++dirty == 2) {
+                               if (size-- <= 0)
+                                       goto emsgsize;
+                               *dst++ = (u_char) tmp;
+                               dirty = 0;
+                       }
                }
-               if (dirty)
-                       size--;
+               if (dirty) {  /* Odd trailing nybble? */
+                       if (size-- <= 0)
+                               goto emsgsize;
+                       *dst++ = (u_char) (tmp << 4);
+               }
        } else if (isascii(ch) && isdigit(ch)) {
                /* Decimal: eat dotted digit string. */
                for (;;) {
@@ -178,8 +183,7 @@
                        assert(n >= 0 && n <= 9);
                        bits *= 10;
                        bits += n;
-               } while ((ch = *src++) != '\0' &&
-                        isascii(ch) && isdigit(ch));
+               } while ((ch = *src++) != '\0' && isascii(ch) && isdigit(ch));
                if (ch != '\0')
                        goto enoent;
                if (bits > 32)
diff -r b3bcdaf46a72 -r 2eb54f5417a6 lib/libc/net/inet_network.c
--- a/lib/libc/net/inet_network.c       Sun Apr 23 16:47:45 2000 +0000
+++ b/lib/libc/net/inet_network.c       Sun Apr 23 16:59:12 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: inet_network.c,v 1.10 2000/01/22 22:19:15 mycroft Exp $        */
+/*     $NetBSD: inet_network.c,v 1.11 2000/04/23 16:59:12 itojun Exp $ */
 
 /*
  * Copyright (c) 1983, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)inet_network.c     8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: inet_network.c,v 1.10 2000/01/22 22:19:15 mycroft Exp $");
+__RCSID("$NetBSD: inet_network.c,v 1.11 2000/04/23 16:59:12 itojun Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -63,34 +63,40 @@
 inet_network(cp)
        register const char *cp;
 {
-       register u_long val, base, n;
+       register u_long val, base, n, i;
        register char c;
        u_long parts[4], *pp = parts;
-       register int i;
+       int digit;
 
        _DIAGASSERT(cp != NULL);
 
 again:
-       val = 0; base = 10;
+       val = 0; base = 10; digit = 0;
        if (*cp == '0')
-               base = 8, cp++;
+               digit = 1, base = 8, cp++;
        if (*cp == 'x' || *cp == 'X')
                base = 16, cp++;
-       while ((c = *cp) != '\0') {
+       while ((c = *cp) != 0) {
                if (isdigit(c)) {
+                       if (base == 8 && (c == '8' || c == '9'))
+                               return (INADDR_NONE);
                        val = (val * base) + (c - '0');
                        cp++;
+                       digit = 1;
                        continue;
                }
                if (base == 16 && isxdigit(c)) {
                        val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A'));
                        cp++;
+                       digit = 1;
                        continue;
                }
                break;
        }
+       if (!digit)
+               return (INADDR_NONE);
        if (*cp == '.') {
-               if (pp >= parts + 3)
+               if (pp >= parts + 4 || val > 0xff)
                        return (INADDR_NONE);
                *pp++ = val, cp++;
                goto again;
@@ -99,6 +105,8 @@
                return (INADDR_NONE);
        *pp++ = val;
        n = pp - parts;
+       if (n > 4)
+               return (INADDR_NONE);
        for (val = 0, i = 0; i < n; i++) {
                val <<= 8;
                val |= parts[i] & 0xff;
diff -r b3bcdaf46a72 -r 2eb54f5417a6 lib/libc/net/inet_ntoa.c
--- a/lib/libc/net/inet_ntoa.c  Sun Apr 23 16:47:45 2000 +0000
+++ b/lib/libc/net/inet_ntoa.c  Sun Apr 23 16:59:12 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: inet_ntoa.c,v 1.8 2000/01/22 22:19:16 mycroft Exp $    */
+/*     $NetBSD: inet_ntoa.c,v 1.9 2000/04/23 16:59:12 itojun Exp $     */
 
 /*
  * Copyright (c) 1983, 1993
@@ -38,34 +38,31 @@
 #if 0
 static char sccsid[] = "@(#)inet_ntoa.c        8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: inet_ntoa.c,v 1.8 2000/01/22 22:19:16 mycroft Exp $");
+__RCSID("$NetBSD: inet_ntoa.c,v 1.9 2000/04/23 16:59:12 itojun Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
+#include "namespace.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <stdio.h>
+#include <string.h>
+
+#ifdef __weak_alias
+__weak_alias(inet_ntoa,_inet_ntoa)
+#endif
+
 /*
  * Convert network-format internet address
  * to base 256 d.d.d.d representation.
  */
-#include "namespace.h"
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <stdio.h>
-
-#ifdef __weak_alias
-__weak_alias(inet_ntoa,_inet_ntoa)
-#endif
+/*const*/ char *
+inet_ntoa(struct in_addr in) {
+       static char ret[18];
 
-char *
-inet_ntoa(in)
-       struct in_addr in;
-{
-       static char b[18];
-       register char *p;
-
-       p = (char *)(void *)&in;
-#define        UC(b)   (((int)b)&0xff)
-       (void)snprintf(b, sizeof(b),
-           "%d.%d.%d.%d", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3]));
-       return (b);
+       strcpy(ret, "[inet_ntoa error]");
+       (void) inet_ntop(AF_INET, &in, ret, sizeof ret);
+       return (ret);
 }



Home | Main Index | Thread Index | Old Index