module Network.Socks5.Conf
( SocksConf(..)
, socksHost
, socksPort
, defaultSocksConf
, defaultSocksConfFromSockAddr
) where
import Network.Socket
import Network.Socks5.Types (SocksAddress(..), SocksHostAddress(..), SocksVersion(..))
import qualified Data.ByteString.Char8 as BC
data SocksConf = SocksConf
{ socksServer :: SocksAddress
, socksVersion :: SocksVersion
}
socksHost :: SocksConf -> SocksHostAddress
socksHost conf = ha where (SocksAddress ha _) = socksServer conf
socksPort :: SocksConf -> PortNumber
socksPort conf = port where (SocksAddress _ port) = socksServer conf
defaultSocksConf host port = SocksConf server SocksVer5
where server = SocksAddress haddr port
haddr = SocksAddrDomainName $ BC.pack host
defaultSocksConfFromSockAddr sockaddr = SocksConf server SocksVer5
where server = SocksAddress haddr port
(haddr,port) = case sockaddr of
SockAddrInet p h -> (SocksAddrIPV4 h, p)
SockAddrInet6 p _ h _ -> (SocksAddrIPV6 h, p)
_ -> error "unsupported unix sockaddr type"