--- gio/gunixcredentialsmessage.c.orig	Fri Nov 12 14:52:52 2010
+++ gio/gunixcredentialsmessage.c	Wed Dec  8 00:11:15 2010
@@ -53,6 +53,14 @@
 #include <unistd.h>
 #include <fcntl.h>
 #define G_UNIX_CREDENTIALS_MESSAGE_SUPPORTED 1
+
+#elif defined(__OpenBSD__)
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <unistd.h>
+#include <fcntl.h>
+#define G_UNIX_CREDENTIALS_MESSAGE_SUPPORTED 1
 #else
 /* TODO: please add support for your UNIX flavor */
 #define G_UNIX_CREDENTIALS_MESSAGE_SUPPORTED 0
@@ -88,6 +96,8 @@ g_unix_credentials_message_get_size (GSocketControlMes
   return sizeof (struct ucred);
 #elif defined(__FreeBSD__)
   return sizeof (struct cmsgcred);
+#elif defined(__OpenBSD__)
+  return sizeof (struct sockpeercred);
 #else
   return 0;
 #endif
@@ -100,6 +110,8 @@ g_unix_credentials_message_get_level (GSocketControlMe
   return SOL_SOCKET;
 #elif defined(__FreeBSD__)
   return SOL_SOCKET;
+#elif defined(__OpenBSD__)
+  return SOL_SOCKET;
 #else
   return 0;
 #endif
@@ -112,6 +124,8 @@ g_unix_credentials_message_get_msg_type (GSocketContro
   return SCM_CREDENTIALS;
 #elif defined(__FreeBSD__)
   return SCM_CREDS;
+#elif defined(__OpenBSD__)
+  return SCM_CREDS;
 #else
   return 0;
 #endif
@@ -180,6 +194,32 @@ g_unix_credentials_message_deserialize (gint     level
  out:
     ;
   }
+#elif defined(__OpenBSD__)
+  {
+    GCredentials *credentials;
+    struct sockpeercred *cr;
+
+    if (level != SOL_SOCKET || type != SCM_CREDS)
+      goto out;
+
+    if (size != sizeof (struct sockpeercred))
+      {
+        g_warning ("Expected a struct sockpeercred (%" G_GSIZE_FORMAT " bytes) but "
+                   "got %" G_GSIZE_FORMAT " bytes of data",
+                   sizeof (struct sockpeercred),
+                   size);
+        goto out;
+      }
+
+    cr = data;
+
+    credentials = g_credentials_new ();
+    g_credentials_set_native (credentials, G_CREDENTIALS_TYPE_OPENBSD_SOCKPEERCRED, cr);
+    message = g_unix_credentials_message_new_with_credentials (credentials);
+    g_object_unref (credentials);
+ out:
+    ;
+  }
 #endif
 
   return message;
@@ -200,7 +240,11 @@ g_unix_credentials_message_serialize (GSocketControlMe
           g_credentials_get_native (message->priv->credentials,
                                     G_CREDENTIALS_TYPE_FREEBSD_CMSGCRED),
           sizeof (struct cmsgcred));
-
+#elif defined(__OpenBSD__)
+  memcpy (data,
+          g_credentials_get_native (message->priv->credentials,
+                                    G_CREDENTIALS_TYPE_OPENBSD_SOCKPEERCRED),
+          sizeof (struct sockpeercred));
 #endif
 }
 

