@@ -72,26 +72,51 @@ const ubyte[25] MOBILEBRAND_POSITION = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
7272const ubyte [25 ] ELEVATION_POSITION = [0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 11 , 19 , 0 , 19 ];
7373const ubyte [25 ] USAGETYPE_POSITION = [0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 12 , 20 ];
7474
75- protected const string API_VERSION = " 8.0.5" ;
76-
77- protected const BigInt MAX_IPV4_RANGE = BigInt(" 4294967295" );
75+ protected const string API_VERSION = " 8.1.0" ;
7876
7977version (X86 )
8078{
81-
8279 // CTFE of BigInt only supported since phobos 2.079
8380 static if (__VERSION__ < 2079 )
8481 {
82+ protected const BigInt MAX_IPV4_RANGE ;
8583 protected const BigInt MAX_IPV6_RANGE ;
84+ protected const BigInt FROM_6TO4 ;
85+ protected const BigInt TO_6TO4 ;
86+ protected const BigInt FROM_TEREDO ;
87+ protected const BigInt TO_TEREDO ;
88+ protected const BigInt LAST_32BITS ;
8689
87- static this ()
88- {
89- MAX_IPV6_RANGE = BigInt(" 340282366920938463463374607431768211455" );
90- }
90+ static this ()
91+ {
92+ MAX_IPV4_RANGE = BigInt(" 4294967295" );
93+ MAX_IPV6_RANGE = BigInt(" 340282366920938463463374607431768211455" );
94+ FROM_6TO4 = BigInt(" 42545680458834377588178886921629466624" );
95+ TO_6TO4 = BigInt(" 42550872755692912415807417417958686719" );
96+ FROM_TEREDO = BigInt(" 42540488161975842760550356425300246528" );
97+ TO_TEREDO = BigInt(" 42540488241204005274814694018844196863" );
98+ LAST_32BITS = BigInt(" 4294967295" );
99+ }
100+ }
101+ else {
102+ protected const MAX_IPV4_RANGE = BigInt(" 4294967295" );
103+ protected const MAX_IPV6_RANGE = BigInt(" 340282366920938463463374607431768211455" );
104+ protected const FROM_6TO4 = BigInt(" 42545680458834377588178886921629466624" );
105+ protected const TO_6TO4 = BigInt(" 42550872755692912415807417417958686719" );
106+ protected const FROM_TEREDO = BigInt(" 42540488161975842760550356425300246528" );
107+ protected const TO_TEREDO = BigInt(" 42540488241204005274814694018844196863" );
108+ protected const LAST_32BITS = BigInt(" 4294967295" );
91109 }
92- else protected const MAX_IPV6_RANGE = BigInt(" 340282366920938463463374607431768211455" );
93110}
94- else protected const BigInt MAX_IPV6_RANGE = BigInt(" 340282366920938463463374607431768211455" );
111+ else {
112+ protected const BigInt MAX_IPV4_RANGE = BigInt(" 4294967295" );
113+ protected const BigInt MAX_IPV6_RANGE = BigInt(" 340282366920938463463374607431768211455" );
114+ protected const BigInt FROM_6TO4 = BigInt(" 42545680458834377588178886921629466624" );
115+ protected const BigInt TO_6TO4 = BigInt(" 42550872755692912415807417417958686719" );
116+ protected const BigInt FROM_TEREDO = BigInt(" 42540488161975842760550356425300246528" );
117+ protected const BigInt TO_TEREDO = BigInt(" 42540488241204005274814694018844196863" );
118+ protected const BigInt LAST_32BITS = BigInt(" 4294967295" );
119+ }
95120
96121protected const uint COUNTRYSHORT = 0x00001 ;
97122protected const uint COUNTRYLONG = 0x00002 ;
@@ -330,6 +355,26 @@ class ip2location {
330355 ipdata.ipindex = ((ipno2 >> 16 ) << 3 ) + meta.ipv4indexbaseaddr;
331356 }
332357 }
358+ else if (ipdata.ipnum >= FROM_6TO4 && ipdata.ipnum <= TO_6TO4 ) {
359+ // 6to4 so need to remap to ipv4
360+ ipdata.iptype = 4 ;
361+ ipdata.ipnum = ipdata.ipnum >> 80 ;
362+ ipdata.ipnum = ipdata.ipnum & LAST_32BITS ;
363+ uint ipno2 = to! uint (ipdata.ipnum);
364+ if (meta.ipv4indexbaseaddr > 0 ) {
365+ ipdata.ipindex = ((ipno2 >> 16 ) << 3 ) + meta.ipv4indexbaseaddr;
366+ }
367+ }
368+ else if (ipdata.ipnum >= FROM_TEREDO && ipdata.ipnum <= TO_TEREDO ) {
369+ // Teredo so need to remap to ipv4
370+ ipdata.iptype = 4 ;
371+ ipdata.ipnum = ~ ipdata.ipnum; // bitwise NOT
372+ ipdata.ipnum = ipdata.ipnum & LAST_32BITS ;
373+ uint ipno2 = to! uint (ipdata.ipnum);
374+ if (meta.ipv4indexbaseaddr > 0 ) {
375+ ipdata.ipindex = ((ipno2 >> 16 ) << 3 ) + meta.ipv4indexbaseaddr;
376+ }
377+ }
333378 }
334379 }
335380 catch (Exception e) {
0 commit comments