Merge from mainline.
[official-gcc.git] / libjava / classpath / test / java.net / TestNameLookups.java
blob592d9e01f757307dc98bd78d96ea88ccaf54d38d
1 /* A class to test my java.net.InetAddress implementation */
3 import java.net.*;
5 public class TestNameLookups extends Object
7 public static void
8 main(String[] argv) throws UnknownHostException
10 InetAddress addr;
12 System.out.println("Started address lookup test");
14 /* Test local host */
15 try
17 addr = InetAddress.getLocalHost();
19 System.out.println("The local hostname is " + addr.getHostName() +
20 " with an IP address of " + addr.getHostAddress());
22 catch(UnknownHostException e)
24 System.out.println("WARNING: Can't resolve local hostname");
27 /* Test simple lookup by IP */
28 addr = InetAddress.getByName("18.159.0.42");
30 System.out.println("Looked up IP addres 18.159.0.42 and got back a " +
31 "hostname of " + addr.getHostName());
33 /* Test failed reverse lookup of IP */
34 addr = InetAddress.getByName("194.72.246.154");
36 System.out.println("Looked up IP addres 194.72.246.154 and got back a " +
37 "hostname of " + addr.getHostName());
39 /* Test mangled/invalid IP's */
40 try { addr = InetAddress.getByName("122.24.1."); }
41 catch (UnknownHostException e) {
42 System.out.println("Passed bad IP test 1");
45 try { addr = InetAddress.getByName("122.24.52"); }
46 catch (UnknownHostException e) {
47 System.out.println("Passed bad IP test 2");
50 try { addr = InetAddress.getByName("122.256.52.1"); }
51 catch (UnknownHostException e) {
52 System.out.println("Passed bad IP test 3");
55 /* Test simple lookup by name with external info */
56 addr = InetAddress.getByName("www.starnews.com");
57 System.out.println("Looked up host www.starnews.com and got back an " +
58 "IP address of " + addr.getHostAddress());
59 byte[] octets = addr.getAddress();
60 System.out.println("Raw Address Bytes: octet1=" + (int)octets[0] +
61 " octets2=" + (int)octets[1] + " octet3=" + (int)octets[2] +
62 " octets4=" + (int)octets[3]);
63 System.out.println("toString() returned: " + addr.toString());
64 System.out.println("isMulticastAddress returned: "
65 + addr.isMulticastAddress());
67 /* Test complex lookup */
68 System.out.println("Looking up all addresses for indiana.edu ...");
69 InetAddress[] list = InetAddress.getAllByName("indiana.edu");
70 for (int i = 0; i < list.length; i++)
72 addr = list[i];
74 System.out.println(" Hostname: " + addr.getHostName() +
75 " IP Address: " + addr.getHostAddress());
78 /* Test equality */
79 InetAddress addr1 = InetAddress.getByName("www.urbanophile.com");
80 InetAddress addr2 = InetAddress.getByName("www.urbanophile.com");
82 if (addr1.equals(addr2) && addr2.equals(addr1))
83 System.out.println("Passed equality test #1");
84 else
85 System.out.println("Failed equality test #1");
87 addr1 = InetAddress.getByName("www.ac.com");
88 addr2 = InetAddress.getByName("www.hungry.com");
90 if (!addr1.equals(addr2) && !addr2.equals(addr1))
91 System.out.println("Passed equality test #2");
92 else
93 System.out.println("Failed equality test #2");
95 /* Quick test to see if it looks like we're caching things */
96 addr1 = InetAddress.getByName("www.urbanophile.com");
97 System.out.println("Got " + addr1.getHostName() + " " + addr1.getHostAddress());
98 addr2 = InetAddress.getByName("www.hungry.com");
99 System.out.println("Got " + addr2.getHostName() + " " + addr2.getHostAddress());