Source-Changes-HG archive

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

[src/trunk]: src/sys/lib move intoa() from libsa:net.c to libkern, turn inet_...



details:   https://anonhg.NetBSD.org/src/rev/483f4597d5e6
branches:  trunk
changeset: 472790:483f4597d5e6
user:      drochner <drochner%NetBSD.org@localhost>
date:      Fri May 07 14:49:52 1999 +0000

description:
move intoa() from libsa:net.c to libkern, turn inet_ntoa() into a macro,
nuke ip_convertaddr()

diffstat:

 sys/lib/libkern/Makefile  |   4 +-
 sys/lib/libkern/intoa.c   |  80 +++++++++++++++++++++++++++++++++++++++++++++
 sys/lib/libkern/libkern.h |   4 +-
 sys/lib/libsa/dev_net.c   |   7 ++-
 sys/lib/libsa/net.c       |  83 +----------------------------------------------
 sys/lib/libsa/net.h       |   5 +--
 6 files changed, 91 insertions(+), 92 deletions(-)

diffs (266 lines):

diff -r ef9e840b0547 -r 483f4597d5e6 sys/lib/libkern/Makefile
--- a/sys/lib/libkern/Makefile  Fri May 07 14:28:50 1999 +0000
+++ b/sys/lib/libkern/Makefile  Fri May 07 14:49:52 1999 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.52 1999/05/07 14:28:50 drochner Exp $
+#      $NetBSD: Makefile,v 1.53 1999/05/07 14:49:52 drochner Exp $
 
 LIB=   kern
 MKPIC= no
@@ -23,7 +23,7 @@
 .endif
 
 # Other stuff
-SRCS+= inet_addr.c md5c.c sha1.c pmatch.c
+SRCS+= inet_addr.c intoa.c md5c.c sha1.c pmatch.c
 
 # Files to clean up
 CLEANFILES+= lib${LIB}.o lib${LIB}.po
diff -r ef9e840b0547 -r 483f4597d5e6 sys/lib/libkern/intoa.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/lib/libkern/intoa.c   Fri May 07 14:49:52 1999 +0000
@@ -0,0 +1,80 @@
+/*     $NetBSD: intoa.c,v 1.1 1999/05/07 14:49:52 drochner Exp $       */
+
+/*
+ * Copyright (c) 1992 Regents of the University of California.
+ * All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Lawrence Berkeley Laboratory and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#) Header: net.c,v 1.9 93/08/06 19:32:15 leres Exp  (LBL)
+ */
+
+#include <sys/types.h>
+
+#if defined(_KERNEL) || defined(_STANDALONE)
+#include <lib/libkern/libkern.h>
+#else
+char *intoa __P((u_int32_t)); /* XXX */
+#endif
+
+/* Similar to inet_ntoa() */
+char *
+intoa(addr)
+       u_int32_t addr;
+{
+       char *cp;
+       u_int byte;
+       int n;
+       static char buf[17];    /* strlen(".255.255.255.255") + 1 */
+
+       addr = ntohl(addr);
+       cp = &buf[sizeof buf];
+       *--cp = '\0';
+
+       n = 4;
+       do {
+               byte = addr & 0xff;
+               *--cp = byte % 10 + '0';
+               byte /= 10;
+               if (byte > 0) {
+                       *--cp = byte % 10 + '0';
+                       byte /= 10;
+                       if (byte > 0)
+                               *--cp = byte + '0';
+               }
+               *--cp = '.';
+               addr >>= 8;
+       } while (--n > 0);
+
+       return (cp+1);
+}
diff -r ef9e840b0547 -r 483f4597d5e6 sys/lib/libkern/libkern.h
--- a/sys/lib/libkern/libkern.h Fri May 07 14:28:50 1999 +0000
+++ b/sys/lib/libkern/libkern.h Fri May 07 14:49:52 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: libkern.h,v 1.25 1999/04/12 17:23:23 drochner Exp $    */
+/*     $NetBSD: libkern.h,v 1.26 1999/05/07 14:49:53 drochner Exp $    */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -172,3 +172,5 @@
 char   *strrchr __P((const char *, int));
 int     strncasecmp __P((const char *, const char *, size_t));
 u_int32_t inet_addr __P((const char *));
+char *intoa __P((u_int32_t));
+#define inet_ntoa(a) intoa((a).s_addr)
diff -r ef9e840b0547 -r 483f4597d5e6 sys/lib/libsa/dev_net.c
--- a/sys/lib/libsa/dev_net.c   Fri May 07 14:28:50 1999 +0000
+++ b/sys/lib/libsa/dev_net.c   Fri May 07 14:49:52 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dev_net.c,v 1.15 1999/03/26 15:41:38 dbj Exp $ */
+/*     $NetBSD: dev_net.c,v 1.16 1999/05/07 14:49:53 drochner Exp $    */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -61,6 +61,8 @@
 #include <netinet/in.h>
 #include <netinet/in_systm.h>
 
+#include <lib/libkern/libkern.h>
+
 #include "stand.h"
 #include "net.h"
 #include "netif.h"
@@ -250,8 +252,7 @@
                printf("nfs_open: gateway bootparam missing\n");
        else {
                /* Got it!  Parse the netmask. */
-               /* XXX - Use inet_addr() from libkern! */
-               smask = ip_convertaddr(buf);
+               smask = inet_addr(buf);
        }
        if (smask) {
                netmask = smask;
diff -r ef9e840b0547 -r 483f4597d5e6 sys/lib/libsa/net.c
--- a/sys/lib/libsa/net.c       Fri May 07 14:28:50 1999 +0000
+++ b/sys/lib/libsa/net.c       Fri May 07 14:49:52 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: net.c,v 1.22 1999/04/12 01:05:01 ross Exp $    */
+/*     $NetBSD: net.c,v 1.23 1999/05/07 14:49:55 drochner Exp $        */
 
 /*
  * Copyright (c) 1992 Regents of the University of California.
@@ -62,8 +62,6 @@
 #include "net.h"
 
 
-static char    *number __P((char *, int *));
-
 /* Caller must leave room for ethernet, ip and udp headers in front!! */
 ssize_t
 sendudp(d, pkt, len)
@@ -348,82 +346,3 @@
                tlast = t;
        }
 }
-
-char *
-inet_ntoa(ia)
-       struct in_addr ia;
-{
-       return (intoa(ia.s_addr));
-}
-
-/* Similar to inet_ntoa() */
-char *
-intoa(addr)
-       register n_long addr;
-{
-       register char *cp;
-       register u_int byte;
-       register int n;
-       static char buf[17];    /* strlen(".255.255.255.255") + 1 */
-
-       NTOHL(addr);
-       cp = &buf[sizeof buf];
-       *--cp = '\0';
-
-       n = 4;
-       do {
-               byte = addr & 0xff;
-               *--cp = byte % 10 + '0';
-               byte /= 10;
-               if (byte > 0) {
-                       *--cp = byte % 10 + '0';
-                       byte /= 10;
-                       if (byte > 0)
-                               *--cp = byte + '0';
-               }
-               *--cp = '.';
-               addr >>= 8;
-       } while (--n > 0);
-
-       return (cp+1);
-}
-
-
-static char *
-number(s, n)
-       char *s;
-       int *n;
-{
-       for (*n = 0; isdigit(*s); s++)
-               *n = (*n * 10) + *s - '0';
-       return s;
-}
-
-n_long
-ip_convertaddr(p)
-       char *p;
-{
-#define IP_ANYADDR     0
-       n_long addr = 0, n;
-
-       if (p == (char *)0 || *p == '\0')
-               return IP_ANYADDR;
-       p = number(p, &n);
-       addr |= (n << 24) & 0xff000000;
-       if (*p == '\0' || *p++ != '.')
-               return IP_ANYADDR;
-       p = number(p, &n);
-       addr |= (n << 16) & 0xff0000;
-       if (*p == '\0' || *p++ != '.')
-               return IP_ANYADDR;
-       p = number(p, &n);
-       addr |= (n << 8) & 0xff00;
-       if (*p == '\0' || *p++ != '.')
-               return IP_ANYADDR;
-       p = number(p, &n);
-       addr |= n & 0xff;
-       if (*p != '\0')
-               return IP_ANYADDR;
-
-       return htonl(addr);
-}
diff -r ef9e840b0547 -r 483f4597d5e6 sys/lib/libsa/net.h
--- a/sys/lib/libsa/net.h       Fri May 07 14:28:50 1999 +0000
+++ b/sys/lib/libsa/net.h       Fri May 07 14:49:52 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: net.h,v 1.12 1999/04/12 01:05:01 ross Exp $    */
+/*     $NetBSD: net.h,v 1.13 1999/05/07 14:49:56 drochner Exp $        */
 
 /*
  * Copyright (c) 1993 Adam Glass 
@@ -112,10 +112,7 @@
 /* Utilities: */
 char   *ether_sprintf __P((u_char *));
 int    in_cksum __P((void *, int));
-char   *inet_ntoa __P((struct in_addr));
-char   *intoa __P((n_long));           /* similar to inet_ntoa */
 int    in_cksum __P((void *, int));
-n_long ip_convertaddr __P((char *));
 
 /* Machine-dependent functions: */
 time_t getsecs __P((void));



Home | Main Index | Thread Index | Old Index