Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/ifconfig implement netmask slash notation for IP and IP...
details: https://anonhg.NetBSD.org/src/rev/3769cc9c39f6
branches: trunk
changeset: 480425:3769cc9c39f6
user: joda <joda%NetBSD.org@localhost>
date: Wed Jan 12 10:29:35 2000 +0000
description:
implement netmask slash notation for IP and IPv6 addresses
diffstat:
sbin/ifconfig/ifconfig.8 | 5 ++++-
sbin/ifconfig/ifconfig.c | 34 ++++++++++++++++++++++++++++++++--
2 files changed, 36 insertions(+), 3 deletions(-)
diffs (81 lines):
diff -r 8cf12c0b915d -r 3769cc9c39f6 sbin/ifconfig/ifconfig.8
--- a/sbin/ifconfig/ifconfig.8 Wed Jan 12 09:23:26 2000 +0000
+++ b/sbin/ifconfig/ifconfig.8 Wed Jan 12 10:29:35 2000 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: ifconfig.8,v 1.28 1999/12/09 01:28:25 itojun Exp $
+.\" $NetBSD: ifconfig.8,v 1.29 2000/01/12 10:30:05 joda Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -260,6 +260,9 @@
The mask should contain at least the standard network portion,
and the subnet field should be contiguous with the network
portion.
+.Pp
+For INET and INET6 addresses, the netmask can also be given with
+slash-notation after the address (e.g 192.168.17.3/24).
.\" see
.\" Xr eon 5 .
.It Cm nsellength Ar n
diff -r 8cf12c0b915d -r 3769cc9c39f6 sbin/ifconfig/ifconfig.c
--- a/sbin/ifconfig/ifconfig.c Wed Jan 12 09:23:26 2000 +0000
+++ b/sbin/ifconfig/ifconfig.c Wed Jan 12 10:29:35 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ifconfig.c,v 1.59 1999/12/13 15:24:45 itojun Exp $ */
+/* $NetBSD: ifconfig.c,v 1.60 2000/01/12 10:29:35 joda Exp $ */
/*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -80,7 +80,7 @@
#if 0
static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
#else
-__RCSID("$NetBSD: ifconfig.c,v 1.59 1999/12/13 15:24:45 itojun Exp $");
+__RCSID("$NetBSD: ifconfig.c,v 1.60 2000/01/12 10:29:35 joda Exp $");
#endif
#endif /* not lint */
@@ -1809,6 +1809,27 @@
if (which != MASK)
sin->sin_family = AF_INET;
+ if (which == ADDR) {
+ char *p = NULL;
+
+ if((p = strrchr(s, '/')) != NULL) {
+ /* address is `name/masklen' */
+ int masklen;
+ int ret;
+ struct sockaddr_in *min = sintab[MASK];
+ *p = '\0';
+ ret = sscanf(p+1, "%u", &masklen);
+ if(ret != 1 || (masklen < 0 || masklen > 32)) {
+ *p = '/';
+ errx(1, "%s: bad value", s);
+ }
+ min->sin_len = sizeof(*min);
+ min->sin_addr.s_addr =
+ htonl(~((1LL << (32 - masklen)) - 1) &
+ 0xffffffff);
+ }
+ }
+
if (inet_aton(s, &sin->sin_addr) == 0) {
if ((hp = gethostbyname(s)) != NULL)
(void) memcpy(&sin->sin_addr, hp->h_addr, hp->h_length);
@@ -1896,6 +1917,15 @@
if (which != MASK)
sin->sin6_family = AF_INET6;
+ if (which == ADDR) {
+ char *p = NULL;
+ if((p = strrchr(s, '/')) != NULL) {
+ *p = '\0';
+ in6_getprefix(p + 1, MASK);
+ explicit_prefix = 1;
+ }
+ }
+
if (inet_pton(AF_INET6, s, &sin->sin6_addr) != 1)
errx(1, "%s: bad value", s);
#endif
Home |
Main Index |
Thread Index |
Old Index