summaryrefslogtreecommitdiff
path: root/ext/socket/option.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-09-09 17:19:52 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-09-09 17:19:52 +0000
commita75a46710232c09f172523b90756a0e0f79e4811 (patch)
tree969dded8f2b878f1bac306bfbafe43fb850a60df /ext/socket/option.c
parent83a827ac9be0249471b23ee56980bc33a542a0fa (diff)
* ext/socket/option.c (inspect_peercred): support OpenBSD-current.
patch by Jeremy Evans. [ruby-core:32240] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/option.c')
-rw-r--r--ext/socket/option.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/ext/socket/option.c b/ext/socket/option.c
index 63bffb9..6d437db 100644
--- a/ext/socket/option.c
+++ b/ext/socket/option.c
@@ -396,13 +396,18 @@ inspect_timeval_as_interval(int level, int optname, VALUE data, VALUE ret)
}
}
-#if defined(SOL_SOCKET) && defined(SO_PEERCRED) /* GNU/Linux */
+#if defined(SOL_SOCKET) && defined(SO_PEERCRED) /* GNU/Linux, OpenBSD */
+#if defined(__OpenBSD__)
+#define RUBY_SOCK_PEERCRED struct sockpeercred
+#else
+#define RUBY_SOCK_PEERCRED struct ucred
+#endif
static int
inspect_peercred(int level, int optname, VALUE data, VALUE ret)
{
- if (RSTRING_LEN(data) == sizeof(struct ucred)) {
- struct ucred cred;
- memcpy(&cred, RSTRING_PTR(data), sizeof(struct ucred));
+ if (RSTRING_LEN(data) == sizeof(RUBY_SOCK_PEERCRED)) {
+ RUBY_SOCK_PEERCRED cred;
+ memcpy(&cred, RSTRING_PTR(data), sizeof(RUBY_SOCK_PEERCRED));
rb_str_catf(ret, " pid=%u euid=%u egid=%u",
(unsigned)cred.pid, (unsigned)cred.uid, (unsigned)cred.gid);
rb_str_cat2(ret, " (ucred)");
@@ -569,7 +574,7 @@ sockopt_inspect(VALUE self)
# if defined(SO_SNDTIMEO) /* POSIX */
case SO_SNDTIMEO: inspected = inspect_timeval_as_interval(level, optname, data, ret); break;
# endif
-# if defined(SO_PEERCRED) /* GNU/Linux */
+# if defined(SO_PEERCRED) /* GNU/Linux, OpenBSD */
case SO_PEERCRED: inspected = inspect_peercred(level, optname, data, ret); break;
# endif
}