1 // --- T2-COPYRIGHT-NOTE-BEGIN ---
2 // This copyright note is auto-generated by ./scripts/Create-CopyPatch.
4 // T2 SDE: package/.../iproute2/ipnm2nwbc.c
5 // Copyright (C) 2004 - 2005 The T2 SDE Project
6 // Copyright (C) 1998 - 2003 ROCK Linux Project
8 // More information can be found in the files COPYING and README.
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; version 2 of the License. A copy of the
13 // GNU General Public License can be found in the file COPYING.
14 // --- T2-COPYRIGHT-NOTE-END ---
35 int main(int argc
, char ** argv
) {
36 int ip
[4],nm
[4],nw
[4],bc
[4],c
;
37 int verbose
=0,nmbits
=0,n
;
39 if ( argc
> 1 && !strcmp(argv
[1],"-v") ) verbose
=1;
41 if ( argc
== 3+verbose
&&
42 sscanf(argv
[1+verbose
],"%d.%d.%d.%d",ip
,ip
+1,ip
+2,ip
+3) == 4 &&
43 sscanf(argv
[2+verbose
],"%d.%d.%d.%d",nm
,nm
+1,nm
+2,nm
+3) == 4 ) {
44 nmbits
=getbits(nm
[0])+getbits(nm
[1])+
45 getbits(nm
[2])+getbits(nm
[3]);
46 } else if ( argc
== 2+verbose
&& sscanf(argv
[1+verbose
],
47 "%d.%d.%d.%d/%d",ip
,ip
+1,ip
+2,ip
+3,&nmbits
) == 5 ) {
49 if (n
>0) { nm
[0]=setbits(n
>8?8:n
); n
-=8; } else nm
[0]=0;
50 if (n
>0) { nm
[1]=setbits(n
>8?8:n
); n
-=8; } else nm
[1]=0;
51 if (n
>0) { nm
[2]=setbits(n
>8?8:n
); n
-=8; } else nm
[2]=0;
52 if (n
>0) { nm
[3]=setbits(n
>8?8:n
); n
-=8; } else nm
[3]=0;
55 "IP and Netmask to Network and Broadcast converter.\n"
56 "(C) under GPL, 1999 Clifford Wolf\n\n"
57 "Usage: %s [-v] <IP> <Netmask>\n"
58 " %s [-v] <IP>/<Mask>\n\n"
59 "Examples: %s -v 195.170.70.72/25\n"
60 " %s 195.170.70.72 255.255.255.128\n\n",
61 argv
[0],argv
[0],argv
[0],argv
[0]);
67 bc
[c
]=nw
[c
]|(255&~nm
[c
]);
71 printf("Network: %d.%d.%d.%d / %d\n",
72 nw
[0],nw
[1],nw
[2],nw
[3],nmbits
);
73 printf("Netmask: %d.%d.%d.%d\n",
74 nm
[0],nm
[1],nm
[2],nm
[3]);
75 printf("Broadcast: %d.%d.%d.%d\n",
76 bc
[0],bc
[1],bc
[2],bc
[3]);
78 printf("%d.%d.%d.%d %d.%d.%d.%d\n",nw
[0],nw
[1],
79 nw
[2],nw
[3],bc
[0],bc
[1],bc
[2],bc
[3]);