aboutsummaryrefslogtreecommitdiffstats
path: root/ext/socket/socket.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-01 10:37:41 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-01 10:37:41 +0000
commit175561f8dd142d6db89bc6eb8054834da26ee0d9 (patch)
treef95572e1481880e2dfae4f3336eeb071fd3ab48a /ext/socket/socket.c
parent9787d4faaeff4fff798fff6803758f467cb72e7e (diff)
downloadruby-175561f8dd142d6db89bc6eb8054834da26ee0d9.tar.gz
* ext/socket/mkconstants.rb: generate family_to_str.
* ext/socket/socket.c (ipaddr): use family_to_str. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/socket.c')
-rw-r--r--ext/socket/socket.c30
1 files changed, 7 insertions, 23 deletions
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 61f72e7ea6..f6fe3955fb 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -981,6 +981,8 @@ sock_addrinfo(VALUE host, VALUE port, int socktype, int flags)
return sock_getaddrinfo(host, port, &hints);
}
+static char *family_to_str(int val);
+
static VALUE
ipaddr(struct sockaddr *sockaddr, int norevlookup)
{
@@ -988,32 +990,14 @@ ipaddr(struct sockaddr *sockaddr, int norevlookup)
VALUE ary;
int error;
char hbuf[1024], pbuf[1024];
+ char *name;
- switch (sockaddr->sa_family) {
- case AF_UNSPEC:
- family = rb_str_new2("AF_UNSPEC");
- break;
- case AF_INET:
- family = rb_str_new2("AF_INET");
- break;
-#ifdef INET6
- case AF_INET6:
- family = rb_str_new2("AF_INET6");
- break;
-#endif
-#ifdef AF_LOCAL
- case AF_LOCAL:
- family = rb_str_new2("AF_LOCAL");
- break;
-#elif AF_UNIX
- case AF_UNIX:
- family = rb_str_new2("AF_UNIX");
- break;
-#endif
- default:
+ name = family_to_str(sockaddr->sa_family);
+ if (name)
+ family = rb_str_new2(name);
+ else {
sprintf(pbuf, "unknown:%d", sockaddr->sa_family);
family = rb_str_new2(pbuf);
- break;
}
addr1 = Qnil;