diff options
| author | drochner <drochner@NetBSD.org> | 1999-05-07 14:49:52 +0000 |
|---|---|---|
| committer | drochner <drochner@NetBSD.org> | 1999-05-07 14:49:52 +0000 |
| commit | e6b49c7863164ce2ea586b09eee8cb1962e5f8a8 (patch) | |
| tree | afb908ead7f8d535edcb9cf94e7f3dcaebb569ad /sys/lib | |
| parent | 192b3c733ccfad70a054aace090b31a261e59ced (diff) | |
move intoa() from libsa:net.c to libkern, turn inet_ntoa() into a macro,
nuke ip_convertaddr()
Diffstat (limited to 'sys/lib')
| -rw-r--r-- | sys/lib/libkern/Makefile | 4 | ||||
| -rw-r--r-- | sys/lib/libkern/intoa.c | 80 | ||||
| -rw-r--r-- | sys/lib/libkern/libkern.h | 4 | ||||
| -rw-r--r-- | sys/lib/libsa/dev_net.c | 7 | ||||
| -rw-r--r-- | sys/lib/libsa/net.c | 83 | ||||
| -rw-r--r-- | sys/lib/libsa/net.h | 5 |
6 files changed, 91 insertions, 92 deletions
diff --git a/sys/lib/libkern/Makefile b/sys/lib/libkern/Makefile index dd7336d6ed1..0665d231bd8 100644 --- a/sys/lib/libkern/Makefile +++ b/sys/lib/libkern/Makefile @@ -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 @@ SRCS+= adddi3.c anddi3.c ashldi3.c ashrdi3.c cmpdi2.c divdi3.c iordi3.c \ .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 --git a/sys/lib/libkern/intoa.c b/sys/lib/libkern/intoa.c new file mode 100644 index 00000000000..1c6ba88f522 --- /dev/null +++ b/sys/lib/libkern/intoa.c @@ -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 --git a/sys/lib/libkern/libkern.h b/sys/lib/libkern/libkern.h index 045be56cf30..f5dae4835e3 100644 --- a/sys/lib/libkern/libkern.h +++ b/sys/lib/libkern/libkern.h @@ -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 *strncpy __P((char *, const char *, size_t)); 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 --git a/sys/lib/libsa/dev_net.c b/sys/lib/libsa/dev_net.c index b7aa35df23d..93947b600a9 100644 --- a/sys/lib/libsa/dev_net.c +++ b/sys/lib/libsa/dev_net.c @@ -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 @@ net_getparams(sock) 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 --git a/sys/lib/libsa/net.c b/sys/lib/libsa/net.c index c8789b2839e..19ca82ece7e 100644 --- a/sys/lib/libsa/net.c +++ b/sys/lib/libsa/net.c @@ -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 @@ sendrecv(d, sproc, sbuf, ssize, rproc, rbuf, rsize) 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 --git a/sys/lib/libsa/net.h b/sys/lib/libsa/net.h index e1913633cb2..53155b6c013 100644 --- a/sys/lib/libsa/net.h +++ b/sys/lib/libsa/net.h @@ -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 @@ ssize_t sendrecv __P((struct iodesc *, /* 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)); |
