Example #1
0
int
main(int argc, char** argv)
{
	char*		s;
	char*		e;
	char*		f;
	unsigned char	b;
	unsigned char	a[IP6ADDR];
	int		c;
	int		r;
	int		all = 1;

	while (s = *++argv)
	{
		if (*s == '-' && !*(s + 1))
		{
			all = !all;
			continue;
		}
		r = strtoip6(s, &e, a, &b);
		f = fmtip6(a, b);
		c = *e;
		*e = 0;
		if (r || all || strcmp(s, f))
		{
			*e = c;
			printf("%d %32s %32s %s\n", r, s, e, f);
		}
	}
	return 0;
}
Example #2
0
int
main(int argc, char** argv)
{
	char*		file;
	char*		s;
	Ptv_t*		ptv;
	Ptvprefix_t*	pp;
	Sfio_t*		sp;
	unsigned char	prefix[IP6PREFIX];
	unsigned char	addr[IP6ADDR];
	Ptvdisc_t	ptvdisc;

	int		dump = 0;

	error_info.id = "testptv";
	ptvinit(&ptvdisc);
	ptvdisc.errorf = errorf;
	for (;;)
	{
		switch (optget(argv, usage))
		{
		case 'd':
			dump = 1;
			continue;
		case '?':
			error(ERROR_USAGE|4, "%s", opt_info.arg);
			continue;
		case ':':
			error(2, "%s", opt_info.arg);
			continue;
		}
		break;
	}
	argv += opt_info.index;
	if (!(file = *argv++))
		error(ERROR_USAGE|4, "%s", optusage(0));
	if (!(sp = sfopen(0, file, "r")))
		error(ERROR_SYSTEM|3, "%s: cannot read prefix file", file);
	if (!(ptv = ptvopen(&ptvdisc, 16)))
		error(3, "cannot open ptv table");
	while (s = sfgetr(sp, '\n', 1))
		if (strtoip6(s, 0, prefix, prefix + IP6BITS))
			error(1, "%s: invalid prefix", s);
		else
		{
			if (dump)
				sfprintf(sfstderr, "insert  %s  %s\n", fmtip6(ptvmin(ptv->size, ptv->r[0], prefix, prefix[IP6BITS]), prefix[IP6BITS]), fmtip6(ptvmax(ptv->size, ptv->r[1], prefix, prefix[IP6BITS]), prefix[IP6BITS]));
			if (!ptvinsert(ptv, ptvmin(ptv->size, ptv->r[0], prefix, prefix[IP6BITS]), ptvmax(ptv->size, ptv->r[1], prefix, prefix[IP6BITS])))
			{
				error(2, "%s: ptv insertion error", s);
				break;
			}
		}
	sfclose(sp);
	if (dump)
		ptvdump(ptv, sfstdout);
	file = *argv++;
	do
	{
		if (!file || streq(file, "-"))
			sp = sfstdin;
		else if (!(sp = sfopen(0, file, "r")))
			error(ERROR_SYSTEM|3, "%s: cannot read address file", file);
		while (s = sfgetr(sp, '\n', 1))
			if (strtoip6(s, 0, addr, 0))
				error(1, "%s: invalid address", s);
			else if (pp = ptvmatch(ptv, addr))
				sfprintf(sfstdout, "%-38s %-38s %-38s\n", fmtip6(addr, -1), fmtip6(pp->min, -1), fmtip6(pp->max, -1));
			else
				sfprintf(sfstdout, "%-38s -\n", fmtip6(addr, -1));
		if (sp != sfstdin)
			sfclose(sp);
	} while (file && (file = *argv++));
	ptvclose(ptv);
	return 0;
}
Example #3
0
int
ptvprint(Ptv_t* a, Sfio_t* sp)
{
	PTVSCAN(a, b, sfprintf(sp, "%s\n", fmtip6(a->r[0], b)));
	return sfsync(sp);
}