柳田です。

08/03/20 に Nobuyoshi Nakada<nobu / ruby-lang.org> さんは書きました:
> どちらかというと、cygwinでwin32/resolv.rbを使っていることが疑問
> です。

これだと、今度は次のようなエラーになってしまいます。

irb(main):002:0> Resolv.getaddress("www.ruby-lang.org")
NameError: uninitialized constant Resolv::DNS::Config::Win32
        from /usr/local/lib/ruby/1.8/resolv.rb:788:in `default_config_hash'
        from /usr/local/lib/ruby/1.8/resolv.rb:805:in `lazy_initialize'
        from /usr/local/lib/ruby/1.8/resolv.rb:798:in `synchronize'
        from /usr/local/lib/ruby/1.8/resolv.rb:798:in `lazy_initialize'
        from /usr/local/lib/ruby/1.8/resolv.rb:332:in `lazy_initialize'
        from /usr/local/lib/ruby/1.8/resolv.rb:330:in `synchronize'
        from /usr/local/lib/ruby/1.8/resolv.rb:330:in `lazy_initialize'
        from /usr/local/lib/ruby/1.8/resolv.rb:489:in `each_resource'
        from /usr/local/lib/ruby/1.8/resolv.rb:391:in `each_address'
        from /usr/local/lib/ruby/1.8/resolv.rb:110:in `each_address'
        from /usr/local/lib/ruby/1.8/resolv.rb:109:in `each'
        from /usr/local/lib/ruby/1.8/resolv.rb:109:in `each_address'
        from /usr/local/lib/ruby/1.8/resolv.rb:87:in `getaddress'
        from /usr/local/lib/ruby/1.8/resolv.rb:38:in `getaddress'
        from (irb):2
        from /usr/local/lib/ruby/1.8/resolv.rb:1703


これは Config.default_config_hash で Win32::Resolv を参照しているからなのですが、
ここの cygwin チェックをはずすと今度は次のようになります。


% ruby -rresolv -e 'p Resolv.getaddress("www.ruby-lang.org")'
/usr/local/lib/ruby/1.8/resolv.rb:819:in `lazy_initialize': undefined
method `include?' for nil:NilClass (NoMethodError)
        from /usr/local/lib/ruby/1.8/resolv.rb:798:in `synchronize'
        from /usr/local/lib/ruby/1.8/resolv.rb:798:in `lazy_initialize'
        from /usr/local/lib/ruby/1.8/resolv.rb:332:in `lazy_initialize'
        from /usr/local/lib/ruby/1.8/resolv.rb:330:in `synchronize'
        from /usr/local/lib/ruby/1.8/resolv.rb:330:in `lazy_initialize'
        from /usr/local/lib/ruby/1.8/resolv.rb:489:in `each_resource'
        from /usr/local/lib/ruby/1.8/resolv.rb:391:in `each_address'
        from /usr/local/lib/ruby/1.8/resolv.rb:110:in `each_address'
        from /usr/local/lib/ruby/1.8/resolv.rb:109:in `each'
        from /usr/local/lib/ruby/1.8/resolv.rb:109:in `each_address'
        from /usr/local/lib/ruby/1.8/resolv.rb:87:in `getaddress'
        from /usr/local/lib/ruby/1.8/resolv.rb:38:in `getaddress'
        from -e:1

これは、Cygwin では(デフォルトでは) /etc/resolv.conf が存在しないために起こるようです。


Cygwin では、特に自分で作成していなければ
* /etc/hosts は存在する (C:\WINDOWS\system32\drivers\etc\hosts へのシンボリックリンクになっている)
* /etc/resolv.conf は存在しない (ネットワーク設定は Windows のものが使われているようです)
ということのようです。

これは、自分で /etc/resolv.conf を作成するのが筋なのでしょうか。

-- 
Kouhei Yanagita <yanagi at shakenbu.org>