@@ -89,7 +89,6 @@ local from_6to4 = bn("42545680458834377588178886921629466624")
8989local to_6to4 = bn (" 42550872755692912415807417417958686719" )
9090local from_teredo = bn (" 42540488161975842760550356425300246528" )
9191local to_teredo = bn (" 42540488241204005274814694018844196863" )
92- local last_32bits = bn (4294967295 )
9392
9493local country_position = {2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 }
9594local region_position = {0 , 0 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 }
@@ -111,7 +110,7 @@ local mobilebrand_position = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
111110local elevation_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 11 , 19 , 0 , 19 }
112111local usagetype_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 12 , 20 }
113112
114- local api_version = " 8.3.0 "
113+ local api_version = " 8.3.1 "
115114
116115local modes = {
117116 countryshort = 0x00001 ,
@@ -449,6 +448,12 @@ function ip2location:checkip(ip)
449448 end
450449 if chunks [hextets ] == " " then chunks [hextets ] = " 0" end
451450 end
451+
452+ -- DEBUGGING CODE
453+ -- for key, value in pairs(chunks)
454+ -- do
455+ -- print(key, " -- " , value);
456+ -- end
452457
453458 -- only support full IPv6 format for now
454459 if # chunks == 8 then
@@ -462,20 +467,32 @@ function ip2location:checkip(ip)
462467
463468 local override = 0
464469
470+ -- DEBUGGING
471+ -- print("IPNUM BEFORE: " .. ipnum)
472+
465473 -- special cases which should convert to equivalent IPv4
466474 if ipnum >= from_v4mapped and ipnum <= to_v4mapped then -- ipv4-mapped ipv6
475+ -- print("IPv4-mapped") -- DEBUGGING
467476 override = 1
468477 ipnum = ipnum - from_v4mapped
469478 elseif ipnum >= from_6to4 and ipnum <= to_6to4 then -- 6to4
479+ -- print("6to4") -- DEBUGGING
470480 override = 1
471481 ipnum = ipnum >> 80
472- ipnum = ipnum & last_32bits
482+ ipnum2 = ipnum :asnumber () & 0xffffffff
483+ ipnum = bn (ipnum2 ) -- convert back to bn
473484 elseif ipnum >= from_teredo and ipnum <= to_teredo then -- Teredo
485+ -- print("Teredo") -- DEBUGGING
474486 override = 1
475487 ipnum = ~ipnum
476- ipnum = ipnum & last_32bits
488+ ipnum2 = ipnum :asnumber () & 0xffffffff
489+ -- print("ipnum2: " .. ipnum2) -- DEBUGGING
490+ ipnum = bn (ipnum2 ) -- convert back to bn
477491 end
478492
493+ -- DEBUGGING
494+ -- print("IPNUM AFTER: " .. ipnum)
495+
479496 local ipindex = 0 ;
480497 if override == 1 then
481498 if self .ipv4indexbaseaddr > 0 then
0 commit comments