Fix handling of DHCP IP ranges for big LAN subnets
[tomato.git] / release / src / router / www / interfaces.js
blobaba639aa4ecf10b4b9646cd805e4bd3cd638863d
1 MAX_BRIDGE_ID = 3;
2 MAX_PORT_ID = 4;
3 MAX_VLAN_ID = 15;
5 function h_countbitsfromleft(num) {
6         if (num == 255 ){
7                 return(8);
8         }
9         var i = 0;
10         var bitpat=0xff00; 
11         while (i < 8){
12                 if (num == (bitpat & 0xff)){
13                         return(i);
14                 }
15                 bitpat=bitpat >> 1;
16                 i++;
17         }
18         return(Number.NaN);
21 function numberOfBitsOnNetMask(netmask) {
22         var total = 0;
23         var t = netmask.split('.');
24         for (var i = 0; i<= 3 ; i++) {
25                 total += h_countbitsfromleft(t[i]);
26         }
27         return total;
30 function getNetworkAddress(ipaddress, netmask) {
31         return fixIP(ntoa(aton(ipaddress) & aton(netmask)));
34 function getBroadcastAddress(network, netmask) {
35         return fixIP(ntoa(aton(network) ^ (~ aton(netmask))));
38 function getAddress(ipaddress, network) {
39         return fixIP(ntoa( (aton(network)) + (aton(ipaddress)) ));