summaryrefslogtreecommitdiff
path: root/src/bin/cidr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/cidr.c')
-rw-r--r--src/bin/cidr.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/bin/cidr.c b/src/bin/cidr.c
new file mode 100644
index 0000000..fe44668
--- /dev/null
+++ b/src/bin/cidr.c
@@ -0,0 +1,25 @@
+#include <stdio.h>
+
+int main(int argc,char *argv[]) {
+ unsigned int cidr;
+ unsigned int net;
+ unsigned int mask;
+ if(argc < 2) {
+ printf("usage: cidr address/cidr\n");
+ printf("example: cidr 192.168.0.1/24\n");
+ return 1;
+ }
+ if(!strchr(argv[1],'/')) {
+ cidr=32;
+ net=argv[1];
+ } else {
+ cidr=atoi(strchr(argv[1],'/')+1);
+ *strchr(argv[1],'/')=0;
+ net=htonl(inet_addr(argv[1]));
+ }
+ printf("%d.%d.%d.%d ",net>>24&255,net>>16&255,net>>8&255,net&255);
+ mask=-1;
+ mask>>=(32-cidr);
+ mask<<=(32-cidr);
+ printf("%d.%d.%d.%d\n",mask>>24&255,mask>>16&255,mask>>8&255,mask&255);
+}