@@ -146,7 +146,7 @@ var usagetype_position = [26]uint8{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
146146var addresstype_position = [26 ]uint8 {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 21 }
147147var category_position = [26 ]uint8 {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 22 }
148148
149- const api_version string = "9.5.0 "
149+ const api_version string = "9.5.1 "
150150
151151var max_ipv4_range = uint128 .From64 (4294967295 )
152152var max_ipv6_range = uint128 .From64 (0 )
@@ -188,6 +188,12 @@ const missing_file string = "Invalid database file."
188188const not_supported string = "This parameter is unavailable for selected data file. Please upgrade the data file."
189189const invalid_bin string = "Incorrect IP2Location BIN file format. Please make sure that you are using the latest IP2Location BIN file."
190190
191+ func reverseBytes (s []byte ) {
192+ for i , j := 0 , len (s )- 1 ; i < j ; i , j = i + 1 , j - 1 {
193+ s [i ], s [j ] = s [j ], s [i ]
194+ }
195+ }
196+
191197// get IP type and calculate IP number; calculates index too if exists
192198func (d * DB ) checkip (ip string ) (iptype uint32 , ipnum uint128.Uint128 , ipindex uint32 ) {
193199 iptype = 0
@@ -207,7 +213,8 @@ func (d *DB) checkip(ip string) (iptype uint32, ipnum uint128.Uint128, ipindex u
207213
208214 if v6 != nil {
209215 iptype = 6
210- ipnum .PutBytes (v6 )
216+ reverseBytes (v6 )
217+ ipnum = uint128 .FromBytes (v6 )
211218
212219 if ipnum .Cmp (from_v4mapped ) >= 0 && ipnum .Cmp (to_v4mapped ) <= 0 {
213220 // ipv4-mapped ipv6 should treat as ipv4 and read ipv4 data section
@@ -297,10 +304,10 @@ func (d *DB) readuint128_row(row []byte, pos uint32) uint128.Uint128 {
297304 data := row [pos : pos + 16 ]
298305
299306 // little endian to big endian
300- for i , j := 0 , len (data )- 1 ; i < j ; i , j = i + 1 , j - 1 {
301- data [i ], data [j ] = data [j ], data [i ]
302- }
303- retval . PutBytes (data )
307+ // for i, j := 0, len(data)-1; i < j; i, j = i+1, j-1 {
308+ // data[i], data[j] = data[j], data[i]
309+ // }
310+ retval = uint128 . FromBytes (data )
304311 return retval
305312}
306313
@@ -315,10 +322,10 @@ func (d *DB) readuint128(pos uint32) (uint128.Uint128, error) {
315322 }
316323
317324 // little endian to big endian
318- for i , j := 0 , len (data )- 1 ; i < j ; i , j = i + 1 , j - 1 {
319- data [i ], data [j ] = data [j ], data [i ]
320- }
321- retval . PutBytes (data )
325+ // for i, j := 0, len(data)-1; i < j; i, j = i+1, j-1 {
326+ // data[i], data[j] = data[j], data[i]
327+ // }
328+ retval = uint128 . FromBytes (data )
322329 return retval , nil
323330}
324331
0 commit comments