Files
Arquivotheca.Solaris-2.5/cmd/ypcmd/stdhosts.c
seta75D 7c4988eac0 Init
2021-10-11 19:38:01 -03:00

76 lines
1.4 KiB
C
Executable File

/*
* Copyright (c) 1985, 1986, 1987, 1988, 1989, 1990 by Sun Microsystems, Inc.
*/
#ident "@(#)stdhosts.c 1.2 92/07/14 SMI" /* SMI4.1 1.7 */
#include <stdio.h>
#include <sys/types.h>
#include <netinet/in.h>
/*
* Filter to convert addresses in /etc/hosts file to standard form
*/
main(argc, argv)
char **argv;
{
char line[256];
char adr[256];
char *any(), *trailer;
extern char *inet_ntoa();
extern u_long inet_addr();
FILE *fp;
if (argc > 1) {
fp = fopen(argv[1], "r");
if (fp == NULL) {
fprintf(stderr, "stdhosts: can't open %s\n", argv[1]);
exit(1);
}
} else
fp = stdin;
while ( fgets(line, sizeof(line), fp)) {
struct in_addr in;
if (line[0] == '#')
continue;
if ((trailer = any(line, " \t")) == NULL)
continue;
sscanf(line, "%s", adr);
in.s_addr = inet_addr(adr);
if (-1 == (int)in.s_addr) {
fprintf(stderr,
"%s: Warning: malformed line ignored:\n%s",
argv[0], line);
} else {
fputs(inet_ntoa(in), stdout);
fputs(trailer, stdout);
}
}
exit(0);
/* NOTREACHED */
}
/*
* scans cp, looking for a match with any character
* in match. Returns pointer to place in cp that matched
* (or NULL if no match)
*/
static char *
any(cp, match)
register char *cp;
char *match;
{
register char *mp, c;
while (c = *cp) {
for (mp = match; *mp; mp++)
if (*mp == c)
return (cp);
cp++;
}
return (NULL);
}