changes: now Inference engine works fine with the EyeTracking benchmark.
[IRC.git] / Robust / src / ClassLibrary / InetAddress.java
1 public class InetAddress {
2   String hostname;
3   byte[] address;
4
5   public InetAddress(byte[] addr, String hostname) {
6     this.hostname=hostname;
7     this.address=addr;
8   }
9
10   public static InetAddress getByAddress(String host, byte[] addr) {
11     return new InetAddress(addr, host);
12   }
13
14   public static InetAddress getByName(String hostname) {
15     InetAddress[] addresses=getAllByName(hostname);
16     if (addresses != null)
17       return addresses[0];
18     else
19       return null;
20   }
21
22   public byte[] getAddress() {
23     return address;
24   }
25
26   public static InetAddress getLocalHost() {
27     return getByName("localhost");
28   }
29
30   public boolean equals(InetAddress ia) {
31     if (ia==null)
32       return false;
33     if (ia.address.length!=address.length)
34       return false;
35     for(int i=0; i<address.length; i++)
36       if (ia.address[i]!=address[i])
37         return false;
38     return true;
39   }
40
41   public static InetAddress[] getAllByName(String hostname) {
42     InetAddress[] addresses;
43
44     byte[][] iplist = InetAddress.getHostByName(hostname.getBytes());
45
46     if (iplist != null) {
47       addresses = new InetAddress[iplist.length];
48
49       for (int i = 0; i < iplist.length; i++) {
50         addresses[i] = new InetAddress(iplist[i], hostname);
51       }
52       return addresses;
53     } else
54       return null;
55   }
56
57   public static native byte[][] getHostByName(byte[] hostname);
58
59   public String toString() {
60     String h=hostname+" ";
61     for (int i=0; i<address.length; i++) {
62       if (i>0)
63         h+=".";
64       h+=(int)address[i];
65     }
66     return h;
67   }
68 }