$OpenBSD: patch-Network_Socket_hsc,v 1.3 2012/12/02 20:27:19 kili Exp $

ucred is sockpeercred on OpenBSD

don't throw an error when attempting to setsockopt IPV6_V6ONLY

--- Network/Socket.hsc.orig	Thu Aug 16 18:06:46 2012
+++ Network/Socket.hsc	Wed Nov 21 22:08:08 2012
@@ -80,7 +80,7 @@ module Network.Socket
     , getPeerName
     , getSocketName
 
-#ifdef HAVE_STRUCT_UCRED
+#ifdef HAVE_STRUCT_SOCKPEERCRED
     -- get the credentials of our domain socket peer.
     , getPeerCred
 #endif
@@ -424,9 +424,10 @@ socket family stype protocol = do
     socket_status <- newMVar NotConnected
     let sock = MkSocket fd family stype protocol socket_status
 #if HAVE_DECL_IPV6_V6ONLY
-# if defined(mingw32_HOST_OS)
+# if defined(mingw32_HOST_OS) || defined(openbsd_HOST_OS)
     -- the IPv6Only option is only supported on Windows Vista and later,
-    -- so trying to change it might throw an error
+    -- so trying to change it might throw an error. It's also not
+    -- supported on OpenBSD.
     when (family == AF_INET6) $
             catch (setSocketOption sock IPv6Only 0) $ const $ return ()
 # else
@@ -1057,22 +1058,22 @@ getSocketOption (MkSocket s _ _ _ _) so = do
        fromIntegral `liftM` peek ptr_v
 
 
-#ifdef HAVE_STRUCT_UCRED
+#ifdef HAVE_STRUCT_SOCKPEERCRED
 -- | Returns the processID, userID and groupID of the socket's peer.
 --
 -- Only available on platforms that support SO_PEERCRED on domain sockets.
 getPeerCred :: Socket -> IO (CUInt, CUInt, CUInt)
 getPeerCred sock = do
   let fd = fdSocket sock
-  let sz = (fromIntegral (#const sizeof(struct ucred)))
+  let sz = (fromIntegral (#const sizeof(struct sockpeercred)))
   with sz $ \ ptr_cr -> 
    alloca       $ \ ptr_sz -> do
      poke ptr_sz sz
      throwErrnoIfMinus1 "getPeerCred" $
        c_getsockopt fd (#const SOL_SOCKET) (#const SO_PEERCRED) ptr_cr ptr_sz
-     pid <- (#peek struct ucred, pid) ptr_cr
-     uid <- (#peek struct ucred, uid) ptr_cr
-     gid <- (#peek struct ucred, gid) ptr_cr
+     pid <- (#peek struct sockpeercred, pid) ptr_cr
+     uid <- (#peek struct sockpeercred, uid) ptr_cr
+     gid <- (#peek struct sockpeercred, gid) ptr_cr
      return (pid, uid, gid)
 #endif
 
