ruby-changes:10079
From: akr <ko1@a...>
Date: Sat, 17 Jan 2009 15:03:59 +0900 (JST)
Subject: [ruby-changes:10079] Ruby:r21622 (trunk): * ext/socket/raddrinfo.c (make_inspectname): add a res argument to
akr 2009-01-17 15:03:42 +0900 (Sat, 17 Jan 2009) New Revision: 21622 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=21622 Log: * ext/socket/raddrinfo.c (make_inspectname): add a res argument to suppress numeric inspectname. (init_addrinfo_getaddrinfo): call make_inspectname here. (addrinfo_firstonly_new): follow make_inspectname change. (addrinfo_list_new): ditto. (addrinfo_initialize): follow init_addrinfo_getaddrinfo change. Modified files: trunk/ChangeLog trunk/ext/socket/raddrinfo.c Index: ChangeLog =================================================================== --- ChangeLog (revision 21621) +++ ChangeLog (revision 21622) @@ -1,3 +1,12 @@ +Sat Jan 17 15:01:22 2009 Tanaka Akira <akr@f...> + + * ext/socket/raddrinfo.c (make_inspectname): add a res argument to + suppress numeric inspectname. + (init_addrinfo_getaddrinfo): call make_inspectname here. + (addrinfo_firstonly_new): follow make_inspectname change. + (addrinfo_list_new): ditto. + (addrinfo_initialize): follow init_addrinfo_getaddrinfo change. + Sat Jan 17 14:52:27 2009 Tanaka Akira <akr@f...> * ext/socket/mkconstants.rb: don't cause an error for duplicate names. Index: ext/socket/raddrinfo.c =================================================================== --- ext/socket/raddrinfo.c (revision 21621) +++ ext/socket/raddrinfo.c (revision 21622) @@ -590,13 +590,16 @@ return res; } +static VALUE make_inspectname(VALUE node, VALUE service, struct addrinfo *res); + static void init_addrinfo_getaddrinfo(rb_addrinfo_t *rai, VALUE node, VALUE service, VALUE family, VALUE socktype, VALUE protocol, VALUE flags, - VALUE inspectname) + VALUE inspectnode, VALUE inspectservice) { struct addrinfo *res = call_getaddrinfo(node, service, family, socktype, protocol, flags, 1); VALUE canonname; + VALUE inspectname = rb_str_equal(node, inspectnode) ? Qnil : make_inspectname(inspectnode, inspectservice, res); canonname = Qnil; if (res->ai_canonname) { @@ -612,9 +615,26 @@ } static VALUE -make_inspectname(VALUE node, VALUE service) +make_inspectname(VALUE node, VALUE service, struct addrinfo *res) { VALUE inspectname = Qnil; + + if (res) { + char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV]; + int ret; + ret = rb_getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, + sizeof(hbuf), pbuf, sizeof(pbuf), + NI_NUMERICHOST|NI_NUMERICSERV); + if (ret == 0) { + if (TYPE(node) == T_STRING && strcmp(hbuf, RSTRING_PTR(node)) == 0) + node = Qnil; + if (TYPE(service) == T_STRING && strcmp(pbuf, RSTRING_PTR(service)) == 0) + service = Qnil; + else if (TYPE(service) == T_FIXNUM && atoi(pbuf) == FIX2INT(service)) + service = Qnil; + } + } + if (TYPE(node) == T_STRING) { inspectname = rb_str_dup(node); } @@ -648,7 +668,7 @@ struct addrinfo *res = call_getaddrinfo(node, service, family, socktype, protocol, flags, 0); - inspectname = make_inspectname(node, service); + inspectname = make_inspectname(node, service, res); canonname = Qnil; if (res->ai_canonname) { @@ -673,7 +693,7 @@ struct addrinfo *res = call_getaddrinfo(node, service, family, socktype, protocol, flags, 0); - inspectname = make_inspectname(node, service); + inspectname = make_inspectname(node, service, res); ret = rb_ary_new(); for (r = res; r; r = r->ai_next) { @@ -814,7 +834,7 @@ init_addrinfo_getaddrinfo(rai, numericnode, service, INT2NUM(i_pfamily ? i_pfamily : af), INT2NUM(i_socktype), INT2NUM(i_protocol), INT2NUM(flags), - rb_str_equal(numericnode, nodename) ? Qnil : make_inspectname(nodename, service)); + nodename, service); break; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/