1 // --- T2-COPYRIGHT-NOTE-BEGIN ---
2 // T2 SDE: package/*/iproute2/ipnm2nwbc.c
3 // Copyright (C) 2004 - 2023 The T2 SDE Project
4 // Copyright (C) 1998 - 2003 ROCK Linux Project
6 // This Copyright note is generated by scripts/Create-CopyPatch,
7 // more information can be found in the files COPYING and README.
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License version 2.
11 // --- T2-COPYRIGHT-NOTE-END ---
33 int main(int argc
, char ** argv
) {
34 int ip
[4],nm
[4],nw
[4],bc
[4],c
;
35 int verbose
=0,nmbits
=0,n
;
37 if ( argc
> 1 && !strcmp(argv
[1],"-v") ) verbose
=1;
39 if ( argc
== 3+verbose
&&
40 sscanf(argv
[1+verbose
],"%d.%d.%d.%d",ip
,ip
+1,ip
+2,ip
+3) == 4 &&
41 sscanf(argv
[2+verbose
],"%d.%d.%d.%d",nm
,nm
+1,nm
+2,nm
+3) == 4 ) {
42 nmbits
=getbits(nm
[0])+getbits(nm
[1])+
43 getbits(nm
[2])+getbits(nm
[3]);
44 } else if ( argc
== 2+verbose
&& sscanf(argv
[1+verbose
],
45 "%d.%d.%d.%d/%d",ip
,ip
+1,ip
+2,ip
+3,&nmbits
) == 5 ) {
47 if (n
>0) { nm
[0]=setbits(n
>8?8:n
); n
-=8; } else nm
[0]=0;
48 if (n
>0) { nm
[1]=setbits(n
>8?8:n
); n
-=8; } else nm
[1]=0;
49 if (n
>0) { nm
[2]=setbits(n
>8?8:n
); n
-=8; } else nm
[2]=0;
50 if (n
>0) { nm
[3]=setbits(n
>8?8:n
); n
-=8; } else nm
[3]=0;
53 "IP and Netmask to Network and Broadcast converter.\n"
54 "(C) under GPL, 1999 Clifford Wolf\n\n"
55 "Usage: %s [-v] <IP> <Netmask>\n"
56 " %s [-v] <IP>/<Mask>\n\n"
57 "Examples: %s -v 195.170.70.72/25\n"
58 " %s 195.170.70.72 255.255.255.128\n\n",
59 argv
[0],argv
[0],argv
[0],argv
[0]);
65 bc
[c
]=nw
[c
]|(255&~nm
[c
]);
69 printf("Network: %d.%d.%d.%d / %d\n",
70 nw
[0],nw
[1],nw
[2],nw
[3],nmbits
);
71 printf("Netmask: %d.%d.%d.%d\n",
72 nm
[0],nm
[1],nm
[2],nm
[3]);
73 printf("Broadcast: %d.%d.%d.%d\n",
74 bc
[0],bc
[1],bc
[2],bc
[3]);
76 printf("%d.%d.%d.%d %d.%d.%d.%d\n",nw
[0],nw
[1],
77 nw
[2],nw
[3],bc
[0],bc
[1],bc
[2],bc
[3]);