diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-08 14:23:16 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-08 14:23:16 +0000 |
commit | 8f9d6d1863e3b00ed44ac693e9659b860cf1e507 (patch) | |
tree | d2356e5abefaebb9de5ecad675d5ba72b7572c80 /ext/socket | |
parent | 5baafac0b73f8e242e93926bc02754fd821ba00d (diff) | |
download | ruby-8f9d6d1863e3b00ed44ac693e9659b860cf1e507.tar.gz |
* ext/socket/option.c (inspect_peercred): new function to show
SO_PEERCRED socket option.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket')
-rw-r--r-- | ext/socket/option.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/ext/socket/option.c b/ext/socket/option.c index 8fcee4c0c7..283dd7b279 100644 --- a/ext/socket/option.c +++ b/ext/socket/option.c @@ -221,6 +221,23 @@ inspect_timeval(int level, int optname, VALUE data, VALUE ret) } } +#if defined(SOL_SOCKET) && defined(SO_PEERCRED) /* GNU/Linux */ +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)); + rb_str_catf(ret, " pid=%u uid=%u gid=%u", cred.pid, cred.uid, cred.gid); + rb_str_cat2(ret, " (ucred)"); + return 0; + } + else { + return -1; + } +} +#endif + static VALUE sockopt_inspect(VALUE self) { @@ -299,6 +316,9 @@ sockopt_inspect(VALUE self) # if defined(SO_SNDTIMEO) /* POSIX */ case SO_SNDTIMEO: if (inspect_timeval(level, optname, data, ret) == -1) goto dump; break; # endif +# if defined(SO_PEERCRED) /* GNU/Linux */ + case SO_PEERCRED: if (inspect_peercred(level, optname, data, ret) == -1) goto dump; break; +# endif default: goto dump; } |