1- const ip = exports ;
2- const { Buffer } = require ( 'buffer' ) ;
3- const os = require ( 'os' ) ;
1+ var ip = exports ;
2+ var { Buffer } = require ( 'buffer' ) ;
3+ var os = require ( 'os' ) ;
44
55ip . toBuffer = function ( ip , buff , offset ) {
66 offset = ~ ~ offset ;
77
8- let result ;
8+ var result ;
99
1010 if ( this . isV4Format ( ip ) ) {
1111 result = buff || new Buffer ( offset + 4 ) ;
1212 ip . split ( / \. / g) . map ( ( byte ) => {
1313 result [ offset ++ ] = parseInt ( byte , 10 ) & 0xff ;
1414 } ) ;
1515 } else if ( this . isV6Format ( ip ) ) {
16- const sections = ip . split ( ':' , 8 ) ;
16+ var sections = ip . split ( ':' , 8 ) ;
1717
18- let i ;
18+ var i ;
1919 for ( i = 0 ; i < sections . length ; i ++ ) {
20- const isv4 = this . isV4Format ( sections [ i ] ) ;
21- let v4Buffer ;
20+ var isv4 = this . isV4Format ( sections [ i ] ) ;
21+ var v4Buffer ;
2222
2323 if ( isv4 ) {
2424 v4Buffer = this . toBuffer ( sections [ i ] ) ;
@@ -36,16 +36,16 @@ ip.toBuffer = function (ip, buff, offset) {
3636 while ( sections . length < 8 ) sections . push ( '0' ) ;
3737 } else if ( sections . length < 8 ) {
3838 for ( i = 0 ; i < sections . length && sections [ i ] !== '' ; i ++ ) ;
39- const argv = [ i , 1 ] ;
39+ var argv = [ i , 1 ] ;
4040 for ( i = 9 - sections . length ; i > 0 ; i -- ) {
4141 argv . push ( '0' ) ;
4242 }
43- sections . splice ( ... argv ) ;
43+ sections . splice . apply ( sections , argv ) ;
4444 }
4545
4646 result = buff || new Buffer ( offset + 16 ) ;
4747 for ( i = 0 ; i < sections . length ; i ++ ) {
48- const word = parseInt ( sections [ i ] , 16 ) ;
48+ var word = parseInt ( sections [ i ] , 16 ) ;
4949 result [ offset ++ ] = ( word >> 8 ) & 0xff ;
5050 result [ offset ++ ] = word & 0xff ;
5151 }
@@ -62,16 +62,17 @@ ip.toString = function (buff, offset, length) {
6262 offset = ~ ~ offset ;
6363 length = length || ( buff . length - offset ) ;
6464
65- let result = [ ] ;
65+ var result = [ ] ;
66+ var i ;
6667 if ( length === 4 ) {
6768 // IPv4
68- for ( let i = 0 ; i < length ; i ++ ) {
69+ for ( i = 0 ; i < length ; i ++ ) {
6970 result . push ( buff [ offset + i ] ) ;
7071 }
7172 result = result . join ( '.' ) ;
7273 } else if ( length === 16 ) {
7374 // IPv6
74- for ( let i = 0 ; i < length ; i += 2 ) {
75+ for ( i = 0 ; i < length ; i += 2 ) {
7576 result . push ( buff . readUInt16BE ( offset + i ) . toString ( 16 ) ) ;
7677 }
7778 result = result . join ( ':' ) ;
@@ -82,8 +83,8 @@ ip.toString = function (buff, offset, length) {
8283 return result ;
8384} ;
8485
85- const ipv4Regex = / ^ ( \d { 1 , 3 } \. ) { 3 , 3 } \d { 1 , 3 } $ / ;
86- const ipv6Regex = / ^ ( : : ) ? ( ( ( \d { 1 , 3 } \. ) { 3 } ( \d { 1 , 3 } ) { 1 } ) ? ( [ 0 - 9 a - f ] ) { 0 , 4 } : { 0 , 2 } ) { 1 , 8 } ( : : ) ? $ / i;
86+ var ipv4Regex = / ^ ( \d { 1 , 3 } \. ) { 3 , 3 } \d { 1 , 3 } $ / ;
87+ var ipv6Regex = / ^ ( : : ) ? ( ( ( \d { 1 , 3 } \. ) { 3 } ( \d { 1 , 3 } ) { 1 } ) ? ( [ 0 - 9 a - f ] ) { 0 , 4 } : { 0 , 2 } ) { 1 , 8 } ( : : ) ? $ / i;
8788
8889ip . isV4Format = function ( ip ) {
8990 return ipv4Regex . test ( ip ) ;
@@ -110,14 +111,14 @@ ip.fromPrefixLen = function (prefixlen, family) {
110111 family = _normalizeFamily ( family ) ;
111112 }
112113
113- let len = 4 ;
114+ var len = 4 ;
114115 if ( family === 'ipv6' ) {
115116 len = 16 ;
116117 }
117- const buff = new Buffer ( len ) ;
118+ var buff = new Buffer ( len ) ;
118119
119- for ( let i = 0 , n = buff . length ; i < n ; ++ i ) {
120- let bits = 8 ;
120+ for ( var i = 0 , n = buff . length ; i < n ; ++ i ) {
121+ var bits = 8 ;
121122 if ( prefixlen < 8 ) {
122123 bits = prefixlen ;
123124 }
@@ -133,10 +134,10 @@ ip.mask = function (addr, mask) {
133134 addr = ip . toBuffer ( addr ) ;
134135 mask = ip . toBuffer ( mask ) ;
135136
136- const result = new Buffer ( Math . max ( addr . length , mask . length ) ) ;
137+ var result = new Buffer ( Math . max ( addr . length , mask . length ) ) ;
137138
138139 // Same protocol - do bitwise and
139- let i ;
140+ var i ;
140141 if ( addr . length === mask . length ) {
141142 for ( i = 0 ; i < addr . length ; i ++ ) {
142143 result [ i ] = addr [ i ] & mask [ i ] ;
@@ -169,38 +170,38 @@ ip.mask = function (addr, mask) {
169170} ;
170171
171172ip . cidr = function ( cidrString ) {
172- const cidrParts = cidrString . split ( '/' ) ;
173+ var cidrParts = cidrString . split ( '/' ) ;
173174
174- const addr = cidrParts [ 0 ] ;
175+ var addr = cidrParts [ 0 ] ;
175176 if ( cidrParts . length !== 2 ) {
176177 throw new Error ( `invalid CIDR subnet: ${ addr } ` ) ;
177178 }
178179
179- const mask = ip . fromPrefixLen ( parseInt ( cidrParts [ 1 ] , 10 ) ) ;
180+ var mask = ip . fromPrefixLen ( parseInt ( cidrParts [ 1 ] , 10 ) ) ;
180181
181182 return ip . mask ( addr , mask ) ;
182183} ;
183184
184185ip . subnet = function ( addr , mask ) {
185- const networkAddress = ip . toLong ( ip . mask ( addr , mask ) ) ;
186+ var networkAddress = ip . toLong ( ip . mask ( addr , mask ) ) ;
186187
187188 // Calculate the mask's length.
188- const maskBuffer = ip . toBuffer ( mask ) ;
189- let maskLength = 0 ;
189+ var maskBuffer = ip . toBuffer ( mask ) ;
190+ var maskLength = 0 ;
190191
191- for ( let i = 0 ; i < maskBuffer . length ; i ++ ) {
192+ for ( var i = 0 ; i < maskBuffer . length ; i ++ ) {
192193 if ( maskBuffer [ i ] === 0xff ) {
193194 maskLength += 8 ;
194195 } else {
195- let octet = maskBuffer [ i ] & 0xff ;
196+ var octet = maskBuffer [ i ] & 0xff ;
196197 while ( octet ) {
197198 octet = ( octet << 1 ) & 0xff ;
198199 maskLength ++ ;
199200 }
200201 }
201202 }
202203
203- const numberOfAddresses = 2 ** ( 32 - maskLength ) ;
204+ var numberOfAddresses = 2 ** ( 32 - maskLength ) ;
204205
205206 return {
206207 networkAddress : ip . fromLong ( networkAddress ) ,
@@ -223,82 +224,86 @@ ip.subnet = function (addr, mask) {
223224} ;
224225
225226ip . cidrSubnet = function ( cidrString ) {
226- const cidrParts = cidrString . split ( '/' ) ;
227+ var cidrParts = cidrString . split ( '/' ) ;
227228
228- const addr = cidrParts [ 0 ] ;
229+ var addr = cidrParts [ 0 ] ;
229230 if ( cidrParts . length !== 2 ) {
230231 throw new Error ( `invalid CIDR subnet: ${ addr } ` ) ;
231232 }
232233
233- const mask = ip . fromPrefixLen ( parseInt ( cidrParts [ 1 ] , 10 ) ) ;
234+ var mask = ip . fromPrefixLen ( parseInt ( cidrParts [ 1 ] , 10 ) ) ;
234235
235236 return ip . subnet ( addr , mask ) ;
236237} ;
237238
238239ip . not = function ( addr ) {
239- const buff = ip . toBuffer ( addr ) ;
240- for ( let i = 0 ; i < buff . length ; i ++ ) {
240+ var buff = ip . toBuffer ( addr ) ;
241+ for ( var i = 0 ; i < buff . length ; i ++ ) {
241242 buff [ i ] = 0xff ^ buff [ i ] ;
242243 }
243244 return ip . toString ( buff ) ;
244245} ;
245246
246247ip . or = function ( a , b ) {
248+ var i ;
249+
247250 a = ip . toBuffer ( a ) ;
248251 b = ip . toBuffer ( b ) ;
249252
250253 // same protocol
251254 if ( a . length === b . length ) {
252- for ( let i = 0 ; i < a . length ; ++ i ) {
255+ for ( i = 0 ; i < a . length ; ++ i ) {
253256 a [ i ] |= b [ i ] ;
254257 }
255258 return ip . toString ( a ) ;
256259
257260 // mixed protocols
258261 }
259- let buff = a ;
260- let other = b ;
262+ var buff = a ;
263+ var other = b ;
261264 if ( b . length > a . length ) {
262265 buff = b ;
263266 other = a ;
264267 }
265268
266- const offset = buff . length - other . length ;
267- for ( let i = offset ; i < buff . length ; ++ i ) {
269+ var offset = buff . length - other . length ;
270+ for ( i = offset ; i < buff . length ; ++ i ) {
268271 buff [ i ] |= other [ i - offset ] ;
269272 }
270273
271274 return ip . toString ( buff ) ;
272275} ;
273276
274277ip . isEqual = function ( a , b ) {
278+ var i ;
279+
275280 a = ip . toBuffer ( a ) ;
276281 b = ip . toBuffer ( b ) ;
277282
278283 // Same protocol
279284 if ( a . length === b . length ) {
280- for ( let i = 0 ; i < a . length ; i ++ ) {
285+ for ( i = 0 ; i < a . length ; i ++ ) {
281286 if ( a [ i ] !== b [ i ] ) return false ;
282287 }
283288 return true ;
284289 }
285290
286291 // Swap
287292 if ( b . length === 4 ) {
288- const t = b ;
293+ var t = b ;
289294 b = a ;
290295 a = t ;
291296 }
292297
293298 // a - IPv4, b - IPv6
294- for ( let i = 0 ; i < 10 ; i ++ ) {
299+ for ( i = 0 ; i < 10 ; i ++ ) {
295300 if ( b [ i ] !== 0 ) return false ;
296301 }
297302
298- const word = b . readUInt16BE ( 10 ) ;
303+ var word = b . readUInt16BE ( 10 ) ;
299304 if ( word !== 0 && word !== 0xffff ) return false ;
300305
301- for ( let i = 0 ; i < 4 ; i ++ ) {
306+ for ( i = 0 ; i < 4 ; i ++ ) {
302307 if ( a [ i ] !== b [ i + 12 ] ) return false ;
303308 }
304309
@@ -360,7 +365,7 @@ ip.loopback = function (family) {
360365// * undefined: First address with `ipv4` or loopback address `127.0.0.1`.
361366//
362367ip . address = function ( name , family ) {
363- const interfaces = os . networkInterfaces ( ) ;
368+ var interfaces = os . networkInterfaces ( ) ;
364369
365370 //
366371 // Default to `ipv4`
@@ -372,8 +377,8 @@ ip.address = function (name, family) {
372377 // return the address.
373378 //
374379 if ( name && name !== 'private' && name !== 'public' ) {
375- const res = interfaces [ name ] . filter ( ( details ) => {
376- const itemFamily = _normalizeFamily ( details . family ) ;
380+ var res = interfaces [ name ] . filter ( ( details ) => {
381+ var itemFamily = _normalizeFamily ( details . family ) ;
377382 return itemFamily === family ;
378383 } ) ;
379384 if ( res . length === 0 ) {
@@ -382,12 +387,12 @@ ip.address = function (name, family) {
382387 return res [ 0 ] . address ;
383388 }
384389
385- const all = Object . keys ( interfaces ) . map ( ( nic ) => {
390+ var all = Object . keys ( interfaces ) . map ( ( nic ) => {
386391 //
387392 // Note: name will only be `public` or `private`
388393 // when this is called.
389394 //
390- const addresses = interfaces [ nic ] . filter ( ( details ) => {
395+ var addresses = interfaces [ nic ] . filter ( ( details ) => {
391396 details . family = _normalizeFamily ( details . family ) ;
392397 if ( details . family !== family || ip . isLoopback ( details . address ) ) {
393398 return false ;
@@ -406,7 +411,7 @@ ip.address = function (name, family) {
406411} ;
407412
408413ip . toLong = function ( ip ) {
409- let ipl = 0 ;
414+ var ipl = 0 ;
410415 ip . split ( '.' ) . forEach ( ( octet ) => {
411416 ipl <<= 8 ;
412417 ipl += parseInt ( octet ) ;
0 commit comments