Sock5 proxy: Add support for IPV4 connection method

Former-commit-id: 2b786bdfca8f7c4f13be5d3f2fbffabb3bb6c1ff
Former-commit-id: 79521d28ef7ec78f037a39d345d0b7caa6a21aad [formerly 4f529c3bf32ec3d058f0437a4ed56cd530bb0380] [formerly 5fe75721d4197c31274853956429750a8a6bae34 [formerly b985c09e33290e80db92edd3a6688d56df463ab4 [formerly d19a7a5290bd4676d018052c1ba82ff0a2f7c53c] [formerly d19a7a5290bd4676d018052c1ba82ff0a2f7c53c [formerly d19a7a5290bd4676d018052c1ba82ff0a2f7c53c [formerly 2a811ddc94f163f29e7b13c5c0209edaa0ba94dd]]]]]
Former-commit-id: ac4e18a935137eac85d7a1fcb03aff223ce9a413 [formerly c6a4d21c51709b03cab6c6de9934188da49028e7]
Former-commit-id: 736cb733cf4083f0d6e98f4bd4315119b65ac994
Former-commit-id: 3639f8c1a181eed16f4d642745cbe19725834784
Former-commit-id: d0d2d9ea134579057a321900564f210e35e85a42
Former-commit-id: afc68a28fd773821f36742d9c561f1df8c43f66b [formerly 441a3c84970aba955d980519a74178e4dbe64ec1]
Former-commit-id: 08598a77acb35f6e71f6c5b8aabd905348ec9ea8
This commit is contained in:
Romain GÉRARD 2018-06-06 00:46:02 +02:00
parent 3dff11f99c
commit fe1c17bac1

View file

@ -128,13 +128,20 @@ instance Binary Request where
cmd <- get :: Get Command
_ <- getWord8 -- RESERVED
opCode <- fromIntegral <$> getWord8 -- DOMAINNAME
guard (opCode == 0x03)
opCode <- fromIntegral <$> getWord8 -- Addr type, we support only ipv4 and domainame
guard (opCode == 0x03 || opCode == 0x01) -- DOMAINNAME OR IPV4
host <- if opCode == 0x03
then do
length <- fromIntegral <$> getWord8
host <- either (const T.empty) id . E.decodeUtf8' <$> replicateM length getWord8
return host
else do
ipv4 <- replicateM 4 getWord8 :: Get [Word8]
let ipv4Str = T.intercalate "." $ fmap (tshow . fromEnum) ipv4
return ipv4Str
length <- fromIntegral <$> getWord8
host <- either (const T.empty) id . E.decodeUtf8' <$> replicateM length getWord8
guard (not $ null host)
port <- fromIntegral <$> getWord16be
return Request