📄 284.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>CTerm非常精华下载</title>
</head>
<body bgcolor="#FFFFFF">
<table border="0" width="100%" cellspacing="0" cellpadding="0" height="577">
<tr><td width="32%" rowspan="3" height="123"><img src="DDl_back.jpg" width="300" height="129" alt="DDl_back.jpg"></td><td width="30%" background="DDl_back2.jpg" height="35"><p align="center"><a href="http://apue.dhs.org"><font face="黑体"><big><big>apue</big></big></font></a></td></tr>
<tr>
<td width="68%" background="DDl_back2.jpg" height="44"><big><big><font face="黑体"><p align="center"> ● UNIX网络编程 (BM: clown) </font></big></big></td></tr>
<tr>
<td width="68%" height="44" bgcolor="#000000"><font face="黑体"><big><big><p align="center"></big></big><a href="http://cterm.163.net"><img src="banner.gif" width="400" height="60" alt="banner.gif"border="0"></a></font></td>
</tr>
<tr><td width="100%" colspan="2" height="100" align="center" valign="top"><br><p align="center">[<a href="index.htm">回到开始</a>][<a href="193.htm">上一层</a>][<a href="285.htm">下一篇</a>]
<hr><p align="left"><small>/* socks_v4.c, by Digger, for function fo socks version 4, reference socksv4 <br>
* standard document for more details */ <br>
<br>
#include <stdio.h> <br>
#include <string.h> <br>
#include <signal.h> <br>
#include <sys/types.h> <br>
#include <sys/socket.h> <br>
#include <sys/time.h> <br>
#include <sys/select.h> <br>
#include <netinet/in.h> <br>
#include <netdb.h> <br>
#include <unistd.h> <br>
#include <errno.h> <br>
#include "socks.h" <br>
<br>
extern int errno; <br>
extern u_char ver; /* socks version, 4 or 5 */ <br>
<br>
void reply_command_v4( int sockfd, <br>
u_char cmd, <br>
u_short dst_port, <br>
u_long l_dst_ip) <br>
{ <br>
u_char buf[32]; <br>
buf[0] = '\0'; <br>
buf[1] = cmd; <br>
memcpy(&buf[2], &dst_port, 2); <br>
memcpy(&buf[4], &l_dst_ip, 4); <br>
write_chars(sockfd, buf, 8); <br>
} <br>
<br>
int handle_command_v4(int sockfd) <br>
{ <br>
int i; <br>
u_char cmd; /* client command */ <br>
u_short dst_port; /* destination port */ <br>
struct in_addr dst_ip; /* destination host IP */ <br>
u_char userid[256]; /* user id */ <br>
struct sockaddr_in me_addr; <br>
int addr_len; <br>
u_char buf[64]; <br>
<br>
read_chars(sockfd, &cmd, 1); <br>
#ifdef DEBUG <br>
#ifdef DEBUG <br>
fprintf(stderr, "command: %u\n", cmd); <br>
#endif <br>
read_chars(sockfd, (u_char *)&dst_port, 2); <br>
#ifdef DEBUG <br>
fprintf(stderr, "dst_port: %u\n", ntohs(dst_port)); <br>
#endif <br>
read_chars(sockfd, (u_char *)&dst_ip, 4); <br>
#ifdef DEBUG <br>
fprintf(stderr, "dst_ip: %s\n", inet_ntoa(dst_ip)); <br>
#endif <br>
i = 0; <br>
while(1) { <br>
read_chars(sockfd, &userid[i], 1); <br>
if (userid[i] == '\0') break; <br>
} <br>
#ifdef DEBUG <br>
fprintf(stderr, "userid: %s\n", userid); <br>
#endif <br>
if (cmd != CONNECT && cmd != BIND) { <br>
reply_command_v4(sockfd, REQ_FAILED, dst_port, dst_ip.s_addr); <br>
close_and_exit(sockfd); <br>
} else if (cmd == CONNECT) { <br>
if (creat_connect_sock(dst_ip.s_addr, dst_port) == FALSE) { <br>
reply_command_v4(sockfd, REQ_REJECT_CNNT, <br>
dst_port, dst_ip.s_addr); <br>
close_and_exit(sockfd); <br>
} else { <br>
reply_command_v4(sockfd, REQ_GRANTED, <br>
dst_port, dst_ip.s_addr); <br>
} <br>
} else if (cmd == BIND) { <br>
if (creat_bind_sock(&dst_ip.s_addr, &dst_port) == FALSE) { <br>
reply_command_v4(sockfd, REQ_REJECT_CNNT, <br>
dst_port, dst_ip.s_addr); <br>
close_and_exit(sockfd); <br>
} else { <br>
reply_command_v4(sockfd, REQ_GRANTED, <br>
dst_port, dst_ip.s_addr); <br>
} <br>
if (wait_connect_in(&dst_ip.s_addr, &dst_port) == FALSE) { <br>
reply_command_v4(sockfd, REQ_REJECT_CNNT, <br>
dst_port, dst_ip.s_addr); <br>
close_and_exit(sockfd); <br>
<br>
} else { <br>
reply_command_v4(sockfd, REQ_GRANTED, <br>
dst_port, dst_ip.s_addr); <br>
} <br>
} <br>
} <br>
</small><hr>
<p align="center">[<a href="index.htm">回到开始</a>][<a href="193.htm">上一层</a>][<a href="285.htm">下一篇</a>]
<p align="center"><a href="http://cterm.163.net">欢迎访问Cterm主页</a></p>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -