testiv.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2000-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
#include <iv.h>
#include <ip6.h>
#include <error.h>
#include <option.h>
#include <ctype.h>
static const char usage[] =
"[-?\n@(#)$Id: testiv (AT&T Research) 2011-10-06 $\n]"
"[+NAME?testiv - iv ipv6 longest prefix match test harness]"
"[+DESCRIPTION?\btestiv\b loads the ipv6 prefixes in \aprefix-file\a and "
"then does a longest prefix match for each ipv6 address in each "
"\aaddress-file\a. If \aaddress-file\a is omitted or \b-\b then the "
"standard input is read. Matched addresses are listed with the longest "
"matching prefix and optional associated string one line per match. "
"\b-\b is listed instead of the prefix for unmatched addresses.]"
"[+?\aprefix-file\a must contain a sequence of lines of one or two space "
"separated fields, with the \bipv6\b prefix in the first field and an "
"optional string identifying the interval in the second field. Each "
"\aaddress-file\a must contain a sequence of lines with the \bipv6\b "
"address in the first space separated field.]"
"[d:dump?Dump the prefix table before matching the addresses.]"
"[D:debug?Enable implementation defined debugging code.]"
"[i:ip?Set the IP version to \aversion\a.]:[version:=v6]"
"{"
"[4:4|p4|v4?32 bit IPv4 addresses.]"
"[6:6|p6|v6?128 bit IPv6 addresses.]"
"}"
"\n"
"\nprefix-file [ address-file ... ]\n"
"\n"
"[+SEE ALSO?\blpm\b(1), \bfv\b(3), \biv\b(3)]"
;
typedef struct Hop_s
{
char name[1];
} Hop_t;
static void
{
}
int
{
char* file;
char* s;
char* v;
unsigned char* lo;
unsigned char* hi;
int size = 16;
int dump = 0;
for (;;)
{
{
case 'd':
dump = 1;
continue;
case 'D':
continue;
case 'i':
{
case '4':
size = 4;
break;
case '6':
size = 16;
break;
}
continue;
case '?':
continue;
case ':':
continue;
}
break;
}
else
{
while (isspace(*v))
v++;
if (!*v)
v = "(unknown)";
{
break;
}
if (dump)
sfprintf(sfstdout, "set %-42s %-42s %-42s %s\n", ivfmt(iv, lo, prefix[size]), ivfmt(iv, lo, -1), ivfmt(iv, hi, -1), v);
{
break;
}
}
do
{
{
sfprintf(sfstdout, "%s%-42s %-42s %s\n", dump ? "get " : "", ivfmt(iv, addr, -1), ivfmt(iv, hop->prefix, hop->prefix[iv->size]), hop->name);
}
else
return 0;
}