[ruby-trunk - Feature #5959][Assigned] Addrinfo#inspectname

Issue #5959 has been reported by Yui NARUSE.


Feature #5959: Addrinfo#inspectname
https://bugs.ruby-lang.org/issues/5959

Author: Yui NARUSE
Status: Assigned
Priority: Normal
Assignee: Akira T.
Category:
Target version:

Addrinfo の導入によって、Socket.getaddrinfo での正引き結果がオブジェクト化され、
元のホスト名を inspect で見れるようになってとても便利になったわけですが、
現在この元のホスト名をとりだす API がありません。

ホスト名とIP アドレスをセットで扱うのに、つまり解決済みの名前とアドレスの組を扱うのに Addrinfo って便利なので、
ホスト名を取り出す API が欲しいです。
現在の C での名前、inspectname か hostname あたりでどうでしょう。

Addrinfo $B$NF3F~$K$h$C$F!"(BSocket.getaddrinfo
[email protected]$-7k2L$,%*%V%8%’%/%H2=$5$l!"(B
$B85$N%[%9%HL>$r(B inspect
$B$G8+$l$k$h$&$K$J$C$F$H$F$bJXMx$K$J$C$?$o$1$G$9$,!"(B
$B8=:_$3$N85$N%[%9%HL>[email protected]$9(B API $B$,$"$j$^$;$s!#(B

$B%[%9%HL>$H(BIP
$B%"%I%l%9$r%;%C%H$G07$&$N$K!"$D$^$j2r7h:Q$$NL>A0$H%"%I%l%9$NAH$r07$&$N$K(B
Addrinfo $B$C$FJXMx$J$N$G!"(B
$B%[%9%HL>$r<h$j=P$9(B API $B$,M
$7$$$G$9!#(B
$B8=:_$N(B C $B$G$NL>A0!"(Binspectname $B$+(B hostname
$B$"$?$j$G$I$&$G$7$g$&!#(B

inspectname
$B$O$"$+$i$5$^$K!"(Binspect$BMQ$H$$$&%K%e%"%s%9$r46$8$k$N$G$=$l0J30$,$$$$$J$"!&!&!&(B
$BDs0F<+BN$K$OFC$K%3%a%s%H$O$J$/$F%K%e!<%H%i%k$G$9(B

2012$BG/(B2$B7n(B2$BF|(B17:16 Yui NARUSE [email protected]:

Addrinfo $B$NF3F~$K$h$C$F!"(BSocket.getaddrinfo
[email protected]$-7k2L$,%*%V%8%’%/%H2=$5$l!"(B
$B85$N%[%9%HL>$r(B inspect
$B$G8+$l$k$h$&$K$J$C$F$H$F$bJXMx$K$J$C$?$o$1$G$9$,!"(B
$B8=:_$3$N85$N%[%9%HL>[email protected]$9(B API $B$,$"$j$^$;$s!#(B

$B%[%9%HL>$H(BIP
$B%"%I%l%9$r%;%C%H$G07$&$N$K!"$D$^$j2r7h:Q$$NL>A0$H%"%I%l%9$NAH$r07$&$N$K(B
Addrinfo $B$C$FJXMx$J$N$G!"(B
$B%[%9%HL>$r<h$j=P$9(B API $B$,M
$7$$$G$9!#(B
$B8=:_$N(B C $B$G$NL>A0!"(Binspectname $B$+(B hostname
$B$"$?$j$G$I$&$G$7$g$&!#(B

inspectname $B$O%[%9%HL>$G$O$"$j$^$;$s!#(B

$B%I%-%e%a%s%H$NNc$K(B

  • Addrinfo.getaddrinfo(“www.kame.net”, 80, nil, :STREAM)
  • #=> [#<Addrinfo: 203.178.141.194:80 TCP (www.kame.net:80)>,
  • #<Addrinfo: [2001:200:0:8002:203:47ff:fea5:3085]:80 TCP

(www.kame.net:80)>]

$B$H$$$&$H$3$m$N(B www.kame.net:80
$B$H$$$&$h$&$K!"%]!<%H$,$D$/$3$H$b$"$j$^$9!#(B
($B$$$^F0$+$9$H$J$<$+$D$-$^$;$s$,!"$=$l$O0U?^$;$6$kF0:n$G$9!#(B)

inspectname [email protected]@.$7$?$H$-$N>pJs$r(B inspect
$B$N$?$a$K$o$+$j$d$9$$$h$&$K(B
$B;D$7$F$*$/!"$H$$$&$N$,0U?^$G$9!#(B

$B$^$?!"(BAddrinfo
[email protected]@.;~$K$OI,$:$7$b%[%9%HL>$,B8:_$9$k$H$O8B$i$J$$$h$&$K;W$$$^$9!#(B

2012$BG/(B2$B7n(B2$BF|(B18:12 Tanaka A. [email protected]:

$B$H$$$&$H$3$m$N(B www.kame.net:80
$B$H$$$&$h$&$K!"%]!<%H$,$D$/$3$H$b$"$j$^$9!#(B
($B$$$^F0$+$9$H$J$<$+$D$-$^$;$s$,!"$=$l$O0U?^$;$6$kF0:n$G$9!#(B)

$B$$C$H!"$3$l$O0U?^E$G$7$?!#(B:80
$B$,%"%I%l%9$NItJ,$K$9$G$KI=<($5$l$F$$$F!"(B
$B>iD9$J$N$G:o$C$?$G$7$?!#(B

“http” $B$K;XDj$9$l$P!"(Binspectname
$B$,%[%9%HL>$=$N$b$N$G$J$$Nc$K$J$j$^$9!#(B

% ./ruby -rsocket -rpp -e ‘pp Addrinfo.getaddrinfo(“www.kame.net”,
“http”, nil, :STREAM)’
[#<Addrinfo: 203.178.141.194:80 TCP (www.kame.net:http)>,
#<Addrinfo: [2001:200:dff:fff1:216:3eff:feb1:44d7]:80 TCP
(www.kame.net:http)>]

$B$D$^$j!“[email protected]$OF1$8$G!”(Binspectname $B$O$*K>$_$N$b$N$G$O$"$j$^$;$s!#(B

2012$BG/(B2$B7n(B2$BF|(B19:13 NARUSE, Yui [email protected]:

$B$J$k$[$I!"$J$i$P$o$?$7$,M_$7$$$N$O!V(Binspectname$B$N0lIt!W$G$9$M!#(B
$B:[email protected]$1$N$h$&$KJ9$3$($^$9!#(B

$B:o$l$P$$$$$N$J$i!"(Binspect $B$r;H$&$N$O$I$&$G$7$g$&$+!#(B

inspectname [email protected]$O!“L>A0$+$iN`?d$G$-$k$h$&$K!”(Binspect
$B$HF1DxEY$N8+9~$_$G$9!#(B

(2012/02/02 18:33), Tanaka A. wrote:

[#<Addrinfo: 203.178.141.194:80 TCP (www.kame.net:http)>,
#<Addrinfo: [2001:200:dff:fff1:216:3eff:feb1:44d7]:80 TCP
(www.kame.net:http)>]

$B$D$^$j!“[email protected]$OF1$8$G!”(Binspectname $B$O$*K>$_$N$b$N$G$O$"$j$^$;$s!#(B

$B$J$k$[$I!"$J$i$P$o$?$7$,M_$7$$$N$O!V(Binspectname$B$N0lIt!W$G$9$M!#(B
$B:[email protected]$1$N$h$&$KJ9$3$($^$9!#(B

inspectname [email protected]@.$7$?$H$-$N>pJs$r(B inspect $B$N$?$a$K$o$+$j$d$9$$$h$&$K(B
$B;D$7$F$*$/!"$H$$$&$N$,0U?^$G$9!#(B

$B$^$?!"(BAddrinfo
[email protected]@.;~$K$OI,$:$7$b%[%9%HL>$,B8:_$9$k$H$O8B$i$J$$$h$&$K;W$$$^$9!#(B

$B$^[email protected]@.$7$?$H$-$N>pJs$,M_$7$$$N$G!"$3$A$i$b$=$l$G9=$$$^$;$s!#(B
$B%[%9%HL>$,B8:_$7$J$$>l9g$O(B nil $B$G$$$$$s$8$c$J$$$G$7$g$&$+!#(B

2012$BG/(B2$B7n(B5$BF|(B23:06 NARUSE, Yui [email protected]:

$B8=>u$G$O(B ad hoc $B$K$=$&$d$C$F$k$s$G$9$,!"(BAPI
$B$K$J$C$F$$$J$$$HB>$r$$$8$j$E$i$$$s$G$9$h$M!#(B
$B0J2<$N$h$&$J$3$H$r$d$j$?$$$s$G$9$,!#(B

$B$3$l$C$F!“A0$K!”(Bnet/http $B$K(B ipaddr: $B$r2C$($h$&$H$7$?!"(B
[ruby-dev:44368] $B$N:FD)@o$G$9$+$M!#(B

$B!VB>$r$$$8$k!W$H$$$&$N$N!VB>!W$,$"$^[email protected]$G$O$"$j$^$;$s$,!"(B
$B!V(Bnet/http $B$r$$$8$k!W$H$$$&0UL#$G$7$g$&$+!#(B

http proxy $B$rDL$9>l9g$O(B IP $B%"%I%l%9$r;XDj$G$-$J$$$N$G!"(B
net/http
$B%l%Y%[email protected]_Dj$O$"$^$jE,@Z$8$c$J$$$s$8$c$J$$$+$J$!!"$H;W$C$F$$$^$9!#(B

(2012/02/05 21:23), Tanaka A. wrote:

2012$BG/(B2$B7n(B2$BF|(B19:13 NARUSE, Yui [email protected]:

$B$J$k$[$I!"$J$i$P$o$?$7$,M_$7$$$N$O!V(Binspectname$B$N0lIt!W$G$9$M!#(B
$B:[email protected]$1$N$h$&$KJ9$3$($^$9!#(B

$B:o$l$P$$$$$N$J$i!"(Binspect $B$r;H$&$N$O$I$&$G$7$g$&$+!#(B

inspectname [email protected]$O!“L>A0$+$iN`?d$G$-$k$h$&$K!”(Binspect
$B$HF1DxEY$N8+9~$_$G$9!#(B

$B8=>u$G$O(B ad hoc $B$K$=$&$d$C$F$k$s$G$9$,!"(BAPI
$B$K$J$C$F$$$J$$$HB>$r$$$8$j$E$i$$$s$G$9$h$M!#(B
$B0J2<$N$h$&$J$3$H$r$d$j$?$$$s$G$9$,!#(B
$B$=$NL>A0$G0z$1$kA4$F$N%5!<%P!<[email protected]$?$$!"$H!#(B

#!/usr/local/bin/ruby
require ‘net/http’
class Addrinfo
def to_str
inspect[/(([a-zA-Z-.]+)/, 1]
end
def +(a)
inspect[/(([a-zA-Z-.]+)/, 1] + a
end
end
class Net::HTTP
def conn_address
@address.is_a?(Addrinfo) ? @address.ip_address : @address
end
end
Addrinfo.getaddrinfo(‘rubyci.org’, ‘http’, nil, :STREAM).each do |ai|
p ai
p Net::HTTP.get_response(ai, ‘/’)
end

Issue #5959 has been updated by Yui NARUSE.

Status changed from Assigned to Rejected

並列動作を考えると libcurl 使ったほうが賢い気がしてきたので reject します

Feature #5959: Addrinfo#inspectname
https://bugs.ruby-lang.org/issues/5959

Author: Yui NARUSE
Status: Rejected
Priority: Normal
Assignee: Akira T.
Category:
Target version:

Addrinfo の導入によって、Socket.getaddrinfo での正引き結果がオブジェクト化され、
元のホスト名を inspect で見れるようになってとても便利になったわけですが、
現在この元のホスト名をとりだす API がありません。

ホスト名とIP アドレスをセットで扱うのに、つまり解決済みの名前とアドレスの組を扱うのに Addrinfo って便利なので、
ホスト名を取り出す API が欲しいです。
現在の C での名前、inspectname か hostname あたりでどうでしょう。

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs