Methods Summary |
---|
public byte[] | getBytes()Answer the message's byte buffer.
return buffer;
|
public int | getCommandOrResult()Get the request's command or result.
return buffer[INDEX_COMMAND];
|
public java.lang.String | getErrorString(int error)Answer an error string corresponding to the given error value.
switch (error) {
case RETURN_FAILURE:
return Msg.getString("K00cd"); //$NON-NLS-1$
case RETURN_CANNOT_CONNECT_TO_IDENTD:
return Msg.getString("K00ce"); //$NON-NLS-1$
case RETURN_DIFFERENT_USER_IDS:
return Msg.getString("K00cf"); //$NON-NLS-1$
default:
return Msg.getString("K00d0"); //$NON-NLS-1$
}
|
public int | getIP()
return getInt32(INDEX_IP);
|
private int | getInt16(int offset)Get a 16 bit integer from the buffer at the offset given.
return (((buffer[offset] & 0xFF) << 8) + (buffer[offset + 1] & 0xFF));
|
private int | getInt32(int offset)Get a 32 bit integer from the buffer at the offset given.
return ((buffer[offset + 3] & 0xFF)
+ ((buffer[offset + 2] & 0xFF) << 8)
+ ((buffer[offset + 1] & 0xFF) << 16) + ((buffer[offset + 0] & 0xFF) << 24));
|
public int | getLength()Answer the total number of bytes used for the request. This method
searches for the end of the user id, then searches for the end of the
password and returns the final index as the requests length.
int index = 0;
// Look for the end of the user id.
for (index = INDEX_USER_ID; buffer[index] != 0; index++) {
/*
* Finds the end of the user id by searching for the null
* termination of the user id string.
*/
}
// Increment the index to include the NULL character in the length;
index++;
return index;
|
public int | getPort()Answer the request's port number.
return getInt16(INDEX_PORT);
|
private java.lang.String | getString(int offset, int maxLength)Get a String from the buffer at the offset given. The method reads until
it encounters a null value or reaches the maxLength given.
int index = offset;
int lastIndex = index + maxLength;
String result;
while (index < lastIndex && (buffer[index] != 0)) {
index++;
}
try {
result = new String(buffer, offset, index - offset, "ISO8859_1"); //$NON-NLS-1$
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e.toString());
}
return result;
|
public java.lang.String | getUserId()Answer the user id for authentication.
return getString(INDEX_USER_ID, MAX_USER_ID_LENGTH);
|
private int | getVersionNumber()Answer the SOCKS version number. Should always be 4.
return buffer[INDEX_VERSION];
|
public void | setCommandOrResult(int command)Set the request's command or result.
buffer[INDEX_COMMAND] = (byte) command;
|
public void | setIP(byte[] ip)Set the IP address. This expects an array of four bytes in host order.
buffer[INDEX_IP] = ip[0];
buffer[INDEX_IP + 1] = ip[1];
buffer[INDEX_IP + 2] = ip[2];
buffer[INDEX_IP + 3] = ip[3];
|
private void | setInt16(int offset, int value)Put a 16 bit integer into the buffer at the offset given.
buffer[offset] = (byte) (value >>> 8 & 0xFF);
buffer[offset + 1] = (byte) (value & 0xFF);
|
public void | setPort(int port)Set the request's port number.
setInt16(INDEX_PORT, port);
|
private void | setString(int offset, int maxLength, java.lang.String theString)Put a string into the buffer at the offset given.
byte[] stringBytes;
try {
stringBytes = theString.getBytes("ISO8859_1"); //$NON-NLS-1$
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e.toString());
}
int length = Math.min(stringBytes.length, maxLength);
System.arraycopy(stringBytes, 0, buffer, offset, length);
buffer[offset + length] = 0;
|
public void | setUserId(java.lang.String id)Set the user id for authentication.
setString(INDEX_USER_ID, MAX_USER_ID_LENGTH, id);
|
private void | setVersionNumber(int number)Set the SOCKS version number. This should always be 4.
buffer[INDEX_VERSION] = (byte) number;
|
public java.lang.String | toString()
StringBuilder buf = new StringBuilder(50);
buf.append("Version: ");
buf.append(Integer.toHexString(getVersionNumber()));
buf.append(" Command: ");
buf.append(Integer.toHexString(getCommandOrResult()));
buf.append(" Port: ");
buf.append(getPort());
buf.append(" IP: ");
buf.append(Integer.toHexString(getIP()));
buf.append(" User ID: ");
buf.append(getUserId());
return buf.toString();
|