Skip to content

Commit

Permalink
Sock5 proxy: Add support for IPV4 connection method
Browse files Browse the repository at this point in the history
  • Loading branch information
Romain GÉRARD committed Jun 5, 2018
1 parent 8dc4fad commit 2b786bd
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/Socks5.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2b786bd

Please sign in to comment.