with -n, permit non-IPv4 address in the output.
option name synchronized with solaris 8.
This commit is contained in:
parent
d760e0b407
commit
863848734f
|
@ -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>
|
.\" Copyright (c) 1994 Mats O Jansson <moj@stacken.kth.se>
|
||||||
.\" All rights reserved.
|
.\" All rights reserved.
|
||||||
|
@ -37,6 +37,7 @@
|
||||||
.Nd a YP filter program
|
.Nd a YP filter program
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm ""
|
.Nm ""
|
||||||
|
.Op Fl n
|
||||||
.Op Ar file
|
.Op Ar file
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
.Nm
|
.Nm
|
||||||
|
@ -44,7 +45,7 @@ parses the
|
||||||
.Xr hosts 5
|
.Xr hosts 5
|
||||||
style input stream (stdin, or
|
style input stream (stdin, or
|
||||||
.Ar file
|
.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
|
.Pp
|
||||||
.Nm
|
.Nm
|
||||||
is used by other
|
is used by other
|
||||||
|
@ -52,6 +53,9 @@ is used by other
|
||||||
programs when creating some of the
|
programs when creating some of the
|
||||||
.Tn YP
|
.Tn YP
|
||||||
maps.
|
maps.
|
||||||
|
.Pp
|
||||||
|
.Fl n
|
||||||
|
allows other address types in the output, including IPv6 addresses.
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr yp 8 ,
|
.Xr yp 8 ,
|
||||||
.Xr ypserv 8
|
.Xr ypserv 8
|
||||||
|
|
|
@ -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>
|
* Copyright (c) 1994 Mats O Jansson <moj@stacken.kth.se>
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#ifndef lint
|
#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
|
#endif
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -47,6 +47,8 @@ __RCSID("$NetBSD: stdhosts.c,v 1.11 1999/07/25 09:01:05 lukem Exp $");
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <util.h>
|
#include <util.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
|
||||||
#include "protos.h"
|
#include "protos.h"
|
||||||
|
|
||||||
|
@ -65,14 +67,30 @@ main(argc, argv)
|
||||||
size_t line_no;
|
size_t line_no;
|
||||||
size_t len;
|
size_t len;
|
||||||
char *line, *k, *v, *addr_string, *fname;
|
char *line, *k, *v, *addr_string, *fname;
|
||||||
|
int ch;
|
||||||
|
int af = 1 << 4; /*IPv4*/
|
||||||
|
struct addrinfo hints, *res;
|
||||||
|
|
||||||
addr_string = NULL; /* XXX gcc -Wuninitialized */
|
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();
|
usage();
|
||||||
|
|
||||||
if (argc == 2) {
|
if (argc == 1) {
|
||||||
fname = argv[1];
|
fname = argv[0];
|
||||||
data_file = fopen(fname, "r");
|
data_file = fopen(fname, "r");
|
||||||
if (data_file == NULL)
|
if (data_file == NULL)
|
||||||
err(1, "%s", fname);
|
err(1, "%s", fname);
|
||||||
|
@ -95,12 +113,22 @@ main(argc, argv)
|
||||||
while (*v && isspace(*v))
|
while (*v && isspace(*v))
|
||||||
*v++ = '\0';
|
*v++ = '\0';
|
||||||
|
|
||||||
if (inet_aton(k, &host_addr) == 0 ||
|
memset(&hints, 0, sizeof(hints));
|
||||||
(addr_string = inet_ntoa(host_addr)) == NULL) {
|
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,
|
warnx("%s line %lu: syntax error", fname,
|
||||||
(unsigned long)line_no);
|
(unsigned long)line_no);
|
||||||
} else
|
|
||||||
printf("%s %s\n", addr_string, v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -110,6 +138,6 @@ void
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
|
|
||||||
fprintf(stderr, "usage: %s [file]\n", __progname);
|
fprintf(stderr, "usage: %s [-n] [file]\n", __progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue