Skip to content

Commit 8a3491b

Browse files
Added support for 6to4 and Teredo.
1 parent 6d93b0b commit 8a3491b

3 files changed

Lines changed: 27 additions & 12 deletions

File tree

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Revision history for ip2proxy
22

3+
## 2.1.0 -- 2019-07-22
4+
5+
* Added support for 6to4 and Teredo.
6+
37
## 2.0.0 -- 2019-05-27
48

59
* Added support for PX5 to PX8 packages.

IP2Proxy.hs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ getMeta = do
9999
The 'getModuleVersion' function returns a string containing the module version.
100100
-}
101101
getModuleVersion :: String
102-
getModuleVersion = "2.0.0"
102+
getModuleVersion = "2.1.0"
103103

104104
{-|
105105
The 'getPackageVersion' function returns a string containing the package version.
@@ -435,21 +435,32 @@ isProxy myfile meta myip = do
435435
doQuery :: String -> Meta -> String -> Int -> IO IP2ProxyRecord
436436
doQuery myfile meta myip mode = do
437437
contents <- BS.readFile myfile
438-
let from = 281470681743360
439-
let to = 281474976710655
440-
let fromA = 0
441-
let toA = 4294967295
438+
let fromV4Mapped = 281470681743360
439+
let toV4Mapped = 281474976710655
440+
let fromV4Compatible = 0
441+
let toV4Compatible = 4294967295
442+
let from6To4 = 42545680458834377588178886921629466624
443+
let to6To4 = 42550872755692912415807417417958686719
444+
let fromTeredo = 42540488161975842760550356425300246528
445+
let toTeredo = 42540488241204005274814694018844196863
446+
let last32Bits = 4294967295
442447

443448
ipnum <- tryfirst myip
444449
if ipnum == -1
445450
then do
446451
let x = "INVALID IP ADDRESS"
447452
return $ IP2ProxyRecord x x x x x x x x x x x (-1)
448-
else if ipnum >= from && ipnum <= to
453+
else if ipnum >= fromV4Mapped && ipnum <= toV4Mapped
449454
then do
450-
return $ search4 contents (ipnum - (toInteger from)) (databasetype meta) 0 (ipv4databasecount meta) (ipv4databaseaddr meta) (ipv4indexbaseaddr meta) (ipv4columnsize meta) mode
451-
else if ipnum >= fromA && ipnum <= toA
455+
return $ search4 contents (ipnum - (toInteger fromV4Mapped)) (databasetype meta) 0 (ipv4databasecount meta) (ipv4databaseaddr meta) (ipv4indexbaseaddr meta) (ipv4columnsize meta) mode
456+
else if ipnum >= from6To4 && ipnum <= to6To4
452457
then do
453-
return $ search4 contents ipnum (databasetype meta) 0 (ipv4databasecount meta) (ipv4databaseaddr meta) (ipv4indexbaseaddr meta) (ipv4columnsize meta) mode
454-
else do
455-
return $ search6 contents ipnum (databasetype meta) 0 (ipv6databasecount meta) (ipv6databaseaddr meta) (ipv6indexbaseaddr meta) (ipv6columnsize meta) mode
458+
return $ search4 contents ((ipnum `rotateR` 80) .&. last32Bits) (databasetype meta) 0 (ipv4databasecount meta) (ipv4databaseaddr meta) (ipv4indexbaseaddr meta) (ipv4columnsize meta) mode
459+
else if ipnum >= fromTeredo && ipnum <= toTeredo
460+
then do
461+
return $ search4 contents ((complement ipnum) .&. last32Bits) (databasetype meta) 0 (ipv4databasecount meta) (ipv4databaseaddr meta) (ipv4indexbaseaddr meta) (ipv4columnsize meta) mode
462+
else if ipnum >= fromV4Compatible && ipnum <= toV4Compatible
463+
then do
464+
return $ search4 contents ipnum (databasetype meta) 0 (ipv4databasecount meta) (ipv4databaseaddr meta) (ipv4indexbaseaddr meta) (ipv4columnsize meta) mode
465+
else do
466+
return $ search6 contents ipnum (databasetype meta) 0 (ipv6databasecount meta) (ipv6databaseaddr meta) (ipv6indexbaseaddr meta) (ipv6columnsize meta) mode

ip2proxy.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ name: ip2proxy
1010
-- PVP summary: +-+------- breaking API changes
1111
-- | | +----- non-breaking API additions
1212
-- | | | +--- code changes with no API change
13-
version: 2.0.0
13+
version: 2.1.0
1414

1515
-- A short (one-line) description of the package.
1616
synopsis: IP2Proxy Haskell package for proxy detection.

0 commit comments

Comments
 (0)