Java DNS查询内部实现(2)

for (NameService nameService : nameServices) { try { /* * Do not put the call to lookup() inside the * constructor. if you do you will still be * allocating space when the lookup fails. */ addresses = nameService.lookupAllHostAddr(host); success = true; break; } catch (UnknownHostException uhe) { if (host.equalsIgnoreCase("localhost")) { InetAddress[] local = new InetAddress[] { impl.loopbackAddress() }; addresses = local; success = true; break; } else { addresses = unknown_array; success = false; ex = uhe; } } }

这是真正执行DNS查询的地方,而且可以看到是通过NameService链来依次解析的。其中nameServices是InetAddress的一个成员变量:

/* Used to store the name service provider */ private static List<NameService> nameServices = null;

通过static块进行初始化的:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/2502f6543a00bb6143a79c23ee2f39fb.html