mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/socket/ancdata.c (anc_inspect_socket_rights): return 1 on
success. 0 on failure. (anc_inspect_passcred_credentials): ditto. (anc_inspect_socket_creds): ditto. (anc_inspect_socket_creds): ditto. (anc_inspect_socket_creds): ditto. (anc_inspect_ip_recvdstaddr): ditto. (anc_inspect_ip_pktinfo): ditto. (anc_inspect_ipv6_pktinfo): ditto. (ancillary_inspect): check family. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22228 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6e6676a223
commit
4b036bb69b
2 changed files with 106 additions and 64 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
||||||
|
Wed Feb 11 14:08:23 2009 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* ext/socket/ancdata.c (anc_inspect_socket_rights): return 1 on
|
||||||
|
success. 0 on failure.
|
||||||
|
(anc_inspect_passcred_credentials): ditto.
|
||||||
|
(anc_inspect_socket_creds): ditto.
|
||||||
|
(anc_inspect_socket_creds): ditto.
|
||||||
|
(anc_inspect_socket_creds): ditto.
|
||||||
|
(anc_inspect_ip_recvdstaddr): ditto.
|
||||||
|
(anc_inspect_ip_pktinfo): ditto.
|
||||||
|
(anc_inspect_ipv6_pktinfo): ditto.
|
||||||
|
(ancillary_inspect): check family.
|
||||||
|
|
||||||
Wed Feb 11 12:55:07 2009 Tanaka Akira <akr@fsij.org>
|
Wed Feb 11 12:55:07 2009 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* ext/socket/ancdata.c (anc_inspect_ip_pktinfo): make result bit
|
* ext/socket/ancdata.c (anc_inspect_ip_pktinfo): make result bit
|
||||||
|
|
|
@ -494,10 +494,10 @@ anc_inspect_socket_rights(int level, int type, VALUE data, VALUE ret)
|
||||||
memcpy((char*)&fd, RSTRING_PTR(data)+off, sizeof(int));
|
memcpy((char*)&fd, RSTRING_PTR(data)+off, sizeof(int));
|
||||||
rb_str_catf(ret, " %d", fd);
|
rb_str_catf(ret, " %d", fd);
|
||||||
}
|
}
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -512,10 +512,10 @@ anc_inspect_passcred_credentials(int level, int type, VALUE data, VALUE ret)
|
||||||
memcpy(&cred, RSTRING_PTR(data), sizeof(struct ucred));
|
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_catf(ret, " pid=%u uid=%u gid=%u", cred.pid, cred.uid, cred.gid);
|
||||||
rb_str_cat2(ret, " (ucred)");
|
rb_str_cat2(ret, " (ucred)");
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -526,7 +526,7 @@ static int
|
||||||
anc_inspect_socket_creds(int level, int type, VALUE data, VALUE ret)
|
anc_inspect_socket_creds(int level, int type, VALUE data, VALUE ret)
|
||||||
{
|
{
|
||||||
if (level != SOL_SOCKET && type != SCM_CREDS)
|
if (level != SOL_SOCKET && type != SCM_CREDS)
|
||||||
return -1;
|
return 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* FreeBSD has struct cmsgcred and struct sockcred.
|
* FreeBSD has struct cmsgcred and struct sockcred.
|
||||||
|
@ -556,7 +556,7 @@ anc_inspect_socket_creds(int level, int type, VALUE data, VALUE ret)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rb_str_cat2(ret, " (cmsgcred)");
|
rb_str_cat2(ret, " (cmsgcred)");
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(HAVE_TYPE_STRUCT_SOCKCRED) /* FreeBSD, NetBSD */
|
#if defined(HAVE_TYPE_STRUCT_SOCKCRED) /* FreeBSD, NetBSD */
|
||||||
|
@ -579,11 +579,11 @@ anc_inspect_socket_creds(int level, int type, VALUE data, VALUE ret)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rb_str_cat2(ret, " (sockcred)");
|
rb_str_cat2(ret, " (sockcred)");
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -600,10 +600,10 @@ anc_inspect_ip_recvdstaddr(int level, int type, VALUE data, VALUE ret)
|
||||||
rb_str_cat2(ret, " invalid-address");
|
rb_str_cat2(ret, " invalid-address");
|
||||||
else
|
else
|
||||||
rb_str_catf(ret, " %s", addrbuf);
|
rb_str_catf(ret, " %s", addrbuf);
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -629,10 +629,10 @@ anc_inspect_ip_pktinfo(int level, int type, VALUE data, VALUE ret)
|
||||||
rb_str_cat2(ret, " spec_dst:invalid-address");
|
rb_str_cat2(ret, " spec_dst:invalid-address");
|
||||||
else
|
else
|
||||||
rb_str_catf(ret, " spec_dst:%s", buf);
|
rb_str_catf(ret, " spec_dst:%s", buf);
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -657,10 +657,10 @@ anc_inspect_ipv6_pktinfo(int level, int type, VALUE data, VALUE ret)
|
||||||
rb_str_catf(ret, " ifindex:%d", ifindex);
|
rb_str_catf(ret, " ifindex:%d", ifindex);
|
||||||
else
|
else
|
||||||
rb_str_catf(ret, " %s", ifbuf);
|
rb_str_catf(ret, " %s", ifbuf);
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -680,79 +680,108 @@ ancillary_inspect(VALUE self)
|
||||||
VALUE ret;
|
VALUE ret;
|
||||||
int family, level, type;
|
int family, level, type;
|
||||||
VALUE data;
|
VALUE data;
|
||||||
ID family_id, level_id;
|
ID family_id, level_id, type_id;
|
||||||
VALUE vtype;
|
VALUE vtype;
|
||||||
|
int inspected;
|
||||||
|
|
||||||
family = ancillary_family(self);
|
family = ancillary_family(self);
|
||||||
level = ancillary_level(self);
|
level = ancillary_level(self);
|
||||||
type = ancillary_type(self);
|
type = ancillary_type(self);
|
||||||
data = ancillary_data(self);
|
data = ancillary_data(self);
|
||||||
|
|
||||||
ret = rb_sprintf("#<%s: ", rb_obj_classname(self));
|
ret = rb_sprintf("#<%s:", rb_obj_classname(self));
|
||||||
|
|
||||||
family_id = intern_family_noprefix(family);
|
family_id = intern_family_noprefix(family);
|
||||||
if (family_id)
|
if (family_id)
|
||||||
rb_str_cat2(ret, rb_id2name(family_id));
|
rb_str_catf(ret, " %s", rb_id2name(family_id));
|
||||||
else
|
else
|
||||||
rb_str_catf(ret, "family:%d", family);
|
rb_str_catf(ret, " family:%d", family);
|
||||||
|
|
||||||
level_id = intern_iplevel(level);
|
if (level == SOL_SOCKET) {
|
||||||
if (level_id)
|
rb_str_cat2(ret, " SOCKET");
|
||||||
rb_str_catf(ret, " %s", rb_id2name(level_id));
|
|
||||||
else
|
type_id = intern_scm_optname(type);
|
||||||
|
if (type_id)
|
||||||
|
rb_str_catf(ret, " %s", rb_id2name(type_id));
|
||||||
|
else
|
||||||
|
rb_str_catf(ret, " cmsg_type:%d", type);
|
||||||
|
}
|
||||||
|
else if (IS_IP_FAMILY(family)) {
|
||||||
|
level_id = intern_iplevel(level);
|
||||||
|
if (level_id)
|
||||||
|
rb_str_catf(ret, " %s", rb_id2name(level_id));
|
||||||
|
else
|
||||||
|
rb_str_catf(ret, " cmsg_level:%d", level);
|
||||||
|
|
||||||
|
vtype = ip_cmsg_type_to_sym(level, type);
|
||||||
|
if (SYMBOL_P(vtype))
|
||||||
|
rb_str_catf(ret, " %s", rb_id2name(SYM2ID(vtype)));
|
||||||
|
else
|
||||||
|
rb_str_catf(ret, " cmsg_type:%d", type);
|
||||||
|
}
|
||||||
|
else {
|
||||||
rb_str_catf(ret, " cmsg_level:%d", level);
|
rb_str_catf(ret, " cmsg_level:%d", level);
|
||||||
|
|
||||||
vtype = ip_cmsg_type_to_sym(level, type);
|
|
||||||
if (SYMBOL_P(vtype))
|
|
||||||
rb_str_catf(ret, " %s", rb_id2name(SYM2ID(vtype)));
|
|
||||||
else
|
|
||||||
rb_str_catf(ret, " cmsg_type:%d", type);
|
rb_str_catf(ret, " cmsg_type:%d", type);
|
||||||
|
}
|
||||||
|
|
||||||
switch (level) {
|
inspected = 0;
|
||||||
# if defined(SOL_SOCKET)
|
|
||||||
case SOL_SOCKET:
|
if (level == SOL_SOCKET)
|
||||||
switch (type) {
|
family = AF_UNSPEC;
|
||||||
# if defined(SCM_RIGHTS) /* 4.4BSD */
|
|
||||||
case SCM_RIGHTS: if (anc_inspect_socket_rights(level, type, data, ret) == -1) goto dump; break;
|
switch (family) {
|
||||||
|
case AF_UNSPEC:
|
||||||
|
switch (level) {
|
||||||
|
# if defined(SOL_SOCKET)
|
||||||
|
case SOL_SOCKET:
|
||||||
|
switch (type) {
|
||||||
|
# if defined(SCM_RIGHTS) /* 4.4BSD */
|
||||||
|
case SCM_RIGHTS: inspected = anc_inspect_socket_rights(level, type, data, ret); break;
|
||||||
|
# endif
|
||||||
|
# if defined(SCM_CREDENTIALS) /* GNU/Linux */
|
||||||
|
case SCM_CREDENTIALS: inspected = anc_inspect_passcred_credentials(level, type, data, ret); break;
|
||||||
|
# endif
|
||||||
|
# if defined(INSPECT_SCM_CREDS) /* NetBSD */
|
||||||
|
case SCM_CREDS: inspected = anc_inspect_socket_creds(level, type, data, ret); break;
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
# endif
|
# endif
|
||||||
# if defined(SCM_CREDENTIALS) /* GNU/Linux */
|
|
||||||
case SCM_CREDENTIALS: if (anc_inspect_passcred_credentials(level, type, data, ret) == -1) goto dump; break;
|
|
||||||
# endif
|
|
||||||
# if defined(INSPECT_SCM_CREDS) /* NetBSD */
|
|
||||||
case SCM_CREDS: if (anc_inspect_socket_creds(level, type, data, ret) == -1) goto dump; break;
|
|
||||||
# endif
|
|
||||||
default: goto dump;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
# endif
|
|
||||||
|
|
||||||
# if defined(IPPROTO_IP)
|
case AF_INET:
|
||||||
case IPPROTO_IP:
|
#ifdef INET6
|
||||||
switch (type) {
|
case AF_INET6:
|
||||||
# if defined(IP_RECVDSTADDR) /* 4.4BSD */
|
#endif
|
||||||
case IP_RECVDSTADDR: if (anc_inspect_ip_recvdstaddr(level, type, data, ret) == -1) goto dump; break;
|
switch (level) {
|
||||||
|
# if defined(IPPROTO_IP)
|
||||||
|
case IPPROTO_IP:
|
||||||
|
switch (type) {
|
||||||
|
# if defined(IP_RECVDSTADDR) /* 4.4BSD */
|
||||||
|
case IP_RECVDSTADDR: inspected = anc_inspect_ip_recvdstaddr(level, type, data, ret); break;
|
||||||
|
# endif
|
||||||
|
# if defined(IP_PKTINFO) && defined(HAVE_TYPE_STRUCT_IN_PKTINFO) /* GNU/Linux */
|
||||||
|
case IP_PKTINFO: inspected = anc_inspect_ip_pktinfo(level, type, data, ret); break;
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
# endif
|
# endif
|
||||||
# if defined(IP_PKTINFO) && defined(HAVE_TYPE_STRUCT_IN_PKTINFO) /* GNU/Linux */
|
|
||||||
case IP_PKTINFO: if (anc_inspect_ip_pktinfo(level, type, data, ret) == -1) goto dump; break;
|
# if defined(IPPROTO_IPV6)
|
||||||
|
case IPPROTO_IPV6:
|
||||||
|
switch (type) {
|
||||||
|
# if defined(IPV6_PKTINFO) /* RFC 3542 */
|
||||||
|
case IPV6_PKTINFO: inspected = anc_inspect_ipv6_pktinfo(level, type, data, ret); break;
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
# endif
|
# endif
|
||||||
default: goto dump;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
# endif
|
}
|
||||||
|
|
||||||
# if defined(IPPROTO_IPV6)
|
if (!inspected) {
|
||||||
case IPPROTO_IPV6:
|
|
||||||
switch (type) {
|
|
||||||
# if defined(IPV6_PKTINFO) /* RFC 3542 */
|
|
||||||
case IPV6_PKTINFO: if (anc_inspect_ipv6_pktinfo(level, type, data, ret) == -1) goto dump; break;
|
|
||||||
# endif
|
|
||||||
default: goto dump;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
# endif
|
|
||||||
|
|
||||||
default:
|
|
||||||
dump:
|
|
||||||
data = rb_str_dump(data);
|
data = rb_str_dump(data);
|
||||||
rb_str_catf(ret, " %s", StringValueCStr(data));
|
rb_str_catf(ret, " %s", StringValueCStr(data));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue