Source-Changes-HG archive

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

[src/netbsd-1-5]: src/usr.sbin/ypserv/stdhosts pullup (approved by releng-1-5)



details:   https://anonhg.NetBSD.org/src/rev/ed597d6929ae
branches:  netbsd-1-5
changeset: 489475:ed597d6929ae
user:      itojun <itojun%NetBSD.org@localhost>
date:      Tue Sep 19 17:48:54 2000 +0000

description:
pullup (approved by releng-1-5)
>with -n, permit non-IPv4 address in the output.
>option name synchronized with solaris 8.

this makes stdhosts(8) to ignore non-IPv4 address by default.  stdhosts -n
will allow other address types.
this is to be friendly with /etc/hosts with IPv6 mapping, and to make
hosts.{byname,byaddr} IPv4 only (solaris8 nis practice).

full IPv6 NIS database support (like ipnodes.{byname,byaddr} support
in Makefile.yp) is available in netbsd-current, however, it needs to pass
interop test before going into 1.5.

stdhosts.8 1.5 -> 1.6
stdhosts.c 1.11 -> 1.12

diffstat:

 usr.sbin/ypserv/stdhosts/stdhosts.8 |   8 ++++-
 usr.sbin/ypserv/stdhosts/stdhosts.c |  48 +++++++++++++++++++++++++++++-------
 2 files changed, 44 insertions(+), 12 deletions(-)

diffs (132 lines):

diff -r eaa97dc6eb06 -r ed597d6929ae usr.sbin/ypserv/stdhosts/stdhosts.8
--- a/usr.sbin/ypserv/stdhosts/stdhosts.8       Tue Sep 19 17:48:16 2000 +0000
+++ b/usr.sbin/ypserv/stdhosts/stdhosts.8       Tue Sep 19 17:48:54 2000 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: stdhosts.8,v 1.5 1999/03/07 11:58:26 mycroft Exp $
+.\"    $NetBSD: stdhosts.8,v 1.5.10.1 2000/09/19 17:48:54 itojun Exp $
 .\"
 .\" Copyright (c) 1994 Mats O Jansson <moj%stacken.kth.se@localhost>
 .\" All rights reserved.
@@ -37,6 +37,7 @@
 .Nd a YP filter program
 .Sh SYNOPSIS
 .Nm ""
+.Op Fl n
 .Op Ar file
 .Sh DESCRIPTION
 .Nm
@@ -44,7 +45,7 @@
 .Xr hosts 5
 style input stream (stdin, or
 .Ar file
-if given), and outputs lines containing only the IP address and host name.
+if given), and outputs lines containing only the IPv4 address and host name.
 .Pp
 .Nm
 is used by other
@@ -52,6 +53,9 @@
 programs when creating some of the
 .Tn YP
 maps.
+.Pp
+.Fl n
+allows other address types in the output, including IPv6 addresses.
 .Sh SEE ALSO
 .Xr yp 8 ,
 .Xr ypserv 8 
diff -r eaa97dc6eb06 -r ed597d6929ae usr.sbin/ypserv/stdhosts/stdhosts.c
--- a/usr.sbin/ypserv/stdhosts/stdhosts.c       Tue Sep 19 17:48:16 2000 +0000
+++ b/usr.sbin/ypserv/stdhosts/stdhosts.c       Tue Sep 19 17:48:54 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: stdhosts.c,v 1.11 1999/07/25 09:01:05 lukem Exp $       */
+/*     $NetBSD: stdhosts.c,v 1.11.8.1 2000/09/19 17:48:54 itojun Exp $  */
 
 /*
  * Copyright (c) 1994 Mats O Jansson <moj%stacken.kth.se@localhost>
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: stdhosts.c,v 1.11 1999/07/25 09:01:05 lukem Exp $");
+__RCSID("$NetBSD: stdhosts.c,v 1.11.8.1 2000/09/19 17:48:54 itojun Exp $");
 #endif
 
 #include <sys/types.h>
@@ -47,6 +47,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <util.h>
+#include <unistd.h>
+#include <netdb.h>
 
 #include "protos.h"
 
@@ -65,14 +67,30 @@
        size_t   line_no;
        size_t   len;
        char    *line, *k, *v, *addr_string, *fname;
+       int      ch;
+       int      af = 1 << 4;   /*IPv4*/
+       struct addrinfo hints, *res;
 
        addr_string = NULL;             /* XXX gcc -Wuninitialized */
 
-       if (argc > 2)
+       while ((ch = getopt(argc, argv, "n")) != EOF) {
+               switch (ch) {
+               case 'n':
+                       af |= 1 << 6;   /*IPv6*/
+                       break;
+               default:
+                       usage();
+                       /* NOTREACHED */
+               }
+       }
+       argc -= optind;
+       argv += optind;
+
+       if (argc > 1)
                usage();
 
-       if (argc == 2) {
-               fname = argv[1];
+       if (argc == 1) {
+               fname = argv[0];
                data_file = fopen(fname, "r");
                if (data_file == NULL)
                        err(1, "%s", fname); 
@@ -95,12 +113,22 @@
                while (*v && isspace(*v))
                        *v++ = '\0';
 
-               if (inet_aton(k, &host_addr) == 0 ||
-                   (addr_string = inet_ntoa(host_addr)) == NULL) {
+               memset(&hints, 0, sizeof(hints));
+               hints.ai_socktype = SOCK_DGRAM;         /*dummy*/
+               hints.ai_flags = AI_NUMERICHOST;
+
+               if ((af & (1 << 4)) != 0 && inet_aton(k, &host_addr) == 1 &&
+                   (addr_string = inet_ntoa(host_addr)) != NULL) {
+                       /* IPv4 */
+                       printf("%s %s\n", addr_string, v);
+               } else if ((af & (1 << 6)) != 0 &&
+                          getaddrinfo(k, "0", &hints, &res) == 0) {
+                       /* IPv6, with scope extension permitted */
+                       freeaddrinfo(res);
+                       printf("%s %s\n", k, v);
+               } else
                        warnx("%s line %lu: syntax error", fname,
                            (unsigned long)line_no);
-               } else
-                       printf("%s %s\n", addr_string, v);
        }
 
        exit(0);
@@ -110,6 +138,6 @@
 usage()
 {
 
-       fprintf(stderr, "usage: %s [file]\n", __progname);
+       fprintf(stderr, "usage: %s [-n] [file]\n", __progname);
        exit(1);
 }



Home | Main Index | Thread Index | Old Index