📄 sockspacket.java
字号:
/*This file is part of Socks via HTTP.This package is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.Socks via HTTP is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with Socks via HTTP; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/// Title : SocksPacket.java// Version : 0.40// Copyright : Copyright (c) 2001// Author : Florent CUETO (fcueto@wanadoo.fr)// Description : Class containing the data of a socks packetpackage socks4;public class SocksPacket{ public static final int SOCKS4_REPLY_VERSION = 0; // Must be 0 public static final int SOCKS4_OK = 90; // request granted public static final int SOCKS4_KO = 91; // request rejected or failed public static final int SOCKS4_IDENTD_KO = 92; // request rejected because SOCKS server cannot connect to identd on the client public static final int SOCKS4_USERID_KO = 93; // request rejected because the client program and identd report different user-ids public int version; public int command; public int destPort; public String destIP; public String userId; public String dnsName = null; public SocksPacket() { super(); } public SocksPacket(byte[] tab) { version = b2i(tab[0]); command = b2i(tab[1]); destPort = 256 * b2i(tab[2]) + b2i(tab[3]); if ((tab[4] == 0) && (tab[5] == 0) && (tab[6] == 0)) { // SOCKS 4A destIP = "0.0.0." + b2i(tab[7]); int pos = -1; for (int i = 8; i < tab.length; i++) { if (tab[i] == 0) pos = i; } userId = new String(tab, 8, pos - 8); dnsName = new String(tab, pos + 1, tab.length - pos - 2); } else { // SOCKS 4 destIP = "" + b2i(tab[4]) + "." + b2i(tab[5]) + "." + b2i(tab[6]) + "." + b2i(tab[7]); userId = new String(tab, 8, tab.length - 8 - 1); dnsName = null; } /*Log.printLog("RECEIVED"); Log.printLog(toString());*/ } public byte[] toBytes() { String[] bytes = ServletSocks.stringSplit(destIP, ".", false); byte[] ret = new byte[8]; ret[0] = (byte)version; ret[1] = (byte)command; ret[2] = i2b(destPort / 256); ret[3] = i2b(destPort % 256); ret[4] = i2b(Integer.parseInt(bytes[0])); ret[5] = i2b(Integer.parseInt(bytes[1])); ret[6] = i2b(Integer.parseInt(bytes[2])); ret[7] = i2b(Integer.parseInt(bytes[3])); //for (int i = 0; i < 8; i++) Log.printLog("" + i + " : " + ret[i]); return(ret); } public String toString() { String ret = "SocksPacket\n"; ret += "version : " + version + "\n"; ret += "command : " + command + "\n"; ret += "destPort : " + destPort + "\n"; ret += "destIP : " + destIP + "\n"; ret += "userId : " + userId + "\n"; ret += "dnsName : " + dnsName + "\n"; return(ret); } public int b2i(byte b) { return (b < 0 ? 256 + b : b); } public byte i2b(int i) { return (i > 127 ? (byte)(i - 256) : (byte)i); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -