(address, netmask, family)
| 812 | } |
| 813 | |
| 814 | function 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 | |
| 859 | const handleTypes = ['TCP', 'TTY', 'UDP', 'FILE', 'PIPE', 'UNKNOWN']; |
| 860 | function guessHandleType(fd) { |
no test coverage detected
searching dependent graphs…