comparison src/net/sourceforge/jsocks/ProxyMessage.java @ 349:205ee2873330

update jsocks to 2011-03-19
author Carl Byington <carl@five-ten-sg.com>
date Fri, 01 Aug 2014 11:23:10 -0700
parents 0ce5cc452d02
children
comparison
equal deleted inserted replaced
348:29076621bab0 349:205ee2873330
1 package net.sourceforge.jsocks; 1 package net.sourceforge.jsocks;
2 2
3 import java.io.IOException; 3 import java.io.IOException;
4 import java.io.InputStream; 4 import java.io.InputStream;
5 import java.io.OutputStream; 5 import java.io.OutputStream;
6 import java.io.DataInputStream;
6 import java.net.InetAddress; 7 import java.net.InetAddress;
7 import java.net.UnknownHostException; 8 import java.net.UnknownHostException;
8 9
9 /** 10 /**
10 Abstract class which describes SOCKS4/5 response/request. 11 Abstract class which describes SOCKS4/5 response/request.
11 */ 12 */
12 public abstract class ProxyMessage { 13 public abstract class ProxyMessage{
13 /** Host as an IP address */ 14 /** Host as an IP address */
14 public InetAddress ip = null; 15 public InetAddress ip=null;
15 /** SOCKS version, or version of the response for SOCKS4*/ 16 /** SOCKS version, or version of the response for SOCKS4*/
16 public int version; 17 public int version;
17 /** Port field of the request/response*/ 18 /** Port field of the request/response*/
18 public int port; 19 public int port;
19 /** Request/response code as an int*/ 20 /** Request/response code as an int*/
20 public int command; 21 public int command;
21 /** Host as string.*/ 22 /** Host as string.*/
22 public String host = null; 23 public String host=null;
23 /** User field for SOCKS4 request messages*/ 24 /** User field for SOCKS4 request messages*/
24 public String user = null; 25 public String user=null;
25 26
26 ProxyMessage(int command, InetAddress ip, int port) { 27 ProxyMessage(int command,InetAddress ip,int port){
27 this.command = command; 28 this.command = command;
28 this.ip = ip; 29 this.ip = ip;
29 this.port = port; 30 this.port = port;
30 } 31 }
31 32
32 ProxyMessage() { 33 ProxyMessage(){
33 } 34 }
34 35
35 36
36 /** 37 /**
37 Initialises Message from the stream. Reads server response from 38 Initialises Message from the stream. Reads server response from
38 given stream. 39 given stream.
39 @param in Input stream to read response from. 40 @param in Input stream to read response from.
40 @throws SocksException If server response code is not SOCKS_SUCCESS(0), or 41 @throws SocksException If server response code is not SOCKS_SUCCESS(0), or
41 if any error with protocol occurs. 42 if any error with protocol occurs.
42 @throws IOException If any error happens with I/O. 43 @throws IOException If any error happens with I/O.
43 */ 44 */
44 public abstract void read(InputStream in) 45 public abstract void read(InputStream in)
45 throws SocksException, 46 throws SocksException,
46 IOException; 47 IOException;
47 48
48 49
49 /** 50 /**
50 Initialises Message from the stream. Reads server response or client 51 Initialises Message from the stream. Reads server response or client
51 request from given stream. 52 request from given stream.
52 53
53 @param in Input stream to read response from. 54 @param in Input stream to read response from.
54 @param clinetMode If true read server response, else read client request. 55 @param clinetMode If true read server response, else read client request.
55 @throws SocksException If server response code is not SOCKS_SUCCESS(0) and 56 @throws SocksException If server response code is not SOCKS_SUCCESS(0) and
56 reading in client mode, or if any error with protocol occurs. 57 reading in client mode, or if any error with protocol occurs.
57 @throws IOException If any error happens with I/O. 58 @throws IOException If any error happens with I/O.
58 */ 59 */
59 public abstract void read(InputStream in, boolean client_mode) 60 public abstract void read(InputStream in,boolean client_mode)
60 throws SocksException, 61 throws SocksException,
61 IOException; 62 IOException;
62 63
63 64
64 /** 65 /**
65 Writes the message to the stream. 66 Writes the message to the stream.
66 @param out Output stream to which message should be written. 67 @param out Output stream to which message should be written.
67 */ 68 */
68 public abstract void write(OutputStream out)throws SocksException, 69 public abstract void write(OutputStream out)throws SocksException,
69 IOException; 70 IOException;
70 71
71 /** 72 /**
72 Get the Address field of this message as InetAddress object. 73 Get the Address field of this message as InetAddress object.
73 @return Host address or null, if one can't be determined. 74 @return Host address or null, if one can't be determined.
74 */ 75 */
75 public InetAddress getInetAddress() throws UnknownHostException { 76 public InetAddress getInetAddress() throws UnknownHostException{
76 return ip; 77 return ip;
77 } 78 }
78 79
79 80
80 /** 81 /**
81 Get string representaion of this message. 82 Get string representaion of this message.
82 @return string representation of this message. 83 @return string representation of this message.
83 */ 84 */
84 public String toString() { 85 public String toString(){
85 return 86 return
86 "Proxy Message:\n" + 87 "Proxy Message:\n"+
87 "Version:" + version + "\n" + 88 "Version:"+ version+"\n"+
88 "Command:" + command + "\n" + 89 "Command:"+ command+"\n"+
89 "IP: " + ip + "\n" + 90 "IP: "+ ip+"\n"+
90 "Port: " + port + "\n" + 91 "Port: "+ port+"\n"+
91 "User: " + user + "\n" ; 92 "User: "+ user+"\n" ;
92 } 93 }
93 94
94 //Package methods 95 //Package methods
95 ////////////////// 96 //////////////////
96 97
97 static final String bytes2IPV4(byte[] addr, int offset) { 98 static final String bytes2IPV4(byte[] addr,int offset){
98 String hostName = "" + (addr[offset] & 0xFF); 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 }
99 104
100 for (int i = offset + 1; i < offset + 4; ++i) 105 static final String bytes2IPV6(byte[] addr,int offset){
101 hostName += "." + (addr[i] & 0xFF); 106 //Have no idea how they look like!
102 107 return null;
103 return hostName; 108 }
104 }
105
106 static final String bytes2IPV6(byte[] addr, int offset) {
107 //Have no idea how they look like!
108 return null;
109 }
110 109
111 } 110 }