File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed
Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change 1- import ipLib from 'ip'
21import common from '../common.js'
32import { equal } from 'uint8-util'
43
4+ function ipToString ( buff , offset , length ) {
5+ offset = ~ ~ offset
6+ length = length || ( buff . length - offset )
7+
8+ let result = [ ]
9+ if ( length === 4 ) {
10+ // IPv4
11+ for ( let i = 0 ; i < length ; i ++ ) {
12+ result . push ( buff [ offset + i ] )
13+ }
14+ result = result . join ( '.' )
15+ } else if ( length === 16 ) {
16+ // IPv6
17+ for ( let i = 0 ; i < length ; i += 2 ) {
18+ result . push ( buff . readUInt16BE ( offset + i ) . toString ( 16 ) )
19+ }
20+ result = result . join ( ':' )
21+ result = result . replace ( / ( ^ | : ) 0 ( : 0 ) * : 0 ( : | $ ) / , '$1::$3' )
22+ result = result . replace ( / : { 3 , 4 } / , '::' )
23+ }
24+
25+ return result
26+ } ;
27+
528export default function ( msg , rinfo ) {
629 if ( msg . length < 16 ) throw new Error ( 'received packet is too short' )
730
@@ -30,7 +53,7 @@ export default function (msg, rinfo) {
3053
3154 const ip = msg . readUInt32BE ( 84 ) // optional
3255 params . ip = ip
33- ? ipLib . toString ( ip )
56+ ? ipToString ( ip )
3457 : rinfo . address
3558
3659 params . key = msg . readUInt32BE ( 88 ) // Optional: unique random key from client
Original file line number Diff line number Diff line change 3535 "compact2string" : " ^1.4.1" ,
3636 "cross-fetch-ponyfill" : " ^1.0.3" ,
3737 "debug" : " ^4.3.4" ,
38- "ip" : " ^2.0.1" ,
3938 "lru" : " ^3.1.0" ,
4039 "minimist" : " ^1.2.8" ,
4140 "once" : " ^1.4.0" ,
You can’t perform that action at this time.
0 commit comments