Skip to content
This repository
Browse code

Add a way to pass user defined socket address to the underlaying layer.

Since the actual sockaddr length is undefined, there's no way to marshal the
SockAddrRaw back to the haskell structure.
  • Loading branch information...
commit 414edbb4ce58311135fc415b434b157e014e9dd7 1 parent c29ac92
Vincent Hanquez vincenthz authored

Showing 1 changed file with 10 additions and 0 deletions. Show diff stats Hide diff stats

  1. +10 0 Network/Socket/Internal.hsc
10 Network/Socket/Internal.hsc
@@ -239,6 +239,9 @@ data SockAddr -- C Names
239 239 | SockAddrUnix
240 240 String -- sun_path
241 241 #endif
  242 + | SockAddrRaw
  243 + Family -- socket family
  244 + [Word8] -- raw bytes
242 245 deriving (Eq)
243 246
244 247 #if defined(WITH_WINSOCK) || defined(cygwin32_HOST_OS)
@@ -263,6 +266,7 @@ sizeOfSockAddr (SockAddrInet _ _) = #const sizeof(struct sockaddr_in)
263 266 #if defined(IPV6_SOCKET_SUPPORT)
264 267 sizeOfSockAddr (SockAddrInet6 _ _ _ _) = #const sizeof(struct sockaddr_in6)
265 268 #endif
  269 +sizeOfSockAddr (SockAddrRaw _ bytes) = (#const sizeof(sa_family_t)) + length bytes
266 270
267 271 -- | Computes the storage requirements (in bytes) required for a
268 272 -- 'SockAddr' with the given 'Family'.
@@ -335,6 +339,12 @@ pokeSockAddr p (SockAddrInet6 (PortNum port) flow addr scope) = do
335 339 (#poke struct sockaddr_in6, sin6_addr) p addr
336 340 (#poke struct sockaddr_in6, sin6_scope_id) p scope
337 341 #endif
  342 +pokeSockAddr p sa@(SockAddrRaw family bytes) = do
  343 +#if defined(darwin_TARGET_OS)
  344 + zeroMemory p (sizeOfSockAddr sa)
  345 +#endif
  346 + (#poke struct sockaddr, sa_family) p (fromIntegral (packFamily family) :: CSaFamily)
  347 + pokeArray ((#ptr struct sockaddr, sa_data) p) bytes
338 348
339 349 -- | Read a 'SockAddr' from the given memory location.
340 350 peekSockAddr :: Ptr SockAddr -> IO SockAddr

0 comments on commit 414edbb

Please sign in to comment.
Something went wrong with that request. Please try again.