2016-04-04 10:37:07 +03:00
|
|
|
/* $NetBSD: show.c,v 1.50 2016/04/04 07:37:07 ozaki-r Exp $ */
|
1996-11-15 21:01:36 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1983, 1988, 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.
|
2003-08-07 14:04:22 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1996-11-15 21:01:36 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
1997-09-15 13:15:26 +04:00
|
|
|
#include <sys/cdefs.h>
|
1996-11-15 21:01:36 +03:00
|
|
|
#ifndef lint
|
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "from: @(#)route.c 8.3 (Berkeley) 3/9/94";
|
|
|
|
#else
|
2016-04-04 10:37:07 +03:00
|
|
|
__RCSID("$NetBSD: show.c,v 1.50 2016/04/04 07:37:07 ozaki-r Exp $");
|
1996-11-15 21:01:36 +03:00
|
|
|
#endif
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
2010-06-26 18:29:36 +04:00
|
|
|
#include <arpa/inet.h>
|
1996-11-15 21:01:36 +03:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
#include <netinet/in.h>
|
2010-06-26 18:29:36 +04:00
|
|
|
#include <netmpls/mpls.h>
|
1996-11-15 21:01:36 +03:00
|
|
|
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
|
|
|
#include <netdb.h>
|
2008-09-09 20:18:17 +04:00
|
|
|
#include <stdbool.h>
|
1996-11-15 21:01:36 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
1997-11-16 20:03:11 +03:00
|
|
|
#include <err.h>
|
1996-11-15 21:01:36 +03:00
|
|
|
|
2005-08-10 01:25:42 +04:00
|
|
|
#include "keywords.h"
|
2014-11-07 00:29:32 +03:00
|
|
|
#include "rtutil.h"
|
1997-04-03 06:35:46 +04:00
|
|
|
#include "extern.h"
|
2010-12-13 20:39:47 +03:00
|
|
|
#include "prog_ops.h"
|
1996-11-15 21:01:36 +03:00
|
|
|
|
2006-09-24 02:41:25 +04:00
|
|
|
void
|
2008-09-10 05:06:58 +04:00
|
|
|
parse_show_opts(int argc, char * const *argv, int *afp, int *flagsp,
|
2008-09-09 20:18:17 +04:00
|
|
|
const char **afnamep, bool nolink)
|
2006-09-24 02:41:25 +04:00
|
|
|
{
|
|
|
|
const char *afname = "unspec";
|
|
|
|
int af, flags;
|
|
|
|
|
|
|
|
flags = 0;
|
|
|
|
af = AF_UNSPEC;
|
|
|
|
for (; argc >= 2; argc--) {
|
|
|
|
if (*argv[argc - 1] != '-')
|
|
|
|
goto bad;
|
|
|
|
switch (keyword(argv[argc - 1] + 1)) {
|
|
|
|
case K_HOST:
|
|
|
|
flags |= RTF_HOST;
|
|
|
|
break;
|
|
|
|
case K_INET:
|
|
|
|
af = AF_INET;
|
|
|
|
afname = argv[argc - 1] + 1;
|
|
|
|
break;
|
|
|
|
#ifdef INET6
|
|
|
|
case K_INET6:
|
|
|
|
af = AF_INET6;
|
|
|
|
afname = argv[argc - 1] + 1;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifndef SMALL
|
|
|
|
case K_ATALK:
|
|
|
|
af = AF_APPLETALK;
|
|
|
|
afname = argv[argc - 1] + 1;
|
|
|
|
break;
|
2010-06-26 18:29:36 +04:00
|
|
|
case K_MPLS:
|
|
|
|
af = AF_MPLS;
|
|
|
|
afname = argv[argc - 1] + 1;
|
|
|
|
break;
|
2006-09-24 02:41:25 +04:00
|
|
|
#endif /* SMALL */
|
|
|
|
case K_LINK:
|
|
|
|
if (nolink)
|
|
|
|
goto bad;
|
|
|
|
af = AF_LINK;
|
|
|
|
afname = argv[argc - 1] + 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (argc) {
|
|
|
|
case 1:
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bad:
|
|
|
|
usage(argv[argc - 1]);
|
|
|
|
}
|
|
|
|
if (afnamep != NULL)
|
|
|
|
*afnamep = afname;
|
|
|
|
*afp = af;
|
|
|
|
*flagsp = flags;
|
|
|
|
}
|
|
|
|
|
1996-11-15 21:01:36 +03:00
|
|
|
/*
|
|
|
|
* Print routing tables.
|
|
|
|
*/
|
|
|
|
void
|
2014-11-07 00:29:32 +03:00
|
|
|
show(int argc, char *const *argv, int flags)
|
1996-11-15 21:01:36 +03:00
|
|
|
{
|
2014-11-07 00:29:32 +03:00
|
|
|
int af, rflags;
|
|
|
|
static int interesting = RTF_UP | RTF_GATEWAY | RTF_HOST |
|
2016-04-04 10:37:07 +03:00
|
|
|
RTF_REJECT | RTF_LOCAL | RTF_BROADCAST;
|
1996-11-15 21:01:36 +03:00
|
|
|
|
2014-11-07 00:29:32 +03:00
|
|
|
parse_show_opts(argc, argv, &af, &rflags, NULL, true);
|
|
|
|
p_rttables(af, flags, rflags, interesting);
|
1996-11-15 21:01:36 +03:00
|
|
|
}
|