This commit was manufactured by cvs2svn to create tag 'buildscript'.
[IRC.git] /
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     return addresses[0];
17   }
18
19   public byte[] getAddress() {
20     return address;
21   }
22
23   public static InetAddress getLocalHost() {
24     return getByName("localhost");
25   }
26
27   public boolean equals(InetAddress ia) {
28     if (ia==null)
29       return false;
30     if (ia.address.length!=address.length)
31       return false;
32     for(int i=0; i<address.length; i++)
33       if (ia.address[i]!=address[i])
34         return false;
35     return true;
36   }
37
38   public static InetAddress[] getAllByName(String hostname) {
39     InetAddress[] addresses;
40
41     byte[][] iplist = InetAddress.getHostByName(hostname.getBytes());
42
43     addresses = new InetAddress[iplist.length];
44
45     for (int i = 0; i < iplist.length; i++) {
46       addresses[i] = new InetAddress(iplist[i], hostname);
47     }
48     return addresses;
49   }
50
51   public static native byte[][] getHostByName(byte[] hostname);
52
53   public String toString() {
54     String h=hostname+" ";
55     for (int i=0; i<address.length; i++) {
56       if (i>0)
57         h+=".";
58       h+=(int)address[i];
59     }
60     return h;
61   }
62 }