-
Bug
-
Resolution: Fixed
-
P5
-
1.1.4
-
beta
-
x86
-
windows_95
Name: joT67522 Date: 10/21/97
I've had a look through the bug parade section, but
couldn't find this one. Apologies if it's already
been reported. It's similar to bug #4026796,
but different. :)
The code below works as a simple finger client but
contains (debugging) lines to show what the problem
is. Basically, the number of aliases is correct,
the IP addresses (numeric) are correct but the names
of the hosts are incorrect and are the same as that
passed to the InetAddress.getAllByName method.
For example, here at Lancaster, we have
unix.lancs.ac.uk
aliased to
unixa.lancs.ac.uk
unixb.lancs.ac.uk
unixc.lancs.ac.uk
Providing, for example, ###@###.###
returns 3 hosts of name unix.lancs.ac.uk, but the
numeric addresses are OK.
eg,
>java FingerClient sherratt@unix
# Hosts: 3
Host #0: unix/148.88.16.114
Host #1: unix/148.88.16.115
Host #2: unix/148.88.16.116
If that makes sense? :) Looks like the hostnames
are not being copied properly.
Regards,
Kev.
Full Source Follows.
--8<--
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.io.IOException;
import java.net.UnknownHostException;
public class FingerClient {
// Class variables and defines
public static final int FINGER_PORT = 79;
// Instance variables
private Socket socket = null; // our connection mechanism
public static void main (String[] args) {
// check we have the correct number of args
if (args.length == 0) {
System.err.println ("Usage: java FingerClient <username>@<host>");
System.exit (1);
} // if no args
// create a new client and look up the user
FingerClient f = new FingerClient ();
try {
String info = f.lookup (args[0]);
System.out.println (info);
} catch (Exception e) { // catch all exceptions
System.err.println ("Exception: " + e.toString ());
} // catch any exception
} // void main
public String lookup (String request)
throws IOException, UnknownHostException {
StringBuffer info = new StringBuffer ();
String hostname = null;
String username = null;
// obtain the index of '@'
int index = request.indexOf ('@');
if (index == -1)
return ("No host separator");
// split the username and hostname
username = request.substring (0, index) + "\r\n"; // CRLF
hostname = request.substring (++index);
InetAddress[] host = InetAddress.getAllByName (hostname);
info.append ("[" + host[0].getHostName () + "]\n");
System.out.println ("# Hosts: " + host.length);
for (int i = 0; i < host.length; i++)
System.out.println ("Host #" + i + ": " + host[i].getHostName () + "/" + host[i].getHostAddress ());
// connect to the host -- no getservbyname() equivalent in Java.
socket = new Socket (hostname, FINGER_PORT);
// send the request
OutputStreamWriter output = new OutputStreamWriter (socket.getOutputStream ());
output.write (username, 0, username.length ());
output.flush ();
// obtain the result
InputStreamReader input = new InputStreamReader (socket.getInputStream ());
char[] data = new char[1024]; // temporary buffer
int number = 0; // how many chars read
while ((number = input.read (data, 0, data.length)) != -1)
info.append (data, 0, number);
// clean up before returning
socket.close ();
return (info.toString ());
} // boolean lookup
} // class FingerClientsync
======================================================================