1999-07-25 13:01:04 +04:00
|
|
|
/* $NetBSD: stdhosts.c,v 1.11 1999/07/25 09:01:05 lukem Exp $ */
|
1996-08-09 14:14:49 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1994 Mats O Jansson <moj@stacken.kth.se>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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 Mats O Jansson
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
*/
|
|
|
|
|
1997-10-13 07:15:30 +04:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#ifndef lint
|
1999-07-25 13:01:04 +04:00
|
|
|
__RCSID("$NetBSD: stdhosts.c,v 1.11 1999/07/25 09:01:05 lukem Exp $");
|
1997-10-13 07:15:30 +04:00
|
|
|
#endif
|
|
|
|
|
1996-08-09 14:14:49 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
1998-06-08 10:53:47 +04:00
|
|
|
#include <stdlib.h>
|
1996-08-09 14:14:49 +04:00
|
|
|
#include <string.h>
|
1998-06-08 10:53:47 +04:00
|
|
|
#include <util.h>
|
1996-08-09 14:14:49 +04:00
|
|
|
|
|
|
|
#include "protos.h"
|
|
|
|
|
1997-07-19 01:57:00 +04:00
|
|
|
int main __P((int, char *[]));
|
1996-08-09 14:14:49 +04:00
|
|
|
void usage __P((void));
|
|
|
|
|
|
|
|
extern char *__progname; /* from crt0.o */
|
|
|
|
|
|
|
|
int
|
|
|
|
main(argc, argv)
|
|
|
|
int argc;
|
1997-07-19 01:57:00 +04:00
|
|
|
char *argv[];
|
1996-08-09 14:14:49 +04:00
|
|
|
{
|
|
|
|
struct in_addr host_addr;
|
1997-11-01 17:24:50 +03:00
|
|
|
FILE *data_file;
|
1998-06-11 18:50:46 +04:00
|
|
|
size_t line_no;
|
1997-11-13 21:35:57 +03:00
|
|
|
size_t len;
|
1999-07-25 13:01:04 +04:00
|
|
|
char *line, *k, *v, *addr_string, *fname;
|
1996-08-09 14:14:49 +04:00
|
|
|
|
1997-07-19 01:57:00 +04:00
|
|
|
addr_string = NULL; /* XXX gcc -Wuninitialized */
|
|
|
|
|
1996-08-09 14:14:49 +04:00
|
|
|
if (argc > 2)
|
|
|
|
usage();
|
|
|
|
|
|
|
|
if (argc == 2) {
|
|
|
|
fname = argv[1];
|
|
|
|
data_file = fopen(fname, "r");
|
|
|
|
if (data_file == NULL)
|
|
|
|
err(1, "%s", fname);
|
|
|
|
} else {
|
|
|
|
fname = "<stdin>";
|
|
|
|
data_file = stdin;
|
|
|
|
}
|
|
|
|
|
1997-11-01 17:24:50 +03:00
|
|
|
line_no = 0;
|
1998-06-08 10:53:47 +04:00
|
|
|
for (;
|
1999-07-25 13:01:04 +04:00
|
|
|
(line = fparseln(data_file, &len, &line_no, NULL,
|
|
|
|
FPARSELN_UNESCALL));
|
|
|
|
free(line)) {
|
1998-06-08 10:53:47 +04:00
|
|
|
if (len == 0)
|
1996-08-09 14:14:49 +04:00
|
|
|
continue;
|
|
|
|
|
1999-07-25 13:01:04 +04:00
|
|
|
v = line;
|
1997-11-01 17:24:50 +03:00
|
|
|
for (k = v; *v && !isspace(*v); v++)
|
|
|
|
;
|
|
|
|
while (*v && isspace(*v))
|
1996-11-24 23:16:43 +03:00
|
|
|
*v++ = '\0';
|
1996-08-09 14:14:49 +04:00
|
|
|
|
|
|
|
if (inet_aton(k, &host_addr) == 0 ||
|
1999-01-17 10:01:26 +03:00
|
|
|
(addr_string = inet_ntoa(host_addr)) == NULL) {
|
1998-06-11 18:50:46 +04:00
|
|
|
warnx("%s line %lu: syntax error", fname,
|
|
|
|
(unsigned long)line_no);
|
1999-01-17 10:01:26 +03:00
|
|
|
} else
|
|
|
|
printf("%s %s\n", addr_string, v);
|
1996-08-09 14:14:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
|
|
|
|
fprintf(stderr, "usage: %s [file]\n", __progname);
|
|
|
|
exit(1);
|
|
|
|
}
|