Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/ypserv/stdhosts with -n, permit non-IPv4 address in...



details:   https://anonhg.NetBSD.org/src/rev/aeb33cb46eb6
branches:  trunk
changeset: 495496:aeb33cb46eb6
user:      itojun <itojun%NetBSD.org@localhost>
date:      Sun Jul 30 02:25:08 2000 +0000

description:
with -n, permit non-IPv4 address in the output.
option name synchronized with solaris 8.

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 e0651f3677ba -r aeb33cb46eb6 usr.sbin/ypserv/stdhosts/stdhosts.8
--- a/usr.sbin/ypserv/stdhosts/stdhosts.8       Sat Jul 29 23:18:46 2000 +0000
+++ b/usr.sbin/ypserv/stdhosts/stdhosts.8       Sun Jul 30 02:25:08 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.6 2000/07/30 02:25:08 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 e0651f3677ba -r aeb33cb46eb6 usr.sbin/ypserv/stdhosts/stdhosts.c
--- a/usr.sbin/ypserv/stdhosts/stdhosts.c       Sat Jul 29 23:18:46 2000 +0000
+++ b/usr.sbin/ypserv/stdhosts/stdhosts.c       Sun Jul 30 02:25:08 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.12 2000/07/30 02:25:08 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.12 2000/07/30 02:25:08 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