blob: 8d16c46c6b30ca0d8c887c60c32218edc9c372b6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/*************************************************
*
* = PACKAGE
* JACE.SOCK_SAP
*
* = FILENAME
* INETAddr.java
*
*@author Chris Cleeland
*
*************************************************/
package JACE.SOCK_SAP;
import java.io.*;
import java.net.*;
import JACE.OS.*;
/**
* <hr>
* <p><b>TITLE</b><br>
* Defines an endpoint of a connection, encapsulating host and port.
* This is only a part-way implementation of C++ ACE's ACE_INET_Addr.
*
* <p><b>LIMITATIONS</b><br>
* Currently the class is very limited in its capabilities; it will
* be expanded in future revisions of ACE.
*/
public class INETAddr // extends Addr
{
private InetAddress addr_;
private int port_ = 0;
/**
*/
public INETAddr ()
{
// Do nothing constructor
}
/**
* Create an INETAddr from a port/hostname
*@param port port number to connect with server at
*@param hostname hostname of the server
*/
public INETAddr (int port, String hostname) throws UnknownHostException
{
super();
port_ = port;
addr_ = InetAddress.getByName(hostname);
// Should really use getAllByName(),
// but I don't think we do that in
// C++ ACE, even.
}
/**
* Create an INETAddr from an address.
* @param address an address in the form "ip-number:port-number", <em>e.g.</em> <pre>tango.cs.wustl.edu:1234</pre> or <pre>128.252.166.57:1234</pre>; if no ':' is present address is assumed to be <b>INADDR_ANY</b> and address contains only the port number
* @throws UnknownHostException
*/
public INETAddr (String address) throws UnknownHostException
{
int colon = address.indexOf(':');
if (colon != 0)
{
addr_ = InetAddress.getByName(address.substring(0, colon));
address = address.substring(colon+1);
}
port_ = Integer.parseInt(address);
}
/**
* Return the name of the host.
*/
public String getHostName()
{
return addr_.getHostName();
}
/**
* Return the dotted Internet address.
*/
public String getHostAddr()
{
return addr_.toString();
}
/**
* Return the port number.
*/
public int getPortNumber()
{
return port_;
}
public String toString()
{
return getHostAddr() + Integer.toString(port_);
}
}
|