OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [test/] [java.net/] [TestNameLookups.java] - Blame information for rev 20

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* A class to test my java.net.InetAddress implementation */
2
 
3
import java.net.*;
4
 
5
public class TestNameLookups extends Object
6
{
7
public static void
8
main(String[] argv) throws UnknownHostException
9
{
10
  InetAddress addr;
11
 
12
  System.out.println("Started address lookup test");
13
 
14
  /* Test local host */
15
  try
16
    {
17
      addr = InetAddress.getLocalHost();
18
 
19
      System.out.println("The local hostname is " + addr.getHostName() +
20
                     " with an IP address of " + addr.getHostAddress());
21
    }
22
  catch(UnknownHostException e)
23
    {
24
      System.out.println("WARNING: Can't resolve local hostname");
25
    }
26
 
27
  /* Test simple lookup by IP */
28
  addr = InetAddress.getByName("18.159.0.42");
29
 
30
  System.out.println("Looked up IP addres 18.159.0.42 and got back a " +
31
                     "hostname of " + addr.getHostName());
32
 
33
  /* Test failed reverse lookup of IP */
34
  addr = InetAddress.getByName("194.72.246.154");
35
 
36
  System.out.println("Looked up IP addres 194.72.246.154 and got back a " +
37
                     "hostname of " + addr.getHostName());
38
 
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");
43
  }
44
 
45
  try { addr = InetAddress.getByName("122.24.52"); }
46
  catch (UnknownHostException e) {
47
    System.out.println("Passed bad IP test 2");
48
  }
49
 
50
  try { addr = InetAddress.getByName("122.256.52.1"); }
51
  catch (UnknownHostException e) {
52
    System.out.println("Passed bad IP test 3");
53
  }
54
 
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());
66
 
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++)
71
    {
72
      addr = list[i];
73
 
74
      System.out.println("   Hostname: " + addr.getHostName() +
75
                         " IP Address: " + addr.getHostAddress());
76
    }
77
 
78
  /* Test equality */
79
  InetAddress addr1 = InetAddress.getByName("www.urbanophile.com");
80
  InetAddress addr2 = InetAddress.getByName("www.urbanophile.com");
81
 
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");
86
 
87
  addr1 = InetAddress.getByName("www.ac.com");
88
  addr2 = InetAddress.getByName("www.hungry.com");
89
 
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");
94
 
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());
100
}
101
 
102
}
103
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.