请问这个类的源码大概是什么意思?java的
package socks;import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import server.RemoteServer;
import java.util.Arrays;
public class SocksConnectionRequest {
/*
* Data VER CMD RSV ATYP DST.ADDR SDT.PORT
* 1 1 1 1Variable 2
* 0501000100000000 1010
* 050100030962616964752E636F6D 0050
* */
private final static Logger logger = LoggerFactory.getLogger(SocksConnectionRequest.class);
private final byte[] data;
private byte version;
private byte cmd;
private byte rsv;
private byte atyp;
private String addr;
private int port;
private SocksConnectionRequest(byte[] data) {
this.data = data;
this.version = data;
this.cmd = data;
this.rsv = data;
this.atyp = data;
if (atyp == 0x01) { //ipv4
addr = bytesToIpv4(Arrays.copyOfRange(data, 4, data.length - 2));
} else if (atyp == 0x03) { //domain
addr = bytesToDomain(Arrays.copyOfRange(data, 5, data.length - 2));
} else if (atyp == 0x04) { //ipv6
addr = bytesToIpv6(Arrays.copyOfRange(data, 4, data.length - 2));
} else {
logger.error("unknown atyp: " + atyp);
}
port = (data & 0xFF) * 256 + (data & 0xFF);
}
private static boolean validate(byte[] data) {
if (data.length < 7) return false;
if (data != 0x05) return false;
if (data != 0x00) return false;
return data == 0x01 || data == 0x03 || data == 0x04;
}
public static SocksConnectionRequest fromBytes(byte[] data) {
if(validate(data)) {
return new SocksConnectionRequest(data);
} else {
return null;
}
}
public String getAddress() {
return addr;
}
public int getDstPort() {
return port;
}
private String bytesToIpv4(byte[] addrBytes) {
String ipv4AddrString = "";
for (byte addrByte : addrBytes) {
ipv4AddrString = ipv4AddrString.concat((addrByte & 0xFF) + ".");
}
return ipv4AddrString.substring(0, ipv4AddrString.length() - 1);
}
private String bytesToDomain(byte[] addrBytes) {
StringBuilder domainString = new StringBuilder(addrBytes.length);
for (byte addrByte : addrBytes) {
domainString.append((char) addrByte);
}
return domainString.toString();
}
private String bytesToIpv6(byte[] addrBytes) {
String ipv6AddrString = "";
for (byte addrByte : addrBytes) {
ipv6AddrString = ipv6AddrString.concat(String.valueOf(addrByte) + ":");
}
return ipv6AddrString.substring(0, ipv6AddrString.length() - 1);
}
}
一点都看不懂 为啥还有十六进制。。。 处理socks5的请求阶段
+----+-----+-------+-------+------------+-----------+
|VER | CMD |RSV |ATYP| DST.ADDR | DST.PORT |
+----+-----+-------+-------+------------+-----------+
| 1 | 1 |X'00'| 1 | Variable| 2 |
+----+-----+-------+-------+------------+-----------+
页:
[1]