Deprecate Socket.gethostbyaddr and Socket.gethostbyname
Is there a reason to keep these methods around? They were marked obsolete by POSIX.1-2001 and the POSIX.1-2008 removes the specifications of gethostbyname, gethostbyaddr recommending the use of getaddrinfo and getnameinfo instead. If they are kept because of Ruby backward compatibility, shouldn't they be re-implemented by these modern interfaces?
Updated by shevegen (Robert A. Heiler) almost 7 years ago
I have no pro or con opinion, just adding links for people who just want to click on stuff for the corresponding docu:
Updated by normalperson (Eric Wong) almost 7 years ago
If nothing else, I would consider right if documentation discouraged their use ...
I support documentation discouraging their use.
I'm against a warning message at runtime; that's just annoying
to non-programmers. Let's not break existing code or try to
force people into caring.
Updated by nobu (Nobuyoshi Nakada) almost 7 years ago
$ ruby -rsocket -e 'host = "ci.ruby-lang.org"; ai = Addrinfo.ip(host); p Socket.gethostbyname(host), Socket.getaddrinfo(host, nil), ai, ai.canonname' ["ci.ruby-lang.org", , 2, "4\xC0P\xDB"] [["AF_INET", 0, "188.8.131.52", "184.108.40.206", 2, 2, 17], ["AF_INET", 0, "220.127.116.11", "18.104.22.168", 2, 1, 6]] #<Addrinfo: 22.214.171.124 (ci.ruby-lang.org)> nil
Socket.gethostbyname returns the hostname, but
Addrinfo#inspect shows the name but it provides
Perhaps we need
Addrinfo#inspectname or something, before deprecating
Updated by shyouhei (Shyouhei Urabe) over 6 years ago
Is it difficult to implement our Socket.gethostbyname on top of getaddrinfo(3) ? I see no need to use gethostbyname(3) directly to provide the feature. If that is possible, I think we don't need to deprecate.
Updated by akr (Akira Tanaka) about 6 years ago
- Status changed from Open to Closed
Applied in changeset trunk|r60266.
Deprecation document for gethostbyname,gethostbyaddr.
I confirmed current ruby (Ruby 2.4 and trunk) uses
gethostbyname() and gethostbyaddr().
Socket.gethostbyname uses getaddrinfo() and gethostbyname().
Socket.gethostbyaddr uses gethostbyaddr().
Socket.gethostbyname uses gethostbyname() to obtain alias hostnames.
RFC 3493 defines getaddrinfo()/getnameinfo() and
describes the problems of gethostbyname()/gethostbyaddr().
The problems are difficult protocol handling and thread-unsafety.
Since Ruby has GVL, the thread-unsafety doesn't cause wrong result.
But it may block other threads until finishing DNS query.
Socket.gethostbyname has the protocol handling problem.
It returns only one address family:
% ruby -rpp -rsocket -e 'pp Socket.gethostbyname("www.wide.ad.jp")' ["www.wide.ad.jp", , 10, " \x01\x02\x00\r\xFF\xFF\xF1\x02\x16>\xFF\xFEKe\x1C", "\xCB\xB2\x89:"]
www.wide.ad.jp has one IPv6 address and one IPv4 address.
But Socket.gethostbyname returns only one address family, 10 (AF_INET6),
which is the address family of the first address.
Also, Socket.gethostbyname and Socket.gethostbyaddr uses
4-bytes binary IPv4 address and 16-bytes binary IPv6 address.
This is not usual in other socket API in Ruby.
(Most socket API uses binary sockaddr string or Addrinfo object)
I think Socket.gethostbyname and Socket.gethostbyaddr are too far
from recommendable API.
So, I added deprecation description for documents for them.