From a05876c9b860f1d5fa786746519ccb8b01db79e3 Mon Sep 17 00:00:00 2001 From: epochqwert Date: Fri, 12 Jun 2015 22:26:31 -0500 Subject: commit of half-finished things. --- src/bin/fontdump.c | 2 +- src/bin/iplist2cidr.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/bin/iprand.c | 17 +++++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/bin/iplist2cidr.c create mode 100644 src/bin/iprand.c (limited to 'src') diff --git a/src/bin/fontdump.c b/src/bin/fontdump.c index eb481d0..1ed2b05 100644 --- a/src/bin/fontdump.c +++ b/src/bin/fontdump.c @@ -10,7 +10,7 @@ int main(int argc,char *argv[]) { read(0,map,height); for(j=0;j=0;k--) { - printf("%c",(map[j]>>k&1)?'#':' '); + printf("%c",(map[j]>>k&1)?'#':'.'); } printf("\n"); } diff --git a/src/bin/iplist2cidr.c b/src/bin/iplist2cidr.c new file mode 100644 index 0000000..b3cc62c --- /dev/null +++ b/src/bin/iplist2cidr.c @@ -0,0 +1,79 @@ +#include +#include + +struct net { + unsigned int ip; + unsigned char cidr; +}; + +#define min(a,b) ((a)<(b)?(a):(b)) +#define max(a,b) ((a)>(b)?(a):(b)) + +int main(int argc,char *argv[]) { + short in; + int maxcidr; + int i=0,j=0,len=0; + struct net list[65536];//don't do more than a /16! + char ips[64];//why not? + char *cidrs; + while((in=fgetc(stdin)) != -1) { + if(in=='\n') { + ips[i]=0; + if((cidrs=strchr(ips,'/')) != 0) { + *cidrs=0; + cidrs++; + } + list[len].ip=htonl(inet_addr(ips)); + list[len].cidr=cidrs?atoi(cidrs):32; + i=0; + cidrs=0; + len++; + continue; + } + ips[i]=in; + i++; + if(i>63) { + printf("your have a line that is TOOO long. stick to IPv4.\n"); + return 0; + } + } + //!!!warning!!! inefficient algo ahead! + for(i=0;i> (32-list[i].cidr) == 1) { + list[i].cidr--; + list[j].cidr--; + list[i].ip &= (0xffffffff << (32-list[i].cidr)); + list[j].ip &= (0xffffffff << (32-list[j].cidr)); + i=-1;//start over! + j=-1;//start over! + continue; + } + } + if(list[i].ip == list[j].ip && list[i].cidr != list[j].cidr) { + list[i].cidr = min(list[i].cidr,list[j].cidr); + list[j].cidr = min(list[i].cidr,list[j].cidr); + i=-1;//start over! + j=-1;//start over! + continue; + } + maxcidr=min(list[i].cidr,list[j].cidr); + if(list[i].cidr != list[j].cidr) { + if(list[i].ip >> (32-maxcidr) == list[j].ip >> (32-maxcidr) ) { + list[i].cidr = min(list[i].cidr,list[j].cidr); + list[j].cidr = min(list[i].cidr,list[j].cidr); + list[i].ip &= (0xffffffff << (32-list[i].cidr)); + list[j].ip &= (0xffffffff << (32-list[j].cidr)); + i=-1;//start over! + j=-1;//start over! + continue; + } + } + } + } + for(i=0;i>24&255,list[i].ip>>16&255,list[i].ip>>8&255,list[i].ip&255,list[i].cidr); + } + return 0; +} diff --git a/src/bin/iprand.c b/src/bin/iprand.c new file mode 100644 index 0000000..e6b2f83 --- /dev/null +++ b/src/bin/iprand.c @@ -0,0 +1,17 @@ +#include +#include + +int main(int argc,char *argv[]) { + srandom(time(0)+getpid()); + unsigned int ip; + unsigned int net=argc>1?htonl(inet_addr(argv[1])):0x0; + unsigned int mask=argc>2?htonl(inet_addr(argv[2])):0x0; + unsigned int a=argc>3?atoi(argv[3]):3; + net &= mask; + for(;a>0;a--) { + ip=random(); + ip &= ~mask; + ip |= net; + printf("%d.%d.%d.%d\n",ip>>24&255,ip>>16&255,ip>>8&255,ip&255); + } +} -- cgit v1.2.3