📄 csdn_文档中心_socks.htm
字号:
the SOCKS server and sends a CONNECT request when<BR>it wants to
establish a connection to an application server. The
client<BR>includes in the request packet the IP address and the port
number of the<BR>destination host, and userid, in the following
format.<BR><BR> +----+----+----+----+----+----+----+----+----+----+....+----+<BR> ¦
VN ¦ CD ¦ DSTPORT ¦ DSTIP
¦ USERID
¦NULL¦<BR> +----+----+----+----+----+----+----+----+----+----+....+----+<BR>#
of bytes: 1 1
2
4 variable
1<BR><BR>VN is the SOCKS protocol version number and should be 4. CD
is the<BR>SOCKS command code and should be 1 for CONNECT request.
NULL is a byte<BR>of all zero bits.<BR><BR>The SOCKS server checks
to see whether such a request should be granted<BR>based on any
combination of source IP address, destination IP
address,<BR>destination port number, the userid, and information it
may obtain by<BR>consulting IDENT, cf. RFC 1413. If the
request is granted, the SOCKS<BR>server makes a connection to the
specified port of the destination host.<BR>A reply packet is sent to
the client when this connection is established,<BR>or when the
request is rejected or the operation fails.
<BR><BR> +----+----+----+----+----+----+----+----+<BR> ¦
VN ¦ CD ¦ DSTPORT ¦ DSTIP
¦<BR> +----+----+----+----+----+----+----+----+<BR>#
of bytes: 1 1
2
4<BR><BR>VN is the version of the reply code and should be 0. CD is
the result<BR>code with one of the following
values:<BR><BR> 90: request
granted<BR> 91: request rejected or
failed<BR> 92: request rejected becasue SOCKS
server cannot connect to<BR>
identd on the client<BR> 93: request rejected
because the client program and
identd<BR> report different
user-ids<BR><BR>The remaining fields are ignored.<BR><BR>The SOCKS
server closes its connection immediately after notifying<BR>the
client of a failed or rejected request. For a successful
request,<BR>the SOCKS server gets ready to relay traffic on both
directions. This<BR>enables the client to do I/O on its connection
as if it were directly<BR>connected to the application
server.<BR><BR><BR>2) BIND<BR><BR>The client connects to the SOCKS
server and sends a BIND request when<BR>it wants to prepare for an
inbound connection from an application server.<BR>This should only
happen after a primary connection to the application<BR>server has
been established with a CONNECT. Typically, this is part
of<BR>the sequence of actions:<BR><BR>-bind(): obtain a
socket<BR>-getsockname(): get the IP address and port number of the
socket<BR>-listen(): ready to accept call from the application
server<BR>-use the primary connection to inform the application
server of<BR>the IP address and the port number that it should
connect to.<BR>-accept(): accept a connection from the application
server<BR><BR>The purpose of SOCKS BIND operation is to support such
a sequence<BR>but using a socket on the SOCKS server rather than on
the client.<BR><BR>The client includes in the request packet the IP
address of the<BR>application server, the destination port used in
the primary connection,<BR>and the
userid.<BR><BR> +----+----+----+----+----+----+----+----+----+----+....+----+<BR> ¦
VN ¦ CD ¦ DSTPORT ¦ DSTIP
¦ USERID
¦NULL¦<BR> +----+----+----+----+----+----+----+----+----+----+....+----+<BR>#
of bytes: 1 1
2
4 variable
1<BR><BR>VN is again 4 for the SOCKS protocol version number. CD
must be 2 to<BR>indicate BIND request.<BR><BR>The SOCKS server uses
the client information to decide whether the<BR>request is to be
granted. The reply it sends back to the client has<BR>the same
format as the reply for CONNECT request,
i.e.,<BR><BR> +----+----+----+----+----+----+----+----+<BR> ¦
VN ¦ CD ¦ DSTPORT ¦ DSTIP
¦<BR> +----+----+----+----+----+----+----+----+<BR>#
of bytes: 1 1
2
4<BR><BR>VN is the version of the reply code and should be 0. CD is
the result<BR>code with one of the following
values:<BR><BR> 90: request
granted<BR> 91: request rejected or
failed<BR> 92: request rejected becasue SOCKS
server cannot connect to<BR>
identd on the client<BR> 93: request rejected
because the client program and
identd<BR> report different
user-ids.<BR><BR>However, for a granted request (CD is 90), the
DSTPORT and DSTIP fields<BR>are meaningful. In that case, the
SOCKS server obtains a socket to wait<BR>for an incoming connection
and sends the port number and the IP address<BR>of that socket to
the client in DSTPORT and DSTIP, respectively. If the<BR>DSTIP in
the reply is 0 (the value of constant INADDR_ANY), then
the<BR>client should replace it by the IP address of the SOCKS
server to which<BR>the cleint is connected. (This happens if the
SOCKS server is not a<BR>multi-homed host.) In the typical
scenario, these two numbers are<BR>made available to the application
client prgram via the result of the<BR>subsequent getsockname()
call. The application protocol must provide a<BR>way for these
two pieces of information to be sent from the client to<BR>the
application server so that it can initiate the connection,
which<BR>connects it to the SOCKS server rather than directly to the
application<BR>client as it normally would.<BR><BR>The SOCKS server
sends a second reply packet to the client when the<BR>anticipated
connection from the application server is established.<BR>The SOCKS
server checks the IP address of the originating host against<BR>the
value of DSTIP specified in the client's BIND request. If a
mismatch<BR>is found, the CD field in the second reply is set to 91
and the SOCKS<BR>server closes both connections. If the two
match, CD in the second<BR>reply is set to 90 and the SOCKS server
gets ready to relay the traffic<BR>on its two connections. From then
on the client does I/O on its connection<BR>to the SOCKS server as
if it were directly connected to the
application<BR>server.<BR><BR><BR><BR>For both CONNECT and BIND
operations, the server sets a time limit<BR>(2 minutes in current
CSTC implementation) for the establishment of its<BR>connection with
the application server. If the connection is still
not<BR>establiched when the time limit expires, the server closes
its connection<BR>to the client and gives
up.<BR>==============================================================================<BR> SOCKS
4A: A Simple Extension to SOCKS 4
Protocol<BR><BR> Ying-Da
Lee<BR> yingda@best.com
or yingda@esd.sgi.com<BR><BR>Please read SOCKS4.protocol first
for an description of the version 4<BR>protocol. This extension is
intended to allow the use of SOCKS on hosts<BR>which are not capable
of resolving all domain names.<BR><BR>In version 4, the client sends
the following packet to the SOCKS server<BR>to request a CONNECT or
a BIND
operation:<BR><BR> +----+----+----+----+----+----+----+----+----+----+....+----+<BR> ¦
VN ¦ CD ¦ DSTPORT ¦ DSTIP
¦ USERID
¦NULL¦<BR> +----+----+----+----+----+----+----+----+----+----+....+----+<BR>#
of bytes: 1 1
2
4 variable
1<BR><BR>VN is the SOCKS protocol version number and should be 4. CD
is the<BR>SOCKS command code and should be 1 for CONNECT or 2 for
BIND. NULL<BR>is a byte of all zero bits.<BR><BR>For version 4A, if
the client cannot resolve the destination host's<BR>domain name to
find its IP address, it should set the first three bytes<BR>of DSTIP
to NULL and the last byte to a non-zero value. (This
corresponds<BR>to IP address 0.0.0.x, with x nonzero. As decreed by
IANA -- The<BR>Internet Assigned Numbers Authority -- such an
address is inadmissible<BR>as a destination IP address and thus
should never occur if the client<BR>can resolve the domain name.)
Following the NULL byte terminating<BR>USERID, the client must sends
the destination domain name and termiantes<BR>it with another NULL
byte. This is used for both CONNECT and BIND requests.<BR><BR>A
server using protocol 4A must check the DSTIP in the request
packet.<BR>If it represent address 0.0.0.x with nonzero x, the
server must read<BR>in the domain name that the client sends in the
packet. The server<BR>should resolve the domain name and make
connection to the destination<BR>host if it can. <BR><BR>SOCKSified
sockd may pass domain names that it cannot resolve to<BR>the
next-hop SOCKS
server.<BR></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
<TABLE align=center bgColor=#006699 border=0 cellPadding=0 cellSpacing=0
width=770>
<TBODY>
<TR bgColor=#006699>
<TD align=middle bgColor=#006699 id=white><FONT
color=#ffffff>对该文的评论</FONT></TD>
<TD align=middle>
<SCRIPT src="CSDN_文档中心_SOCKS.files/readnum.htm"></SCRIPT>
</TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1
width=770>
<TBODY>
<TR>
<TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16
hspace=1 src="CSDN_文档中心_SOCKS.files/ico_pencil.gif" width=16>
</SPAN> limail <I>(2001-11-26 23:56:40)</I> </TD></TR>
<TR>
<TD bgColor=#ffffff colSpan=3 width=532><BR>我也想要一份。ljg_emails@sina.com
<BR></TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1
width=770>
<TBODY>
<TR>
<TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16
hspace=1 src="CSDN_文档中心_SOCKS.files/ico_pencil.gif" width=16>
</SPAN> musicbug <I>(2001-10-27 0:26:51)</I>
</TD></TR>
<TR>
<TD bgColor=#ffffff colSpan=3 width=532><BR>有sock5 client
SDK吗?若有发给我vc@sina.com. 多谢. <BR></TD></TR></TBODY></TABLE><BR>
<DIV align=center>
<TABLE align=center bgColor=#cccccc border=0 cellPadding=2 cellSpacing=1
width=770>
<TBODY>
<TR>
<TH bgColor=#006699 id=white><FONT
color=#ffffff>我要评论</FONT></TH></TR></TBODY></TABLE></DIV>
<DIV align=center>
<TABLE border=0 width=770>
<TBODY>
<TR>
<TD>你没有登陆,无法发表评论。 请先<A
href="http://www.csdn.net/member/login.asp?from=/Develop/read_article.asp?id=3522">登陆</A>
<A
href="http://www.csdn.net/expert/zc.asp">我要注册</A><BR></TD></TR></TBODY></TABLE></DIV><BR>
<HR noShade SIZE=1 width=770>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=500>
<TBODY>
<TR align=middle>
<TD height=10 vAlign=bottom><A
href="http://www.csdn.net/intro/intro.asp?id=2">网站简介</A> - <A
href="http://www.csdn.net/intro/intro.asp?id=5">广告服务</A> - <A
href="http://www.csdn.net/map/map.shtm">网站地图</A> - <A
href="http://www.csdn.net/help/help.asp">帮助信息</A> - <A
href="http://www.csdn.net/intro/intro.asp?id=2">联系方式</A> - <A
href="http://www.csdn.net/english">English</A> </TD>
<TD align=middle rowSpan=3><A
href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010"><IMG
border=0 height=48 src="CSDN_文档中心_SOCKS.files/biaoshi.gif"
width=40></A></TD></TR>
<TR align=middle>
<TD vAlign=top>百联美达美公司 版权所有 京ICP证020026号</TD></TR>
<TR align=middle>
<TD vAlign=top><FONT face=Verdana>Copyright © CSDN.net, Inc. All rights
reserved</FONT></TD></TR>
<TR>
<TD height=15></TD>
<TD></TD></TR></TBODY></TABLE></DIV>
<DIV></DIV><!--内容结束//--><!--结束//--></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -