/*
* Copyright 2001-2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Copyright (c) 1982, 1986, 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
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgment:
* 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.
*
* sheldonh Exp $
* char copyright[] = "@(#) Copyright (c) 1982, 1986, 1993\n"
* "The Regents of the University of California. All rights reserved.\n";
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "defs.h"
#include <netdb.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <md5.h>
#include <libintl.h>
#include <locale.h>
#ident "$Revision: 1.12 $"
/*
* The size of the control buffer passed to recvmsg() used to receive
* ancillary data.
*/
static const char *pgmname;
static union {
} omsg_buf;
static union {
} imsg_buf;
static int out(const char *, int);
static void trace_loop(char *argv[], int);
static void query_loop(char *argv[], int, int);
static void usage(void);
int
{
const char *result;
int on;
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#endif /* ! TEXT_DOMAIN */
(void) textdomain(TEXT_DOMAIN);
pgmname = "rtquery";
switch (ch) {
case 'n':
break;
case 'p':
break;
case '1':
break;
case 'w':
usage();
break;
case 'r':
if (rflag)
usage();
if (rflag) {
} else {
}
}
break;
case 't':
while (*options != '\0') {
/* messy complications to make -W -Wall happy */
static char *traceopts[] = {
#define TRACE_ON 0
0
};
result = "";
&value)) {
case TRACE_ON:
usage();
break;
case TRACE_MORE:
usage();
break;
case TRACE_OFF:
usage();
break;
case TRACE_DUMP:
usage();
result = "dump/../table";
break;
default:
usage();
}
result, MAXPATHLEN);
}
break;
case 'a':
if (p == NULL)
usage();
*p++ = '\0';
else
usage();
usage();
if (auth_type == RIP_AUTH_MD5 &&
delim == '|') {
tmp_ptr = p+1;
p == tmp_ptr)
usage();
} else if (delim != '\0') {
usage();
}
break;
default:
usage();
}
usage();
if (argc == 0) {
argc = 1;
argv = default_argv;
}
if (soc < 0) {
perror("rtquery: socket");
}
on = 1;
perror("rtquery: setsockopt IP_RECVIF");
/* be prepared to receive a lot of routes */
break;
if (bsize <= MIN_RCVBUF) {
perror("rtquery: setsockopt SO_RCVBUF");
break;
}
}
if (trace)
else
/* NOTREACHED */
return (0);
}
static void
usage(void)
{
gettext("usage: %s [-np1] [-r tgt_rt] [-w wtime]"
" [-a type=passwd] [host1 ...]\n"),
pgmname);
gettext("\t%s -t {on=filename|more|off|dump} [host1 ...]\n"),
pgmname);
}
/* Tell the target hosts about tracing */
static void
{
int res;
if (ripv2) {
} else {
}
perror("rtquery: setsockopt UDP_ANONPRIVBIND");
}
perror("rtquery: bind");
}
res = EXIT_FAILURE;
res = EXIT_SUCCESS;
}
}
/* Query all of the listed hosts */
static void
{
struct seen {
int answered = 0;
int cc;
if (ripv2) {
if (auth_type == RIP_AUTH_PW) {
} else if (auth_type == RIP_AUTH_MD5) {
}
} else {
}
/* ask the first (valid) host */
answered++;
}
for (;;) {
if (cc > 0) {
if (cc < 0) {
perror("rtquery: recvmsg");
}
/* avoid looping on high traffic */
break;
/*
* count the distinct responding hosts.
* You cannot match responding hosts with
* addresses to which queries were transmitted,
* because a router might respond with a
* different source address.
*/
break;
}
} else {
perror("rtquery: malloc");
}
answered++;
}
continue;
}
if (cc < 0) {
continue;
perror("rtquery: select");
}
/*
* After a pause in responses, probe another host.
* This reduces the intermingling of answers.
*/
answered++;
/*
* continue until no more packets arrive
* or we have heard from all hosts
*/
break;
/* or until we have waited a long time */
if (gettimeofday(&now, 0) < 0) {
perror("rtquery: gettimeofday");
}
break;
}
/* fail if there was no answer */
}
/* Send to one host */
static int
{
int ret;
if (gettimeofday(&sent, 0) < 0) {
perror("rtquery: gettimeofday");
return (-1);
}
return (-1);
}
res->ai_addrlen) < 0) {
perror("rtquery: sendto");
return (-1);
}
return (0);
}
/*
* Handle an incoming RIP packet.
*/
static void
{
const char *name;
char *sp;
int i;
} else {
/* safe; cannot overflow destination */
}
if (ifindex == 0) {
} else {
else
ifindex);
}
return;
}
size);
if (size > MAXPACKETSIZE) {
(void) printf(
gettext(" at least %d bytes too long\n"),
} else {
}
}
for (; n < lim; n++) {
name = "";
if (n->n_family == RIP_AF_INET) {
sizeof (net_buf));
if (mask != 0) {
(sizeof (net_buf) -
gettext(" mask=%s ? "),
mask = 0;
(sizeof (net_buf) -
} else {
(sizeof (net_buf) -
gettext(" (mask %s)"),
}
}
if (!nflag) {
if (mask == 0) {
mask = 0;
}
/*
* Without a netmask, do not worry about
* whether the destination is a host or a
* network. Try both and use the first name
* we get.
*
* If we have a netmask we can make a
* good guess.
*/
AF_INET);
name = "default";
}
if (name[0] == '\0' &&
mask == 0xffffffff)) {
}
}
} else if (n->n_family == RIP_AF_AUTH) {
(void) printf(
gettext(" Password Authentication:"
" \"%s\"\n"),
continue;
}
" len=%1$d KeyID=%2$d"
" auth_len=%3$d"
" seqno=%4$#x"
" rsvd=%5$#x,%6$#x\n"),
md5_authed = 1;
continue;
}
(void) printf("%02x ",
(void) putchar('\n');
"authentication entry missing hash\n"));
}
continue;
} else {
gettext("(address family %1$u) %2$s"),
}
if (n->n_nhop != 0) {
if (nflag)
else
AF_INET);
}
if (n->n_tag != 0)
(void) putchar('\n');
}
}
/*
* Find the interface which received the given message.
*/
static uint_t
{
void *opt;
/*
* Determine which physical interface this packet was received on by
* processing the message's ancillary data to find the
* IP_RECVIF option we requested.
*/
gettext("%s: unable to retrieve input interface\n"),
pgmname);
else
return (ifindex);
}