Network.Socks5

socks-0.5.5: Socks proxy (version 5) implementation.

License | BSD-style
Maintainer | Vincent Hanquez <vincent@snarc.org>
Stability | experimental
Portability | unknown
Safe Haskell | None
Language | Haskell98

Network.Socks5

Contents

- Types
- Configuration
- Methods
- Variants

Description

This is an implementation of SOCKS5 as defined in RFC 1928

In Wikipedia's words:

SOCKet Secure (SOCKS) is an Internet protocol that routes network packets between a client and server through a proxy server. SOCKS5 additionally provides authentication so only authorized users may access a server. Practically, a SOCKS server will proxy TCP connections to an arbitrary IP address as well as providing a means for UDP packets to be forwarded.

BIND and UDP ASSOCIATE messages are not implemented. However main usage of SOCKS is covered in this implementation.

Synopsis

- data SocksAddress = SocksAddress !SocksHostAddress !PortNumber
- data SocksHostAddress
  - = SocksAddrIPV4 !HostAddress
  - | SocksAddrDomainName !ByteString
  - | SocksAddrIPV6 !HostAddress6
- data SocksReply
  - = SocksReplySuccess
  - | SocksReplyError SocksError
- data SocksError
  - = SocksErrorGeneralServerFailure
  - | SocksErrorConnectionNotAllowedByRule
  - | SocksErrorNetworkUnreachable
  - | SocksErrorHostUnreachable
  - | SocksErrorConnectionRefused
  - | SocksErrorTTLExpired
  - | SocksErrorCommandNotSupported
  - | SocksErrorAddrTypeNotSupported
  - | SocksErrorOther Word8
- data SocksConf = SocksConf {
  - socksServer :: SocksAddress
  - socksVersion :: SocksVersion
  }
- socksHost :: SocksConf -> SocksHostAddress
- socksPort :: SocksConf -> PortNumber
- defaultSocksConf :: String -> PortNumber -> SocksConf
- defaultSocksConfFromSockAddr :: SockAddr -> SocksConf
- socksConnectWithSocket :: Socket -> SocksConf -> SocksAddress -> IO (SocksHostAddress, PortNumber)
- socksConnect :: SocksConf -> SocksAddress -> IO (Socket, (SocksHostAddress, PortNumber))
- socksConnectAddr :: Socket -> SockAddr -> SockAddr -> IO ()
- socksConnectName :: Socket -> SockAddr -> String -> PortNumber -> IO ()
- socksConnectTo' :: String -> PortID -> String -> PortID -> IO Socket
- socksConnectTo :: String -> PortID -> String -> PortID -> IO Handle
- socksConnectWith :: SocksConf -> String -> PortID -> IO Socket

# Types

data SocksAddress #

Describe a Socket address on the SOCKS protocol

Constructors

SocksAddress !SocksHostAddress !PortNumber |

Instances

Eq SocksAddress # |
Methods (==) :: SocksAddress -> SocksAddress -> Bool # (/=) :: SocksAddress -> SocksAddress -> Bool #
Ord SocksAddress # |
Methods compare :: SocksAddress -> SocksAddress -> Ordering # (<) :: SocksAddress -> SocksAddress -> Bool # (<=) :: SocksAddress -> SocksAddress -> Bool # (>) :: SocksAddress -> SocksAddress -> Bool # (>=) :: SocksAddress -> SocksAddress -> Bool # max :: SocksAddress -> SocksAddress -> SocksAddress # min :: SocksAddress -> SocksAddress -> SocksAddress #
Show SocksAddress # |
Methods showsPrec :: Int -> SocksAddress -> ShowS # show :: SocksAddress -> String # showList :: [SocksAddress] -> ShowS #

data SocksHostAddress #

A Host address on the SOCKS protocol.

Constructors

SocksAddrIPV4 !HostAddress |
SocksAddrDomainName !ByteString |
SocksAddrIPV6 !HostAddress6 |

Instances

Eq SocksHostAddress # |
Methods (==) :: SocksHostAddress -> SocksHostAddress -> Bool # (/=) :: SocksHostAddress -> SocksHostAddress -> Bool #
Ord SocksHostAddress # |
Methods compare :: SocksHostAddress -> SocksHostAddress -> Ordering # (<) :: SocksHostAddress -> SocksHostAddress -> Bool # (<=) :: SocksHostAddress -> SocksHostAddress -> Bool # (>) :: SocksHostAddress -> SocksHostAddress -> Bool # (>=) :: SocksHostAddress -> SocksHostAddress -> Bool # max :: SocksHostAddress -> SocksHostAddress -> SocksHostAddress # min :: SocksHostAddress -> SocksHostAddress -> SocksHostAddress #
Show SocksHostAddress # |
Methods showsPrec :: Int -> SocksHostAddress -> ShowS # show :: SocksHostAddress -> String # showList :: [SocksHostAddress] -> ShowS #

data SocksReply #

Type of reply on the SOCKS protocol

Constructors

SocksReplySuccess |
SocksReplyError SocksError |

Instances

Enum SocksReply # |
Methods succ :: SocksReply -> SocksReply # pred :: SocksReply -> SocksReply # toEnum :: Int -> SocksReply # fromEnum :: SocksReply -> Int # enumFrom :: SocksReply -> [SocksReply] # enumFromThen :: SocksReply -> SocksReply -> [SocksReply] # enumFromTo :: SocksReply -> SocksReply -> [SocksReply] # enumFromThenTo :: SocksReply -> SocksReply -> SocksReply -> [SocksReply] #
Eq SocksReply # |
Methods (==) :: SocksReply -> SocksReply -> Bool # (/=) :: SocksReply -> SocksReply -> Bool #
Data SocksReply # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> SocksReply -> c SocksReply # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c SocksReply # toConstr :: SocksReply -> Constr # dataTypeOf :: SocksReply -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c SocksReply) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SocksReply) # gmapT :: (forall b. Data b => b -> b) -> SocksReply -> SocksReply # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SocksReply -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SocksReply -> r # gmapQ :: (forall d. Data d => d -> u) -> SocksReply -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> SocksReply -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> SocksReply -> m SocksReply # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> SocksReply -> m SocksReply # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> SocksReply -> m SocksReply #
Ord SocksReply # |
Methods compare :: SocksReply -> SocksReply -> Ordering # (<) :: SocksReply -> SocksReply -> Bool # (<=) :: SocksReply -> SocksReply -> Bool # (>) :: SocksReply -> SocksReply -> Bool # (>=) :: SocksReply -> SocksReply -> Bool # max :: SocksReply -> SocksReply -> SocksReply # min :: SocksReply -> SocksReply -> SocksReply #
Show SocksReply # |
Methods showsPrec :: Int -> SocksReply -> ShowS # show :: SocksReply -> String # showList :: [SocksReply] -> ShowS #

data SocksError #

SOCKS error that can be received or sent

Constructors

SocksErrorGeneralServerFailure |
SocksErrorConnectionNotAllowedByRule |
SocksErrorNetworkUnreachable |
SocksErrorHostUnreachable |
SocksErrorConnectionRefused |
SocksErrorTTLExpired |
SocksErrorCommandNotSupported |
SocksErrorAddrTypeNotSupported |
SocksErrorOther Word8 |

Instances

Enum SocksError # |
Methods succ :: SocksError -> SocksError # pred :: SocksError -> SocksError # toEnum :: Int -> SocksError # fromEnum :: SocksError -> Int # enumFrom :: SocksError -> [SocksError] # enumFromThen :: SocksError -> SocksError -> [SocksError] # enumFromTo :: SocksError -> SocksError -> [SocksError] # enumFromThenTo :: SocksError -> SocksError -> SocksError -> [SocksError] #
Eq SocksError # |
Methods (==) :: SocksError -> SocksError -> Bool # (/=) :: SocksError -> SocksError -> Bool #
Data SocksError # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> SocksError -> c SocksError # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c SocksError # toConstr :: SocksError -> Constr # dataTypeOf :: SocksError -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c SocksError) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SocksError) # gmapT :: (forall b. Data b => b -> b) -> SocksError -> SocksError # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SocksError -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SocksError -> r # gmapQ :: (forall d. Data d => d -> u) -> SocksError -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> SocksError -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> SocksError -> m SocksError # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> SocksError -> m SocksError # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> SocksError -> m SocksError #
Ord SocksError # |
Methods compare :: SocksError -> SocksError -> Ordering # (<) :: SocksError -> SocksError -> Bool # (<=) :: SocksError -> SocksError -> Bool # (>) :: SocksError -> SocksError -> Bool # (>=) :: SocksError -> SocksError -> Bool # max :: SocksError -> SocksError -> SocksError # min :: SocksError -> SocksError -> SocksError #
Show SocksError # |
Methods showsPrec :: Int -> SocksError -> ShowS # show :: SocksError -> String # showList :: [SocksError] -> ShowS #
Exception SocksError # |
Methods toException :: SocksError -> SomeException # fromException :: SomeException -> Maybe SocksError # displayException :: SocksError -> String #

# Configuration

data SocksConf #

SOCKS configuration structure. this structure will be extended in future to support authentification. use defaultSocksConf to create new record.

Constructors

SocksConf |
Fields socksServer :: SocksAddress SOCKS Address socksVersion :: SocksVersion SOCKS version to use

socksHost :: SocksConf -> SocksHostAddress #

SOCKS Host

socksPort :: SocksConf -> PortNumber #

SOCKS Port

defaultSocksConf :: String -> PortNumber -> SocksConf #

defaultSocksConf create a new record, making sure API remains compatible when the record is extended.

defaultSocksConfFromSockAddr :: SockAddr -> SocksConf #

same as defaultSocksConf except the server address is determined from a `SockAddr`

A unix SockAddr will raises an error. Only Inet and Inet6 types supported

# Methods

socksConnectWithSocket #

Arguments

:: Socket | Socket to use.
-> SocksConf | SOCKS configuration for the server.
-> SocksAddress | SOCKS Address to connect to.
-> IO (SocksHostAddress, PortNumber) |

connect a user specified new socket to the socks server, and connect the stream on the server side to the `SockAddress` specified.

|socket|-----sockServer----->|server|----destAddr----->|destination|

socksConnect #

Arguments

:: SocksConf | SOCKS configuration for the server.
-> SocksAddress | SOCKS Address to connect to.
-> IO (Socket, (SocksHostAddress, PortNumber)) |

connect a new socket to a socks server and connect the stream on the server side to the `SocksAddress` specified.

# Variants

socksConnectAddr :: Socket -> SockAddr -> SockAddr -> IO () #

Deprecated: use socksConnectWithSocket

connect a new socket to the socks server, and connect the stream on the server side to the sockaddr specified. the sockaddr need to be SockAddrInet or SockAddrInet6.

a unix sockaddr will raises an exception.

|socket|-----sockServer----->|server|----destAddr----->|destination|

socksConnectName :: Socket -> SockAddr -> String -> PortNumber -> IO () #

connect a new socket to the socks server, and connect the stream to a FQDN resolved on the server side.

socksConnectTo' :: String -> PortID -> String -> PortID -> IO Socket #

similar to Network connectTo but use a socks proxy with default socks configuration.

socksConnectTo :: String -> PortID -> String -> PortID -> IO Handle #

similar to Network connectTo but use a socks proxy with default socks configuration.

socksConnectWith #

Arguments

:: SocksConf | SOCKS configuration
-> String | destination hostname
-> PortID | destination port
-> IO Socket |

create a new socket and connect in to a destination through the specified SOCKS configuration.