
New patches:

[Make IPv6 address handling more portable and robust.
Bryan O'Sullivan <bos@serpentine.com>**20070627182816
 
 1.  No longer rely on the in6_addr structure's s6_addr32 field, which
     is not available on many platforms.  Use s6_addr instead.
 
 2.  Add a number of AI_* flags that are required by RFC 3493.  Not all
     of these flags are implemented on all systems, but on systems
     where they *are* implemented, we get runtime exceptions if we
     don't make them available.
 
 3.  To let users check whether a particular AI_* flag is implemented,
     we introduce the addrInfoFlagImplemented function.
 
 4.  Fix the autoconf macro used to check for AI_* flag availability.
     The previous check wasn't portable, and caused flags to appear not
     to be present when they really were.
] {
hunk ./Network/Socket.hsc 75
+    addrInfoFlagImplemented,-- :: AddrInfoFlag -> Bool
hunk ./Network/Socket.hsc 427
+-- The peek32 and poke32 functions work around the fact that the RFCs
+-- don't require 32-bit-wide address fields to be present.  We can
+-- only portably rely on an 8-bit field, s6_addr.
+
+s6_addr_offset = (#offset struct in6_addr, s6_addr)
+
+peek32 :: Ptr a -> Int -> IO Word32
+
+peek32 p i = do
+    let i' = i * 4
+        peekByte n = peekByteOff p (s6_addr_offset + i' + n) :: IO Word8
+        a `sl` i = fromIntegral a `shiftL` i
+    a0 <- peekByte 0
+    a1 <- peekByte 1
+    a2 <- peekByte 2
+    a3 <- peekByte 3
+    return ((a0 `sl` 24) .|. (a1 `sl` 16) .|. (a2 `sl` 8) .|. (a3 `sl` 0))
+
+poke32 :: Ptr a -> Int -> Word32 -> IO ()
+
+poke32 p i a = do
+    let i' = i * 4
+        pokeByte n = pokeByteOff p (s6_addr_offset + i' + n)
+        a `sr` i = fromIntegral (a `shiftR` i) :: Word8
+    pokeByte 0 (a `sr` 24)
+    pokeByte 1 (a `sr` 16)
+    pokeByte 2 (a `sr`  8)
+    pokeByte 3 (a `sr`  0)
+
hunk ./Network/Socket.hsc 461
-        a <- (#peek struct in6_addr, s6_addr32[0]) p
-        b <- (#peek struct in6_addr, s6_addr32[1]) p
-        c <- (#peek struct in6_addr, s6_addr32[2]) p
-        d <- (#peek struct in6_addr, s6_addr32[3]) p
+        a <- peek32 p 0
+        b <- peek32 p 1
+        c <- peek32 p 2
+        d <- peek32 p 3
hunk ./Network/Socket.hsc 468
-        (#poke struct in6_addr, s6_addr32[0]) p a
-        (#poke struct in6_addr, s6_addr32[1]) p b
-        (#poke struct in6_addr, s6_addr32[2]) p c
-        (#poke struct in6_addr, s6_addr32[3]) p d
+        poke32 p 0 a
+        poke32 p 1 b
+        poke32 p 2 c
+        poke32 p 3 d
hunk ./Network/Socket.hsc 2110
+    | AI_ALL
hunk ./Network/Socket.hsc 2113
+    | AI_NUMERICSERV
hunk ./Network/Socket.hsc 2115
+    | AI_V4MAPPED
hunk ./Network/Socket.hsc 2124
-#if defined(HAVE_AI_ADDRCONFIG)
+#if defined(HAVE_DECL_AI_ADDRCONFIG)
hunk ./Network/Socket.hsc 2129
+#if defined(HAVE_DECL_AI_ALL)
+     (AI_ALL, #const AI_ALL),
+#else
+     (AI_ALL, 0),
+#endif
hunk ./Network/Socket.hsc 2136
-     (AI_PASSIVE, #const AI_PASSIVE)]
+#if defined(HAVE_DECL_AI_NUMERICSERV)
+     (AI_NUMERICSERV, #const AI_NUMERICSERV),
+#else
+     (AI_NUMERICSERV, 0),
+#endif
+     (AI_PASSIVE, #const AI_PASSIVE),
+#if defined(HAVE_DECL_AI_V4MAPPED)
+     (AI_V4MAPPED, #const AI_V4MAPPED)
+#else
+     (AI_V4MAPPED, 0)
+#endif
+    ]
+
+-- | Indicate whether the given 'AddrInfoFlag' will have any effect on
+-- this system.
+addrInfoFlagImplemented :: AddrInfoFlag -> Bool
+addrInfoFlagImplemented f = packBits aiFlagMapping [f] /= 0
hunk ./Network/Socket.hsc 2270
---      attempted.
+--     attempted.
+-- 
+-- /Note/: Although the following flags are required by RFC 3493, they
+-- may not have an effect on all platforms, because the underlying
+-- network stack may not support them.  To see whether a flag from the
+-- list below will have any effect, call 'addrInfoFlagImplemented'.
+--
+--   [@AI_NUMERICSERV@] The 'ServiceName' argument /must/ be a port
+--     number in string form, and service name lookups will not be
+--     attempted.
+--
+--   [@AI_ADDRCONFIG@] The list of returned 'AddrInfo' values will
+--     only contain IPv4 addresses if the local system has at least
+--     one IPv4 interface configured, and likewise for IPv6.
hunk ./Network/Socket.hsc 2285
---   [@AI_ADDRCONFIG@] The list of returned 'AddrInfo' values will only
---     contain IPv4 addresses if the local system has at least one
---     IPv4 interface configured, and likewise for IPv6.
+--   [@AI_V4MAPPED@] If an IPv6 lookup is performed, and no IPv6
+--     addresses are found, IPv6-mapped IPv4 addresses will be
+--     returned.
hunk ./Network/Socket.hsc 2289
+--   [@AI_ALL@] If 'AI_ALL' is specified, return all matching IPv6 and
+--     IPv4 addresses.  Otherwise, this flag has no effect.
+--     
hunk ./configure.ac 47
-dnl --------------------------------------------------
-dnl * test for AI_ADDRCONFIG (Not all IPv6 implementations have it)
-dnl --------------------------------------------------
-AC_MSG_CHECKING(for AI_ADDRCONFIG in netdb.h)
-AC_EGREP_HEADER(AI_ADDRCONFIG, netdb.h,
- [ AC_DEFINE([HAVE_AI_ADDRCONFIG], [1], [Define to 1 if AI_ADDRCONFIG is available.]) AC_MSG_RESULT(yes) ],
- AC_MSG_RESULT(no))
+dnl -------------------------------------------------------
+dnl * test for AI_* flags that not all implementations have
+dnl -------------------------------------------------------
+AC_CHECK_DECLS([AI_ADDRCONFIG, AI_ALL, AI_NUMERICSERV, AI_V4MAPPED], , ,
+ [#include <netdb.h>])
}

Context:

[Fix further build problems when IPv6 isn't available
Simon Marlow <simonmar@microsoft.com>**20070604105407] 
[Try a hopefully more portable test for RFC 3493 API compatibility.
Bryan O'Sullivan <bos@serpentine.com>**20070602050225] 
[Fix build failure if IPv6 is not available.
Bryan O'Sullivan <bos@serpentine.com>**20070601160943] 
[Fixed support for platforms with IPv6 but no AI_ADDRCONFIG
Michael D. Adams <t-madams@microsoft.com>**20070604153642] 
[--configure-option and --ghc-option are now provided by Cabal
Ross Paterson <ross@soi.city.ac.uk>**20070604115612] 
[Invoke the preprocessor portably.
Bryan O'Sullivan <bos@serpentine.com>**20070408171912] 
[Add IPv6 support to Network.
Bryan O'Sullivan <bos@serpentine.com>**20070404223751
 
 The public API remains unchanged; it can now transparently handle IPv6
 addresses and sockets.
] 
[Add IPv6 support to Network.Socket.
Bryan O'Sullivan <bos@serpentine.com>**20070404222036
 
 The only public API changes are to Network.Socket, which has the following
 exported names added (no existing names have been removed):
 
     -- IPv6 address components
     HostAddress6
     FlowInfo
     ScopeID
 
     -- Name -> address lookup
     getAddrInfo
     AddrInfo
     AddrInfoFlag
     defaultHints
 
     -- Address -> name lookup
     getNameInfo
     NameInfoFlag
 
 The SockAddr type acquires a new branch, SockAddr6.  (This could cause
 new "non-exhaustive matches" warnings when compiling pre-existing client
 code that pattern-matches on SockAddr values.  However, it will not
 cause runtime pattern failure errors in clients using the pre-existing
 IPv4 entry points, as they will never see IPv6 addresses.)
 
 This change moves a few type names from Network.BSD to Network.Socket:
 
     HostName
     ServiceName
 
 These names are still re-exported from Network.BSD, so pre-existing code
 should not be affected.
] 
[Remove Makefile and package.conf.in (used in the old GHC build system)
Ian Lynagh <igloo@earth.li>**20070524145815] 
[add includes: field
Simon Marlow <simonmar@microsoft.com>**20070517095001] 
[TAG GHC 6.6.1 release
Ian Lynagh <igloo@earth.li>**20070428195851] 
Patch bundle hash:
d4bd5adde3966023956746ac9be0ba87428f86e9
