#include <u.h>
#include <libc.h>
#include <ip.h>
void
usage(void)
{
fprint(2, "usage: inrange [-4 | -6] ipaddr iprange [iprange...]\n");
exits("usage");
}
void
main(int argc, char *argv[])
{
int i, ipver;
uchar mask[IPaddrlen];
uchar qip[IPaddrlen], rip[IPaddrlen], mqip[IPaddrlen], mrip[IPaddrlen];
fmtinstall('V', eipfmt);
fmtinstall('I', eipfmt);
ipver=4;
ARGBEGIN {
case '4':
ipver=4;
break;
case '6':
ipver=6;
break;
} ARGEND
if(argc < 2)
usage();
if(ipver==4) {
v4parseip(qip, argv[0]);
for(i=1; i<argc; i++) {
v4parseip(rip, strtok(argv[i], "/"));
/* parseipmask(mask, strcat("/", strtok(nil, "/"))); /* causes missing prints */
parseipmask(mask, smprint("%s/", strtok(nil, "/")));
fprint(2, "%V %V\n", qip, rip);
maskip(qip, mask, mqip);
maskip(rip, mask, mrip);
fprint(2, "%V %V\n", mqip, mrip);
if(equivip4(mqip, mrip))
exits(nil);
}
exits("no match");
} else if(ipver==6) {
parseip(qip, argv[0]);
for(i=1; i<argc; i++) {
parseip(rip, strtok(argv[i], "/"));
/* parseipmask(mask, strcat("/", strtok(nil, "/"))); /* causes missing prints */
parseipmask(mask, smprint("%s/", strtok(nil, "/")));
fprint(2, "%I %I\n", qip, rip);
maskip(qip, mask, mqip);
maskip(rip, mask, mrip);
fprint(2, "%I %I\n", mqip, mrip);
if(equivip6(mqip, mrip))
exits(nil);
}
exits("no match");
} else
usage();
}
|