Skip to content

Commit

Permalink
Fixed issue with IPv6 IP when using IPv4 BIN
Browse files Browse the repository at this point in the history
  • Loading branch information
ip2location committed Dec 3, 2024
1 parent c0c4617 commit e9dd727
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ip2location.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ var district_position = [27]uint8{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
var asn_position = [27]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, 0, 24}
var as_position = [27]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, 0, 25}

const api_version string = "9.7.0"
const api_version string = "9.7.1"

var max_ipv4_range = uint128.From64(4294967295)
var max_ipv6_range = uint128.From64(0)
Expand Down Expand Up @@ -203,6 +203,7 @@ const invalid_address string = "Invalid IP address."
const missing_file string = "Invalid database file."
const not_supported string = "This parameter is unavailable for selected data file. Please upgrade the data file."
const invalid_bin string = "Incorrect IP2Location BIN file format. Please make sure that you are using the latest IP2Location BIN file."
const ipv6_not_supported string = "IPv6 address missing in IPv4 BIN."

func reverseBytes(s []byte) {
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
Expand Down Expand Up @@ -950,6 +951,10 @@ func (d *DB) query(ipaddress string, mode uint32) (IP2Locationrecord, error) {
maxip = max_ipv4_range
colsize = d.meta.ipv4columnsize
} else {
if d.meta.ipv6databasecount == 0 {
x = loadmessage(ipv6_not_supported)
return x, nil
}
firstcol = 16 // 16 bytes for ip from
baseaddr = d.meta.ipv6databaseaddr
high = d.meta.ipv6databasecount
Expand Down

0 comments on commit e9dd727

Please sign in to comment.