MCPcopy Index your code
hub / github.com/nodejs/node / getCIDR

Function getCIDR

lib/internal/util.js:814–857  ·  view source on GitHub ↗
(address, netmask, family)

Source from the content-addressed store, hash-verified

812}
813
814function getCIDR(address, netmask, family) {
815 let ones = 0;
816 let split = '.';
817 let range = 10;
818 let groupLength = 8;
819 let hasZeros = false;
820 let lastPos = 0;
821
822 if (family === 'IPv6') {
823 split = ':';
824 range = 16;
825 groupLength = 16;
826 }
827
828 for (let i = 0; i < netmask.length; i++) {
829 if (netmask[i] !== split) {
830 if (i + 1 < netmask.length) {
831 continue;
832 }
833 i++;
834 }
835 const part = StringPrototypeSlice(netmask, lastPos, i);
836 lastPos = i + 1;
837 if (part !== '') {
838 if (hasZeros) {
839 if (part !== '0') {
840 return null;
841 }
842 } else {
843 const binary = NumberParseInt(part, range);
844 const binaryOnes = countBinaryOnes(binary);
845 ones += binaryOnes;
846 if (binaryOnes !== groupLength) {
847 if (StringPrototypeIncludes(binary.toString(2), '01')) {
848 return null;
849 }
850 hasZeros = true;
851 }
852 }
853 }
854 }
855
856 return `${address}/${ones}`;
857}
858
859const handleTypes = ['TCP', 'TTY', 'UDP', 'FILE', 'PIPE', 'UNKNOWN'];
860function guessHandleType(fd) {

Callers 2

networkInterfacesFunction · 0.85

Calls 2

countBinaryOnesFunction · 0.85
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…