summaryrefslogtreecommitdiffstats
path: root/ext/socket
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-09 14:23:53 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-09 14:23:53 +0000
commite655d5a50f5de54f01ec0451330f3a08584042c7 (patch)
tree448efdd653d2dba25430b6e7c1302125e311138f /ext/socket
parent9c8475fb689d21d8564d470430563237e4adc9e3 (diff)
downloadruby-e655d5a50f5de54f01ec0451330f3a08584042c7.tar.gz
ruby-e655d5a50f5de54f01ec0451330f3a08584042c7.tar.xz
ruby-e655d5a50f5de54f01ec0451330f3a08584042c7.zip
* ext/socket/constants.c (level_arg): use unknown_level_to_int for
non internet protocol. (optname_arg): use only so_optname_to_int for non internet protocol. (cmsg_type_arg): use only scm_optname_to_int for non internet protocol. * ext/socket/mkconstants.rb: generate unknown_level_to_int. rename iplevel_to_int to ip_level_to_int. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@22186 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket')
-rw-r--r--ext/socket/constants.c93
-rw-r--r--ext/socket/mkconstants.rb3
-rw-r--r--ext/socket/rubysocket.h2
3 files changed, 62 insertions, 36 deletions
diff --git a/ext/socket/constants.c b/ext/socket/constants.c
index aaedfa196..f0e210246 100644
--- a/ext/socket/constants.c
+++ b/ext/socket/constants.c
@@ -61,58 +61,83 @@ int
level_arg(int family, VALUE level)
{
/* convert SOL_SOCKET, IPPROTO_TCP, etc. */
- return constant_arg(level, iplevel_to_int, "unknown protocol level");
+ if (IS_IP_FAMILY(family)) {
+ return constant_arg(level, ip_level_to_int, "unknown protocol level");
+ }
+ else {
+ return constant_arg(level, unknown_level_to_int, "unknown protocol level");
+ }
}
int
optname_arg(int family, int level, VALUE optname)
{
- switch (level) {
- case SOL_SOCKET:
- return constant_arg(optname, so_optname_to_int, "unknown socket level option name");
- case IPPROTO_IP:
- return constant_arg(optname, ip_optname_to_int, "unknown IP level option name");
+ if (IS_IP_FAMILY(family)) {
+ switch (level) {
+ case SOL_SOCKET:
+ return constant_arg(optname, so_optname_to_int, "unknown socket level option name");
+ case IPPROTO_IP:
+ return constant_arg(optname, ip_optname_to_int, "unknown IP level option name");
#ifdef IPPROTO_IPV6
- case IPPROTO_IPV6:
- return constant_arg(optname, ipv6_optname_to_int, "unknown IPv6 level option name");
+ case IPPROTO_IPV6:
+ return constant_arg(optname, ipv6_optname_to_int, "unknown IPv6 level option name");
#endif
- case IPPROTO_TCP:
- return constant_arg(optname, tcp_optname_to_int, "unknown TCP level option name");
- case IPPROTO_UDP:
- return constant_arg(optname, udp_optname_to_int, "unknown UDP level option name");
- default:
- return NUM2INT(optname);
+ case IPPROTO_TCP:
+ return constant_arg(optname, tcp_optname_to_int, "unknown TCP level option name");
+ case IPPROTO_UDP:
+ return constant_arg(optname, udp_optname_to_int, "unknown UDP level option name");
+ default:
+ return NUM2INT(optname);
+ }
+ }
+ else {
+ switch (level) {
+ case SOL_SOCKET:
+ return constant_arg(optname, so_optname_to_int, "unknown socket level option name");
+ default:
+ return NUM2INT(optname);
+ }
}
-}
-
-int
-shutdown_how_arg(VALUE how)
-{
- /* convert SHUT_RD, SHUT_WR, SHUT_RDWR. */
- return constant_arg(how, shutdown_how_to_int, "unknown shutdown argument");
}
int
cmsg_type_arg(int family, int level, VALUE type)
{
- switch (level) {
- case SOL_SOCKET:
- return constant_arg(type, scm_optname_to_int, "unknown UNIX control message");
- case IPPROTO_IP:
- return constant_arg(type, ip_optname_to_int, "unknown IP control message");
+ if (IS_IP_FAMILY(family)) {
+ switch (level) {
+ case SOL_SOCKET:
+ return constant_arg(type, scm_optname_to_int, "unknown UNIX control message");
+ case IPPROTO_IP:
+ return constant_arg(type, ip_optname_to_int, "unknown IP control message");
#ifdef INET6
- case IPPROTO_IPV6:
- return constant_arg(type, ipv6_optname_to_int, "unknown IPv6 control message");
+ case IPPROTO_IPV6:
+ return constant_arg(type, ipv6_optname_to_int, "unknown IPv6 control message");
#endif
- case IPPROTO_TCP:
- return constant_arg(type, tcp_optname_to_int, "unknown TCP control message");
- case IPPROTO_UDP:
- return constant_arg(type, udp_optname_to_int, "unknown UDP control message");
- default:
- return NUM2INT(type);
+ case IPPROTO_TCP:
+ return constant_arg(type, tcp_optname_to_int, "unknown TCP control message");
+ case IPPROTO_UDP:
+ return constant_arg(type, udp_optname_to_int, "unknown UDP control message");
+ default:
+ return NUM2INT(type);
+ }
+ }
+ else {
+ switch (level) {
+ case SOL_SOCKET:
+ return constant_arg(type, scm_optname_to_int, "unknown UNIX control message");
+ default:
+ return NUM2INT(type);
+ }
}
}
+int
+shutdown_how_arg(VALUE how)
+{
+ /* convert SHUT_RD, SHUT_WR, SHUT_RDWR. */
+ return constant_arg(how, shutdown_how_to_int, "unknown shutdown argument");
+}
+
static void
sock_define_const(const char *name, int value, VALUE mConst)
{
diff --git a/ext/socket/mkconstants.rb b/ext/socket/mkconstants.rb
index 30cc90d47..d3058f11f 100644
--- a/ext/socket/mkconstants.rb
+++ b/ext/socket/mkconstants.rb
@@ -242,7 +242,8 @@ end
def_name_to_int("family_to_int", /\A(AF_|PF_)/, "AF_")
def_name_to_int("socktype_to_int", /\ASOCK_/, "SOCK_")
def_name_to_int("ipproto_to_int", /\AIPPROTO_/, "IPPROTO_")
-def_name_to_int("iplevel_to_int", /\A(SOL_SOCKET\z|IPPROTO_)/, /\A(SOL_|IPPROTO_)/)
+def_name_to_int("unknown_level_to_int", /\ASOL_SOCKET\z/, "SOL_")
+def_name_to_int("ip_level_to_int", /\A(SOL_SOCKET\z|IPPROTO_)/, /\A(SOL_|IPPROTO_)/)
def_name_to_int("so_optname_to_int", /\ASO_/, "SO_")
def_name_to_int("ip_optname_to_int", /\AIP_/, "IP_")
def_name_to_int("ipv6_optname_to_int", /\AIPV6_/, "IPV6_", "IPPROTO_IPV6")
diff --git a/ext/socket/rubysocket.h b/ext/socket/rubysocket.h
index efd91f662..ae21f2608 100644
--- a/ext/socket/rubysocket.h
+++ b/ext/socket/rubysocket.h
@@ -196,8 +196,8 @@ int family_arg(VALUE domain);
int socktype_arg(VALUE type);
int level_arg(int family, VALUE level);
int optname_arg(int family, int level, VALUE optname);
-int shutdown_how_arg(VALUE how);
int cmsg_type_arg(int family, int level, VALUE type);
+int shutdown_how_arg(VALUE how);
int rb_sock_getfamily(int sockfd);