diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-07-26 06:17:44 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-07-26 06:17:44 +0000 |
commit | a8e116b05eec96f250a6d4917c0d8b7a41e2bbb5 (patch) | |
tree | 41766b761125996b1b668cdde49b29c4bce0062a /ext/socket | |
parent | c932081ea8f9d106e8b87c938412654b3381cf09 (diff) | |
download | ruby-a8e116b05eec96f250a6d4917c0d8b7a41e2bbb5.tar.gz ruby-a8e116b05eec96f250a6d4917c0d8b7a41e2bbb5.tar.xz ruby-a8e116b05eec96f250a6d4917c0d8b7a41e2bbb5.zip |
* random.c: replace with Mersenne Twister RNG.
* eval.c (jump_tag_but_local_jump): preserve retval in
LocalJumpError exceptions.
* parse.y (command): no more check for "super outside of method".
* eval.c (rb_mod_define_method): should set last_class and
last_func in the block->frame.
* eval.c (error_handle): should handle TAG_THROW as well.
* parse.y (yylex): new decimal notation '0d4567'.
* parse.y (yylex): new octal notation '0o777'.
* parse.y (string_content): every string_content node should
return string only. use NODE_EVSTR to coercing.
* eval.c (rb_eval): NODE_EVSTR support.
* re.c (rb_reg_quote): avoid unnecessary string allocation.
* string.c (get_pat): quote metachracters before compiling a
string into a regex.
* string.c (rb_str_split_m): special treatment of strings of size
1, but AWK emulation. now uses get_pat().
* string.c (rb_str_match_m): quote metacharacters.
* string.c (rb_str_match2): ditto.
* ext/socket/socket.c (sock_addrinfo): make all 3 versions of
getaddrinfo happy. [ruby-core:00184]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@2655 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket')
-rw-r--r-- | ext/socket/socket.c | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/ext/socket/socket.c b/ext/socket/socket.c index d0e3b9b57..eb99695a9 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -548,6 +548,22 @@ mkinetaddr(host, buf, len) mkipaddr0((struct sockaddr*)&sin, buf, len); } +static int +str_isnumber(p) + const char *p; +{ + char *ep; + + if (!p || *p == '\0') + return 0; + ep = NULL; + (void)strtoul(p, &ep, 10); + if (ep && *ep == '\0') + return 1; + else + return 0; +} + static struct addrinfo* sock_addrinfo(host, port, socktype, flags) VALUE host, port; @@ -598,17 +614,16 @@ sock_addrinfo(host, port, socktype, flags) portp = RSTRING(port)->ptr; } - if (socktype == 0 && flags == 0) { - hintsp = 0; - } - else { - hintsp = &hints; - MEMZERO(&hints, struct addrinfo, 1); - hints.ai_family = PF_UNSPEC; - hints.ai_protocol = 0; - hints.ai_socktype = socktype; - hints.ai_flags = flags; + if (socktype == 0 && flags == 0 && str_isnumber(portp)) { + socktype = SOCK_DGRAM; } + + hintsp = &hints; + MEMZERO(&hints, struct addrinfo, 1); + hints.ai_family = PF_UNSPEC; + hints.ai_protocol = 0; + hints.ai_socktype = socktype; + hints.ai_flags = flags; error = getaddrinfo(hostp, portp, hintsp, &res); if (error) { if (hostp && hostp[strlen(hostp)-1] == '\n') { |