1 package socks; 2 3 import java.io.IOException ; 4 import java.io.InputStream ; 5 import java.io.OutputStream ; 6 import java.io.DataInputStream ; 7 import java.net.InetAddress ; 8 import java.net.UnknownHostException ; 9 10 13 public abstract class ProxyMessage{ 14 15 public InetAddress ip=null; 16 17 public int version; 18 19 public int port; 20 21 public int command; 22 23 public String host=null; 24 25 public String user=null; 26 27 ProxyMessage(int command,InetAddress ip,int port){ 28 this.command = command; 29 this.ip = ip; 30 this.port = port; 31 } 32 33 ProxyMessage(){ 34 } 35 36 37 45 public abstract void read(InputStream in) 46 throws SocksException, 47 IOException ; 48 49 50 60 public abstract void read(InputStream in,boolean client_mode) 61 throws SocksException, 62 IOException ; 63 64 65 69 public abstract void write(OutputStream out)throws SocksException, 70 IOException ; 71 72 76 public InetAddress getInetAddress() throws UnknownHostException { 77 return ip; 78 } 79 80 81 85 public String toString(){ 86 return 87 "Proxy Message:\n"+ 88 "Version:"+ version+"\n"+ 89 "Command:"+ command+"\n"+ 90 "IP: "+ ip+"\n"+ 91 "Port: "+ port+"\n"+ 92 "User: "+ user+"\n" ; 93 } 94 95 98 static final String bytes2IPV4(byte[] addr,int offset){ 99 String hostName = ""+(addr[offset] & 0xFF); 100 for(int i = offset+1;i<offset+4;++i) 101 hostName+="."+(addr[i] & 0xFF); 102 return hostName; 103 } 104 105 static final String bytes2IPV6(byte[] addr,int offset){ 106 return null; 108 } 109 110 } 111 | Popular Tags |