diff options
Diffstat (limited to 'src/Network/Address.hs')
-rw-r--r-- | src/Network/Address.hs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/Network/Address.hs b/src/Network/Address.hs index 0fbd191a..d34b0431 100644 --- a/src/Network/Address.hs +++ b/src/Network/Address.hs | |||
@@ -83,6 +83,7 @@ module Network.Address | |||
83 | -- * Utils | 83 | -- * Utils |
84 | , libUserAgent | 84 | , libUserAgent |
85 | , sockAddrPort | 85 | , sockAddrPort |
86 | , withPort | ||
86 | , getBindAddress | 87 | , getBindAddress |
87 | ) where | 88 | ) where |
88 | 89 | ||
@@ -147,6 +148,12 @@ sockAddrPort (SockAddrInet6 p _ _ _) = Just p | |||
147 | sockAddrPort _ = Nothing | 148 | sockAddrPort _ = Nothing |
148 | {-# INLINE sockAddrPort #-} | 149 | {-# INLINE sockAddrPort #-} |
149 | 150 | ||
151 | withPort :: SockAddr -> PortNumber -> SockAddr | ||
152 | withPort (SockAddrInet _ ip ) port = SockAddrInet port ip | ||
153 | withPort (SockAddrInet6 _ flow ip scope) port = SockAddrInet6 port flow ip scope | ||
154 | withPort addr _ = addr | ||
155 | {-# INLINE withPort #-} | ||
156 | |||
150 | instance Address a => Address (NodeAddr a) where | 157 | instance Address a => Address (NodeAddr a) where |
151 | toSockAddr NodeAddr {..} = setPort nodePort $ toSockAddr nodeHost | 158 | toSockAddr NodeAddr {..} = setPort nodePort $ toSockAddr nodeHost |
152 | fromSockAddr sa = NodeAddr <$> fromSockAddr sa <*> sockAddrPort sa | 159 | fromSockAddr sa = NodeAddr <$> fromSockAddr sa <*> sockAddrPort sa |