htable.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1989 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* htable - convert NIC host table into a UNIX format.
* DoD Internet host table format is specified in RFC 952, October 1985
*/
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <netdb.h>
int connected_nets[MAXNETS];
int nconnected;
int local_nets[MAXNETS];
int nlocal;
char *myname;
int argc;
char *argv[];
{
int errs;
infile = "(stdin)";
argc--;
argv++;
while (argc--) {
if (*argv[0] == '-') {
switch (argv[0][1]) {
case 'c':
argv++;
argc--;
break;
case 'l':
argv++;
argc--;
break;
default:
usage();
/*NOTREACHED*/
}
} else {
exit(1);
}
}
argv++;
}
perror("hosts");
exit(1);
}
perror("gateways");
exit(1);
}
copygateways("localgateways");
perror("networks");
exit(1);
}
dogateways();
/* NOTREACHED */
}
usage()
{
"usage: %s [ -c connected-nets ] [-l local-nets ] [ input-file ]\n",
myname);
exit(1);
}
/*
* Turn a comma-separated list of network names or numbers in dot notation
* (e.g. "arpanet, 128.32") into an array of net numbers.
*/
char *arg;
int *nets;
{
register char *p, c;
register int nfound = 0;
do {
p = arg;
while (*p && *p != ',' && !isspace(*p))
p++;
c = *p;
*p = 0;
arg++;
if (*arg == 0)
continue;
myname);
return (nfound);
}
nfound++;
else {
exit(1);
}
arg = p + 1;
} while (c);
return (nfound);
}
struct name *
char *str;
{
char *p;
return (nm);
}
char *
char *str;
{
while (*cp) {
cp++;
}
return (str);
}
int keyword;
{
struct addr *connect_addr;
char *cp;
switch (keyword) {
case KW_NET:
break;
}
char *cp;
cp = "\t%s";
cp = " %s";
}
}
break;
case KW_GATEWAY:
/* locate locally connected address, if one */
break;
/*
* Not connected to known networks. Save for later.
*/
register int net;
}
goto dontfree;
}
/*
* Connected to a known network.
* Mark this as the gateway to all other networks
* that are on the addrlist (unless we already have
* gateways to them).
*/
connect_addr = al;
register int net;
/* suppress duplicates -- not optimal */
continue;
}
/*
* Put the gateway in the hosts file.
*/
cp = "%s";
cp = " %s";
}
goto dontfree;
case KW_HOST:
char *cp;
cp = "%s";
cp = " %s";
}
}
}
break;
default:
}
}
int net;
char *name;
int metric;
{
if (np)
else
}
FILE *f;
char *filename;
{
register cc;
extern int errno;
exit(1);
}
return;
}
}
char *filename;
{
char type[80];
char dname[80];
char gname[80];
char junk[80];
char buf[500];
extern int errno;
exit(1);
}
return;
}
/* format: {net | host} XX gateway XX metric DD [passive]\n */
for (;;) {
junk[0] = 0;
break;
if (buf[0] == '#' ||
continue;
continue;
continue;
continue;
}
}
char *name;
int *addr;
{
if (np == 0) {
return (*addr != -1);
} else {
return (0);
return (1);
}
}
char *name;
{
if (hp) {
return (1);
}
return (*addr != -1);
}
int ccount;
{
int count;
char *fgets();
return;
buf[0] = '#';
}
return;
}
#define UC(b) (((int)(b))&0xff)
/*
* Print network number in internet-standard dot notation;
* v is in host byte order.
*/
putnet(f, v)
FILE *f;
register int v;
{
if (v < 128)
fprintf(f, "%d", v);
else if (v < 65536)
else
}
putaddr(f, v)
FILE *f;
struct in_addr v;
{
}
{
}
}
{
}
struct gateway *lastgateway = 0;
struct gateway *
register int net;
{
return (gp);
}
struct gateway *
{
if (gp == 0) {
exit(1);
}
if (lastgateway)
else
lastgateway = gp;
if (metric == 1)
return (gp);
}
int net;
{
register i;
for (i = 0; i < nconnected; i++)
if (connected_nets[i] == net)
return(1);
return(0);
}
int net;
{
register i;
for (i = 0; i < nlocal; i++)
if (local_nets[i] == net)
return(1);
return(0);
}
#define MAXHOPS 10
/*
* Go through list of gateways, finding connections for gateways
* that are not yet connected.
*/
{
char *cp;
/*
* Found a new connection.
* For each other network that this gateway is on,
* add a new gateway to that network.
*/
changed = 1;
continue;
continue;
}
/*
* Put the gateway in the hosts file,
* using the address for the connected net.
*/
cp = "%s";
cp = " %s";
}
}
}
}