unifdef CCITT, ISO & CRUFT.

This commit is contained in:
Poul-Henning Kamp 1997-04-02 16:52:45 +00:00
parent bb789b9ea2
commit 8fd0ef3952
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=24554
3 changed files with 2 additions and 303 deletions

View File

@ -2,7 +2,7 @@
PROG= route
MAN8= route.8
SRCS= route.c keywords.h # ccitt_addr.h
SRCS= route.c keywords.h
CFLAGS+=-I. -Wall -DNS
CLEANFILES+=keywords.h
BINOWN= root

View File

@ -1,175 +0,0 @@
/*
* Copyright (c) 1990, 1993
* The Regents of the University of California. 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 the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
*
* @(#)ccitt_addr.c 8.1 (Berkeley) 6/5/93
*/
/*
* parse CCITT addresses
*
* Addresses must have the format: [hpr],x121address[,userdata][,protocol]
* items enclosed with square brackets are optional
* 'h' or 'p' means hi priority (packet size = 128; specific to Datapac
* and necessary only for X.25(76) and non-negotiating X.25(80) DTE's)
* 'r' means reverse charge (remote DTE pays for call).
* The x121address consists of an optional netid and dot, followed
* by a dte address.
*
* Frank Pronk
* The University of British Columbia
* Laboratory for Computational Vision
* Copyright (c) 1984
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netccitt/x25.h>
static char *copychar ();
ccitt_addr (addr, xp)
char *addr;
register struct sockaddr_x25 *xp;
{
register char *p, *ap, *limit;
int havenet = 0;
bzero ((char *)xp, sizeof (*xp));
xp->x25_family = AF_CCITT;
xp->x25_len = sizeof(*xp);
p = addr;
/*
* process optional priority and reverse charging flags
*/
if (*p == 'p' || *p == 'r' || *p == 'h') {
while (*p == 'p' || *p == 'r' || *p == 'h') {
if (*p == 'p' || *p == 'h')
xp->x25_opts.op_psize = X25_PS128;
else if (*p == 'r')
xp->x25_opts.op_flags |= X25_REVERSE_CHARGE;
p++;
}
if (*p != ',')
return (0);
p++;
}
if (*p == '\0')
return (0);
/*
* [network id:]X.121 address
*/
ap = xp->x25_addr;
limit = ap + sizeof (xp->x25_addr) - 1;
while (*p) {
if (*p == ',')
break;
if (*p == '.' || *p == ':') {
if (havenet)
return (0);
havenet++;
xp->x25_net = atoi (xp->x25_addr);
p++;
ap = xp->x25_addr;
*ap = '\0';
}
if (*p < '0' || *p > '9')
return (0);
if (ap >= limit)
return (0);
*ap++ = *p++;
}
if (*p == '\0')
return (1);
/*
* optional user data, bytes 4 to 16
*/
p++;
ap = xp->x25_udata + 4; /* first four bytes are protocol id */
limit = ap + sizeof (xp->x25_udata) - 4;
xp->x25_udlen = 4;
while (*p) {
if (*p == ',')
break;
if (ap >= limit)
return (0);
p = copychar (p, ap++);
xp->x25_udlen++;
}
if (xp->x25_udlen == 4)
xp->x25_udlen = 0;
if (*p == '\0')
return (1);
p++;
ap = xp->x25_udata; /* protocol id */
limit = ap + (xp->x25_udlen ? 4 : sizeof(xp->x25_udata));
while (*p) {
if (*p == ',')
return (0);
if (ap >= limit)
return (0);
p = copychar (p, ap++);
}
if (xp->x25_udlen == 0)
xp->x25_udlen = ap - xp->x25_udata;
return (1);
}
static char *
copychar (from, to)
register char *from, *to;
{
register int n;
if (*from != '\\' || from[1] < '0' || from[1] > '7') {
*to = *from++;
return (from);
}
n = *++from - '0';
from++;
if (*from >= '0' && *from <= '7') {
register int n1;
n = n*8 + *from++ - '0';
if (*from >= '0' && *from <= '7' && (n1 = n*8 + *from-'0') < 256) {
n = n1;
from++;
}
}
*to = n;
return (from);
}

View File

@ -43,7 +43,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)route.c 8.3 (Berkeley) 3/19/94";
*/
static const char rcsid[] =
"$Id$";
"$Id: route.c,v 1.22 1997/02/22 14:33:10 peter Exp $";
#endif /* not lint */
#include <sys/param.h>
@ -61,12 +61,6 @@ static const char rcsid[] =
#ifdef NS
#include <netns/ns.h>
#endif
#ifdef ISO
#include <netiso/iso.h>
#endif
#ifdef CCITT
#include <netccitt/x25.h>
#endif
#include <arpa/inet.h>
#include <netdb.h>
@ -96,14 +90,8 @@ union sockunion {
struct sockaddr_at sat;
#ifdef NS
struct sockaddr_ns sns;
#endif
#ifdef ISO
struct sockaddr_iso siso;
#endif
struct sockaddr_dl sdl;
#ifdef CCITT
struct sockaddr_x25 sx25;
#endif
} so_dst, so_gate, so_mask, so_genmask, so_ifa, so_ifp;
typedef union sockunion *sup;
@ -122,9 +110,6 @@ void flushroutes(), newroute(), monitor(), sockaddr(), sodump(), bprintf();
void print_getmsg(), print_rtmsg(), pmsg_common(), pmsg_addrs(), mask_addr();
int getaddr(), rtmsg(), x25_makemask();
extern char *inet_ntoa(), *iso_ntoa(), *link_ntoa();
#ifdef CCITT
extern int ccitt_addr __P((char *, struct sockaddr_x25 *));
#endif
void usage __P((const char *)) __dead2;
@ -250,16 +235,6 @@ flushroutes(argc, argv)
case K_LINK:
af = AF_LINK;
break;
#ifdef ISO
case K_ISO:
case K_OSI:
af = AF_ISO;
break;
#endif
#ifdef CCITT
case K_X25:
af = AF_CCITT;
#endif
default:
goto bad;
} else
@ -388,12 +363,6 @@ routename(sa)
case AF_LINK:
return (link_ntoa((struct sockaddr_dl *)sa));
#ifdef ISO
case AF_ISO:
(void) snprintf(line, sizeof line, "iso %s",
iso_ntoa(&((struct sockaddr_iso *)sa)->siso_addr));
break;
#endif
default:
{ u_short *s = (u_short *)sa;
u_short *slim = s + ((sa->sa_len + 1) >> 1);
@ -492,12 +461,6 @@ netname(sa)
case AF_LINK:
return (link_ntoa((struct sockaddr_dl *)sa));
#ifdef ISO
case AF_ISO:
(void) snprintf(line, sizeof(line), "iso %s",
iso_ntoa(&((struct sockaddr_iso *)sa)->siso_addr));
break;
#endif
default:
{ u_short *s = (u_short *)sa->sa_data;
@ -563,13 +526,6 @@ newroute(argc, argv)
af = AF_LINK;
aflen = sizeof(struct sockaddr_dl);
break;
#ifdef ISO
case K_OSI:
case K_ISO:
af = AF_ISO;
aflen = sizeof(struct sockaddr_iso);
break;
#endif
case K_INET:
af = AF_INET;
aflen = sizeof(struct sockaddr_in);
@ -578,12 +534,6 @@ newroute(argc, argv)
af = AF_APPLETALK;
aflen = sizeof(struct sockaddr_at);
break;
#ifdef CCITT
case K_X25:
af = AF_CCITT;
aflen = sizeof(struct sockaddr_x25);
break;
#endif
case K_SA:
af = PF_ROUTE;
aflen = sizeof(union sockunion);
@ -684,25 +634,6 @@ newroute(argc, argv)
gateway = *argv;
(void) getaddr(RTA_GATEWAY, *argv, &hp);
} else {
#ifdef CRUFT
int ret = atoi(*argv);
if (ret == 0) {
if (strcmp(*argv, "0") == 0)
printf("%s,%s",
"old usage of trailing 0",
"assuming route to if\n");
else
usage((char *)NULL);
iflag = 1;
continue;
} else if (ret > 0 && ret < 10) {
printf("old usage of trailing digit, ");
printf("assuming route via gateway\n");
iflag = 0;
continue;
}
#endif
(void) getaddr(RTA_NETMASK, *argv, 0);
}
}
@ -815,9 +746,6 @@ getaddr(which, s, hpp)
register sup su;
#ifdef NS
struct ns_addr ns_addr();
#endif
#ifdef ISO
struct iso_addr *iso_addr();
#endif
struct hostent *hp;
struct netent *np;
@ -926,17 +854,6 @@ getaddr(which, s, hpp)
return (!ns_nullhost(su->sns.sns_addr));
#endif
#ifdef ISO
case AF_OSI:
su->siso.siso_addr = *iso_addr(s);
if (which == RTA_NETMASK || which == RTA_GENMASK) {
register char *cp = (char *)TSEL(&su->siso);
su->siso.siso_nlen = 0;
do {--cp ;} while ((cp > (char *)su) && (*cp == 0));
su->siso.siso_len = 1 + cp - (char *)su;
}
return (1);
#endif
case AF_APPLETALK:
if (!atalk_aton(s, &su->sat.sat_addr))
@ -948,11 +865,6 @@ getaddr(which, s, hpp)
link_addr(s, &su->sdl);
return (1);
#ifdef ISO
case AF_CCITT:
ccitt_addr(s, &su->sx25);
return (which == RTA_DST ? x25_makemask() : 1);
#endif
case PF_ROUTE:
su->sa.sa_len = sizeof(*su);
@ -995,22 +907,6 @@ getaddr(which, s, hpp)
errx(EX_NOHOST, "bad address: %s", s);
}
#ifdef CCITT
int
x25_makemask()
{
register char *cp;
if ((rtm_addrs & RTA_NETMASK) == 0) {
rtm_addrs |= RTA_NETMASK;
for (cp = (char *)&so_mask.sx25.x25_net;
cp < &so_mask.sx25.x25_opts.op_flags; cp++)
*cp = -1;
so_mask.sx25.x25_len = (u_char)&(((sup)0)->sx25.x25_opts);
}
return 0;
}
#endif
#ifdef NS
short ns_nullh[] = {0,0,0};
@ -1201,17 +1097,8 @@ mask_addr()
#endif
case AF_INET:
case AF_APPLETALK:
#ifdef CCITT
case AF_CCITT:
#endif
case 0:
return;
#ifdef ISO
case AF_ISO:
olen = MIN(so_dst.siso.siso_nlen,
MAX(so_mask.sa.sa_len - 6, 0));
break;
#endif
}
cp1 = so_mask.sa.sa_len + 1 + (char *)&so_dst;
cp2 = so_dst.sa.sa_len + 1 + (char *)&so_dst;
@ -1220,13 +1107,6 @@ mask_addr()
cp2 = so_mask.sa.sa_len + 1 + (char *)&so_mask;
while (cp1 > so_dst.sa.sa_data)
*--cp1 &= *--cp2;
#ifdef ISO
switch (so_dst.sa.sa_family) {
case AF_ISO:
so_dst.siso.siso_nlen = olen;
break;
}
#endif
}
char *msgtypes[] = {
@ -1493,12 +1373,6 @@ sodump(su, which)
(void) printf("%s: link %s; ",
which, link_ntoa(&su->sdl));
break;
#ifdef ISO
case AF_ISO:
(void) printf("%s: iso %s; ",
which, iso_ntoa(&su->siso.siso_addr));
break;
#endif
case AF_INET:
(void) printf("%s: inet %s; ",
which, inet_ntoa(su->sin.sin_addr));