summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bin/fontdump.c2
-rw-r--r--src/bin/iplist2cidr.c79
-rw-r--r--src/bin/iprand.c17
3 files changed, 97 insertions, 1 deletions
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<height;j++) {
for(k=7;k>=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 <stdio.h>
+#include <string.h>
+
+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<len;i++) {
+ for(j=0;j<len;j++) {
+ if(list[i].cidr == list[j].cidr) {
+ if((list[i].ip ^ list[j].ip) >> (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<len;i++) {
+ printf("%d.%d.%d.%d/%d\n",list[i].ip>>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 <stdio.h>
+#include <time.h>
+
+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);
+ }
+}