MCPcopy
hub / github.com/panva/node-oidc-provider / ipv4ToInt

Function ipv4ToInt

lib/helpers/fetch_request.js:31–47  ·  view source on GitHub ↗
(ip)

Source from the content-addressed store, hash-verified

29];
30
31function ipv4ToInt(ip) {
32 // Parses an IPv4 dotted-decimal string into an unsigned 32-bit integer
33 // without allocating a split('.') array. Walks the string character by
34 // character, accumulating each decimal octet then shifting it into the
35 // result. The final >>> 0 ensures an unsigned value.
36 let result = 0;
37 let octet = 0;
38 for (let i = 0; i <= ip.length; i++) {
39 if (i === ip.length || ip.charCodeAt(i) === 46 /* '.' */) {
40 result = result * 256 + octet; // * 256 is equivalent to << 8
41 octet = 0;
42 } else {
43 octet = octet * 10 + ip.charCodeAt(i) - 48; // 48 is '0'.charCodeAt(0)
44 }
45 }
46 return result >>> 0;
47}
48
49function expandIPv6(address) {
50 // Expands a potentially shortened IPv6 address into a 32-char lowercase

Callers 2

isSpecialUseIPv4Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected