Mercurial > 510Connectbot
comparison src/net/sourceforge/jsocks/Socks5Message.java @ 352:2bc6805cbc91
update jsocks to 2011-03-19
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 01 Aug 2014 11:32:33 -0700 |
parents | 205ee2873330 |
children |
comparison
equal
deleted
inserted
replaced
351:1bf94d2bfafe | 352:2bc6805cbc91 |
---|---|
9 | 9 |
10 /** | 10 /** |
11 SOCKS5 request/response message. | 11 SOCKS5 request/response message. |
12 */ | 12 */ |
13 | 13 |
14 class Socks5Message extends ProxyMessage{ | 14 public class Socks5Message extends ProxyMessage{ |
15 /** Address type of given message*/ | 15 /** Address type of given message*/ |
16 public int addrType; | 16 public int addrType; |
17 | 17 |
18 byte[] data; | 18 byte[] data; |
19 | 19 |
48 }else | 48 }else |
49 addr = ip.getAddress(); | 49 addr = ip.getAddress(); |
50 | 50 |
51 addrType = addr.length == 4 ? SOCKS_ATYP_IPV4 | 51 addrType = addr.length == 4 ? SOCKS_ATYP_IPV4 |
52 : SOCKS_ATYP_IPV6; | 52 : SOCKS_ATYP_IPV6; |
53 | 53 |
54 data = new byte[6+addr.length]; | 54 data = new byte[6+addr.length]; |
55 data[0] = (byte) SOCKS_VERSION; //Version | 55 data[0] = (byte) SOCKS_VERSION; //Version |
56 data[1] = (byte) command; //Command | 56 data[1] = (byte) command; //Command |
57 data[2] = (byte) 0; //Reserved byte | 57 data[2] = (byte) 0; //Reserved byte |
58 data[3] = (byte) addrType; //Address type | 58 data[3] = (byte) addrType; //Address type |
59 | 59 |
60 //Put Address | 60 //Put Address |
61 System.arraycopy(addr,0,data,4,addr.length); | 61 System.arraycopy(addr,0,data,4,addr.length); |
62 //Put port | 62 //Put port |
63 data[data.length-2] = (byte)(port>>8); | 63 data[data.length-2] = (byte)(port>>8); |
64 data[data.length-1] = (byte)(port); | 64 data[data.length-1] = (byte)(port); |
78 | 78 |
79 //System.out.println("Doing ATYP_DOMAINNAME"); | 79 //System.out.println("Doing ATYP_DOMAINNAME"); |
80 | 80 |
81 addrType = SOCKS_ATYP_DOMAINNAME; | 81 addrType = SOCKS_ATYP_DOMAINNAME; |
82 byte addr[] = hostName.getBytes(); | 82 byte addr[] = hostName.getBytes(); |
83 | 83 |
84 data =new byte[7+addr.length]; | 84 data =new byte[7+addr.length]; |
85 data[0] = (byte) SOCKS_VERSION; //Version | 85 data[0] = (byte) SOCKS_VERSION; //Version |
86 data[1] = (byte) command; //Command | 86 data[1] = (byte) command; //Command |
87 data[2] = (byte) 0; //Reserved byte | 87 data[2] = (byte) 0; //Reserved byte |
88 data[3] = (byte) SOCKS_ATYP_DOMAINNAME; //Address type | 88 data[3] = (byte) SOCKS_ATYP_DOMAINNAME; //Address type |
107 IOException{ | 107 IOException{ |
108 this(in,true); | 108 this(in,true); |
109 } | 109 } |
110 | 110 |
111 /** | 111 /** |
112 Initialises Message from the stream. Reads server response or client | 112 Initialises Message from the stream. Reads server response or client |
113 request from given stream. | 113 request from given stream. |
114 | 114 |
115 @param in Input stream to read response from. | 115 @param in Input stream to read response from. |
116 @param clinetMode If true read server response, else read client request. | 116 @param clinetMode If true read server response, else read client request. |
117 @throws SocksException If server response code is not SOCKS_SUCCESS(0) and | 117 @throws SocksException If server response code is not SOCKS_SUCCESS(0) and |
118 reading in client mode, or if any error with protocol occurs. | 118 reading in client mode, or if any error with protocol occurs. |
119 @throws IOException If any error happens with I/O. | 119 @throws IOException If any error happens with I/O. |
137 read(in,true); | 137 read(in,true); |
138 } | 138 } |
139 | 139 |
140 | 140 |
141 /** | 141 /** |
142 Initialises Message from the stream. Reads server response or client | 142 Initialises Message from the stream. Reads server response or client |
143 request from given stream. | 143 request from given stream. |
144 | 144 |
145 @param in Input stream to read response from. | 145 @param in Input stream to read response from. |
146 @param clinetMode If true read server response, else read client request. | 146 @param clinetMode If true read server response, else read client request. |
147 @throws SocksException If server response code is not SOCKS_SUCCESS(0) and | 147 @throws SocksException If server response code is not SOCKS_SUCCESS(0) and |
148 reading in client mode, or if any error with protocol occurs. | 148 reading in client mode, or if any error with protocol occurs. |
149 @throws IOException If any error happens with I/O. | 149 @throws IOException If any error happens with I/O. |
245 "ATYP "+addrType+"\n"+ | 245 "ATYP "+addrType+"\n"+ |
246 "ADDR "+host+"\n"+ | 246 "ADDR "+host+"\n"+ |
247 "PORT "+port+"\n"; | 247 "PORT "+port+"\n"; |
248 return s; | 248 return s; |
249 } | 249 } |
250 | 250 |
251 | 251 |
252 /** | 252 /** |
253 *Wether to resolve hostIP returned from SOCKS server | 253 *Wether to resolve hostIP returned from SOCKS server |
254 *that is wether to create InetAddress object from the | 254 *that is wether to create InetAddress object from the |
255 *hostName string | 255 *hostName string |