diff options
-rw-r--r-- | src/Network/Address.hs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/Network/Address.hs b/src/Network/Address.hs index 9a601dcd..4f163b79 100644 --- a/src/Network/Address.hs +++ b/src/Network/Address.hs | |||
@@ -126,6 +126,7 @@ import Text.PrettyPrint.HughesPJClass hiding ((<>),($$)) | |||
126 | import System.Locale (defaultTimeLocale) | 126 | import System.Locale (defaultTimeLocale) |
127 | #endif | 127 | #endif |
128 | import System.Entropy | 128 | import System.Entropy |
129 | import System.IO (stderr) | ||
129 | 130 | ||
130 | -- import Paths_bittorrent (version) | 131 | -- import Paths_bittorrent (version) |
131 | 132 | ||
@@ -1168,14 +1169,14 @@ fingerprint pid = either (const def) id $ runGet getCI (getPeerId pid) | |||
1168 | -- function will return a SockAddr to bind to. If the input | 1169 | -- function will return a SockAddr to bind to. If the input |
1169 | -- is not understood as a port number, zero will be set in order | 1170 | -- is not understood as a port number, zero will be set in order |
1170 | -- to ask the system for an unused port. | 1171 | -- to ask the system for an unused port. |
1171 | -- | ||
1172 | -- TODO: Also interpret local ip address specifications in the input | ||
1173 | -- string. | ||
1174 | getBindAddress :: String -> Bool -> IO SockAddr | 1172 | getBindAddress :: String -> Bool -> IO SockAddr |
1175 | getBindAddress listenPortString enabled6 = do | 1173 | getBindAddress bindspec enabled6 = do |
1174 | let (host,listenPortString) = case L.break (==':') (L.reverse bindspec) of | ||
1175 | (rport,':':rhost) -> (Just $ L.reverse rhost, L.reverse rport) | ||
1176 | _ -> (Nothing, bindspec) | ||
1176 | -- Bind addresses for localhost | 1177 | -- Bind addresses for localhost |
1177 | xs <- getAddrInfo (Just (defaultHints {addrFlags = [AI_PASSIVE] })) | 1178 | xs <- getAddrInfo (Just (defaultHints {addrFlags = [AI_PASSIVE] })) |
1178 | Nothing | 1179 | host |
1179 | (Just listenPortString) | 1180 | (Just listenPortString) |
1180 | `onException` return [] | 1181 | `onException` return [] |
1181 | -- We prefer IPv6 because that can also handle connections from IPv4 | 1182 | -- We prefer IPv6 because that can also handle connections from IPv4 |
@@ -1188,6 +1189,7 @@ getBindAddress listenPortString enabled6 = do | |||
1188 | then SockAddrInet6 (parsePort listenPortString) 0 iN6ADDR_ANY 0 | 1189 | then SockAddrInet6 (parsePort listenPortString) 0 iN6ADDR_ANY 0 |
1189 | else SockAddrInet (parsePort listenPortString) iNADDR_ANY | 1190 | else SockAddrInet (parsePort listenPortString) iNADDR_ANY |
1190 | where parsePort s = fromMaybe 0 $ readMaybe s | 1191 | where parsePort s = fromMaybe 0 $ readMaybe s |
1192 | hPutStrLn stderr $ BS8.pack $ "Listening on " ++ show listenAddr | ||
1191 | return listenAddr | 1193 | return listenAddr |
1192 | 1194 | ||
1193 | -- | True if the argument is an IPv4-mapped address with prefix ::FFFF:0:0/96 | 1195 | -- | True if the argument is an IPv4-mapped address with prefix ::FFFF:0:0/96 |