大虾们有没有做proxy的资料!或给讲讲原理(100分)

  • 主题发起人 主题发起人 hpd
  • 开始时间 开始时间
H

hpd

Unregistered / Unconfirmed
GUEST, unregistred user!
自己要做一个proxy,请大虾们指点!
 
一直有个做proxy的念头,只是俗事缠身(可能我把上大富翁的时间用来做proxy会
绰绰有余 :-) )
其实原理比较简单,你做一个程序监听一个端口,当有请求传过来的时候, 你
分析请求后,重新转发就行了。
但实现起来并不很简单,比如你做一个支持HTTP的PROXY,首先你要对HTTP协议
要有所了解,(这个功能其实我大体已经试过,而且实现了);如果你还要支持其他
协议的话,那你还要对其他协议有所了解!
我在做http proxy的时候,遇到的一个最头疼的问题就是,如何很好的处理TServerSocket各种socket异常?(比如你在IE里按stop),所以你做程序如果解决
了这个问题,一定要告诉我哟!或者我们可以再共同探讨。
 
但是,我曾经见别人讨论proxy的时候,经常涉及到什么“sock4”,“sock5”
的东东,他们到底是什么呀?
 
proxy一般有两种, 不理解协议的和理解协议的.

不理解协议的代理只是简单地当一个传声筒, 理解协议的代理则是买卖中间人,
不过可不是为了捞好处, :).

Socks4/5属于不理解协议的代理. 用socks4/5的代理, 客户除了建立连接的工
作必须通过Socks代理, 其他的工作就和同原来需要访问的服务器直接打交道一
样处理. Socks4/5接收客户的连接请求之后, 客户会使用Socks协议告诉Socks
服务器需要连接的目的地址, Socks服务器自己去建立连接, 连好之后, 就把客
户发给Socks服务器的数据原封不动地发送出去, 外面的目标地址上发回来的东
西也原封不动地发给客户.你的软件相当于运行在了代理的那台机器上,

HTTP proxy则属于理解协议的代理, HTTP是它的专业. 这样的代理在客户端看
来是一个HTTP服务器: HTTP的命令它都能理解; 它同时又是一个HTTP的客户:
为了响应用户观看www.borland.com上面的Delphi 5发布的消息, 它自己必须
作为一个客户从www.borland.com的HTTP服务器那里把货买来, 然后转卖给自
己的客户. 如果又有其他客户想买同样的货, 这个代理私设了小仓库, 并且掌
握了先进的克隆技术, 只要货还没有变质(网页的内容有有效时间), 它就克隆
给你...

还有什么原理上不懂的尽管问我, 我是个网络技术 proxy! :)
 
to pegasus:
我正有一有关代理的事想请教,先在这里提问题请教,待会另开一新问题。
问题如下:
现在我是通过学校的代理服务器上网的,知道HTTP,FTP,SOCKS的地址和端口,
当我要从263.net上收取邮件时,不知道要如何编程。还有ftp也不能下载
校外的东西。当然在netscape里是行的,用netants就不行了,不知是否跟学校的
代理有关,如何编程。或请介绍技术资料。
 
pegasus老兄给点资料或者例子(c语言的也行)吧!多谢!
 
忘了,我的email:dph@126.com空间无限谢谢!
 
我可没什么见解。
 
我也在想知道有关内容,有消息请告诉我。
 
Hi, hpd!
好久没有上来,不知道你的要求。要是给我发信就好了。
现在还要么?

祝各位2000年好!
 
我也想知道,HTTP Proxy,和FTP Proxy有何不同之处。
 
同样感兴趣,希望得到有关的信息,My email is mikecool@263.net
 
以下地方有一个proxy的c原码
http://smth.org/SMTH2000/bbsanc?/groups/comp.faq/Winsock/yuanma/proxy
 
g622 提供的地址上不去,我提供一个实例,来自 <计算机世界日报>:
#include "stdafx.h"
#include "Proxy.h"
#include <winsock2.h> //WINSOCKET API 2。0
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////


#define HTTP "http://"
#define FTP "ftp://"
#define PROXYPORT 5001 //Proxy 端口
#define BUFSIZE 10240 //缓冲区大小


CWinApp theApp;

using namespace std;

UINT ProxyToServer(LPVOID pParam);
UINT UserToProxyThread(void *pParam);

struct SocketPair{
SOCKET user_proxy; //socket : 本地机器到PROXY 服务机
SOCKET proxy_server; //socket : PROXY 服务机到远程主机
BOOL IsUser_ProxyClosed; // 本地机器到PROXY 服务机状态
BOOL IsProxy_ServerClosed; // PROXY 服务机到远程主机状态
};


struct ProxyParam{
char Address[256]; // 远程主机地址
HANDLE User_SvrOK; // PROXY 服务机到远程主机的联结状态
SocketPair *pPair; // 维护一组SOCKET的指针
int Port; // 用来联结远程主机的端口
}; //这个结构用来PROXY SERVER与远程主机的信息交换.

SOCKET gListen_Socket; //用来侦听的SOCKET。

int StartServer() //启动服务
{
WSADATA wsaData;
sockaddr_in local;
SOCKET listen_socket;

if(::WSAStartup(0x202,&wsaData)!=0)
{printf("/nError in Startup session./n");WSACleanup();return -1;};

local.sin_family=AF_INET;
local.sin_addr.s_addr=INADDR_ANY;
local.sin_port=htons(PROXYPORT);

listen_socket=socket(AF_INET,SOCK_STREAM,0);
if(listen_socket==INVALID_SOCKET)
{printf("/nError in New a Socket.");WSACleanup();return -2;}

if(::bind(listen_socket,(sockaddr *)&local,sizeof(local))!=0)
{printf("/n Error in Binding socket."); WSACleanup();return -3; };

if(::listen(listen_socket,5)!=0)
{printf("/n Error in Listen."); WSACleanup(); return -4;}
gListen_Socket=listen_socket;
AfxBeginThread(UserToProxyThread,NULL); //启动侦听
return 1;
}

int CloseServer() //关闭服务
{
closesocket(gListen_Socket);
WSACleanup();
return 1;
}

//分析接收到的字符,得到远程主机地址
int GetAddressAndPort( char * str, char *address, int * port)
{
char buf[BUFSIZE], command[512], proto[128], *p;
int j;
sscanf(str,"%s%s%s",command,buf,proto);
p=strstr(buf,HTTP);
//HTTP
if(p)
{
p+=strlen(HTTP);
for(int i=0;i< strlen(p);i++)
if( *(p+i)=='/') break;
*(p+i)=0;
strcpy(address,p);
p=strstr(str,HTTP);
for(int j=0;j< i+strlen(HTTP);j++)
*(p+j)=' '; //去掉远程主机名: GET http://www.njust.edu.cn/ HTTP1.1 == > GET / HTTP1.1
*port=80; //缺省的 http 端口
}
else
{//FTP, 不支持, 下面的代码可以省略.
p=strstr(buf,FTP);
if(!p) return 0;
p+=strlen(FTP);
for(int i=0;i< strlen(p);i++)
if( *(p+i)=='/') break; //Get The Remote Host
*(p+i)=0;
for(j=0;j< strlen(p);j++)
if(*(p+j)==':')
{*port=atoi(p+j+1); //Get The Port
*(p+j)=0;
}
else *port=21;

strcpy(address,p);
p=strstr(str,FTP);
for(j=0;j< i+strlen(FTP);j++)
*(p+j)=' ';
}
return 1;
}

// 取到本地的数据,发往远程主机
UINT UserToProxyThread(void *pParam)
{
char Buffer[BUFSIZE];
int Len;
sockaddr_in from;
SOCKET msg_socket;
int fromlen,retval;
SocketPair SPair;
ProxyParam ProxyP;
CWinThread *pChildThread;
fromlen=sizeof(from);
msg_socket=accept(gListen_Socket,(struct sockaddr*)&from,&fromlen);
AfxBeginThread(UserToProxyThread,pParam); //启动另一侦听.
if( msg_socket==INVALID_SOCKET)
{ printf( "/nError in accept "); return -5;}

//读客户的第一行数据

SPair.IsUser_ProxyClosed=FALSE;
SPair.IsProxy_ServerClosed=TRUE;
SPair.user_proxy=msg_socket;

retval=recv(SPair.user_proxy,Buffer,sizeof(Buffer),0);

if(retval==SOCKET_ERROR)
{ printf("/nError Recv");
if(SPair.IsUser_ProxyClosed==FALSE)
{closesocket(SPair.user_proxy);
SPair.IsUser_ProxyClosed=TRUE;
}
}
if(retval==0)
{printf("Client Close connection/n");
if(SPair.IsUser_ProxyClosed==FALSE)
{closesocket(SPair.user_proxy);
SPair.IsUser_ProxyClosed=TRUE;
}
}
Len=retval;
#ifdef _DEBUG

Buffer[Len]=0;
printf("/n Received %d bytes,data[%s]from client/n",retval,Buffer);
#endif
//
SPair.IsUser_ProxyClosed=FALSE;
SPair.IsProxy_ServerClosed=TRUE;
SPair.user_proxy=msg_socket;

ProxyP.pPair=&SPair;
ProxyP.User_SvrOK=CreateEvent(NULL,TRUE,FALSE,NULL);

GetAddressAndPort( Buffer,ProxyP.Address,&ProxyP.Port);

pChildThread=AfxBeginThread(ProxyToServer,(LPVOID)&ProxyP);
::WaitForSingleObject(ProxyP.User_SvrOK,60000); //等待联结
::CloseHandle(ProxyP.User_SvrOK);

while(SPair.IsProxy_ServerClosed ==FALSE && SPair.IsUser_ProxyClosed==FALSE)
{
retval=send(SPair.proxy_server,Buffer,Len,0);
if(retval==SOCKET_ERROR)
{ printf("/n send() failed:error%d/n",WSAGetLastError());
if(SPair.IsProxy_ServerClosed==FALSE)
{
closesocket(SPair.proxy_server);
SPair.IsProxy_ServerClosed=TRUE;
}
continue;
}
retval=recv(SPair.user_proxy,Buffer,sizeof(Buffer),0);

if(retval==SOCKET_ERROR)
{ printf("/nError Recv");
if(SPair.IsUser_ProxyClosed==FALSE)
{closesocket(SPair.user_proxy);
SPair.IsUser_ProxyClosed=TRUE;
}
continue;
}
if(retval==0)
{printf("Client Close connection/n");
if(SPair.IsUser_ProxyClosed==FALSE)
{closesocket(SPair.user_proxy);
SPair.IsUser_ProxyClosed=TRUE;
}
break;
}
Len=retval;
#ifdef _DEBUG
Buffer[Len]=0;
printf("/n Received %d bytes,data[%s]from client/n",retval,Buffer);
#endif

} //End While

if(SPair.IsProxy_ServerClosed==FALSE)
{
closesocket(SPair.proxy_server);
SPair.IsProxy_ServerClosed=TRUE;
}
if(SPair.IsUser_ProxyClosed==FALSE)
{closesocket(SPair.user_proxy);
SPair.IsUser_ProxyClosed=TRUE;
}
::WaitForSingleObject(pChildThread- >m_hThread,20000); //Should check the return value
return 0;
}

// 读取远程主机数据,并发往本地客户机
UINT ProxyToServer(LPVOID pParam){
ProxyParam * pPar=(ProxyParam*)pParam;
char Buffer[BUFSIZE];
char *server_name= "localhost";
unsigned short port ;
int retval,Len;
unsigned int addr;
int socket_type ;
struct sockaddr_in server;
struct hostent *hp;
SOCKET conn_socket;

socket_type = SOCK_STREAM;
server_name = pPar- >Address;
port = pPar- >Port;

if (isalpha(server_name[0])) { /* server address is a name */
hp = gethostbyname(server_name);
}
else { /* Convert nnn.nnn address to a usable one */
addr = inet_addr(server_name);
hp = gethostbyaddr((char *)&addr,4,AF_INET);
}
if (hp == NULL ) {
fprintf(stderr,"Client: Cannot resolve address [%s]: Error %d/n",
server_name,WSAGetLastError());
::SetEvent(pPar- >User_SvrOK);
return 0;
}

//
// Copy the resolved information into the sockaddr_in structure
//
memset(&server,0,sizeof(server));
memcpy(&(server.sin_addr),hp- >h_addr,hp- >h_length);
server.sin_family = hp- >h_addrtype;
server.sin_port = htons(port);

conn_socket = socket(AF_INET,socket_type,0); /* 打开一个 socket */
if (conn_socket < 0 ) {
fprintf(stderr,"Client: Error Opening socket: Error %d/n",
WSAGetLastError());
pPar- >pPair- >IsProxy_ServerClosed=TRUE;
::SetEvent(pPar- >User_SvrOK);
return -1;
}


#ifdef _DEBUG
printf("Client connecting to: %s/n",hp- >h_name);
#endif
if (connect(conn_socket,(struct sockaddr*)&server,sizeof(server))
== SOCKET_ERROR) {
fprintf(stderr,"connect() failed: %d/n",WSAGetLastError());
pPar- >pPair- >IsProxy_ServerClosed=TRUE;
::SetEvent(pPar- >User_SvrOK);
return -1;
}
pPar- >pPair- >proxy_server=conn_socket;
pPar- >pPair- >IsProxy_ServerClosed=FALSE;
::SetEvent(pPar- >User_SvrOK);
// cook up a string to send
while(!pPar- >pPair- >IsProxy_ServerClosed &&!pPar- >pPair- >IsUser_ProxyClosed)
{
retval = recv(conn_socket,Buffer,sizeof (Buffer),0 );
if (retval == SOCKET_ERROR ) {
fprintf(stderr,"recv() failed: error %d/n",WSAGetLastError());
closesocket(conn_socket);
pPar- >pPair- >IsProxy_ServerClosed=TRUE;
break;
}
Len=retval;
if (retval == 0) {
printf("Server closed connection/n");
closesocket(conn_socket);
pPar- >pPair- >IsProxy_ServerClosed=TRUE;
break;
}

retval = send(pPar- >pPair- >user_proxy,Buffer,Len,0);
if (retval == SOCKET_ERROR) {
fprintf(stderr,"send() failed: error %d/n",WSAGetLastError());
closesocket(pPar- >pPair- >user_proxy);
pPar- >pPair- >IsUser_ProxyClosed=TRUE;
break;
}
#ifdef _DEBUG
Buffer[Len]=0;
printf("Received %d bytes, data [%s] from server/n",retval,Buffer);
#endif
}
if(pPar- >pPair- >IsProxy_ServerClosed==FALSE)
{
closesocket(pPar- >pPair- >proxy_server);
pPar- >pPair- >IsProxy_ServerClosed=TRUE;
}
if(pPar- >pPair- >IsUser_ProxyClosed==FALSE)
{closesocket(pPar- >pPair- >user_proxy);
pPar- >pPair- >IsUser_ProxyClosed=TRUE;
}
return 1;
}



int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

// 初始化SOCKET
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// 错误处理
cerr < < _T("Fatal Error: MFC initialization failed") < < endl;
nRetCode = 1;
}
else
{
// 主程序开始.
StartServer();
while(1)
if(getchar()=='q') break;
CloseServer();
}

return nRetCode;
}
 
上不去?
我贴......

发信人: stwzyang (hook), 信区: Winsock
标 题: Proxy source code
发信站: BBS 水木清华站 (Sat Jan 3 04:14:04 1998)


/****************************************************************************
program: proxyd
module: proxyd.c
summary: provides proxy tcp service for a host on an isolated network.

programmer: Carl Harris (ceharris@vt.edu)
date: 22 Feb 94

description:
This code implements a daemon process which listens for tcp connec-
tions on a specified port number. When a connection is established,
a child is forked to handle the new client. The child then estab-
lishes a tcp connection to a port on the isolated host. The child
then falls into a loop in which it writes data to the isolated host
for the client and vice-versa. Once a child has been forked, the
parent resumes listening for additional connections.

The name of the isolated host and the port to serve as proxy for,
as well as the port number the server listen on are specified as
command line arguments.
****************************************************************************/


#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include <netdb.h>


#define TCP_PROTO "tcp"

int proxy_port; /* port to listen for proxy connections on */
struct sockaddr_in hostaddr; /* host addr assembled from gethostbyname() */

extern int errno; /* defined by libc.a */
extern char *sys_errlist[]; /* defined by libc.a */


void parse_args (int argc, char **argv);
void daemonize (int servfd);
void do_proxy (int usersockfd);
void reap_status (void);
void errorout (char *msg);



/****************************************************************************
function: main
description: Main level driver. After daemonizing the process, a socket
is opened to listen for connections on the proxy port,
connections are accepted and children are spawned to handle
each new connection.
arguments:
argc,argv you know what those are.

return value: none.
calls: parse_args, do_proxy.
globals: reads proxy_port.
****************************************************************************/

main (argc,argv)
int argc;
char **argv;
{
int clilen;
int childpid;
int sockfd, newsockfd;
struct sockaddr_in servaddr, cliaddr;

parse_args(argc,argv);

/* prepare an address struct to listen for connections */
bzero((char *) &servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = proxy_port;

/* get a socket... */
if ((sockfd = socket(AF_INET,SOCK_STREAM,0)) < 0) {
fputs("failed to create server socket/r/n",stderr);
exit(1);
}

/* ...and bind our address and port to it */
if (bind(sockfd,(struct sockaddr_in *) &servaddr,sizeof(servaddr)) < 0) {
fputs("faild to bind server socket to specified port/r/n",stderr);
exit(1);
}

/* get ready to accept with at most 5 clients waiting to connect */
listen(sockfd,5);

/* turn ourselves into a daemon */
daemonize(sockfd);

/* fall into a loop to accept new connections and spawn children */
while (1) {

/* accept the next connection */
clilen = sizeof(cliaddr);
newsockfd = accept(sockfd, (struct sockaddr_in *) &cliaddr, &clilen);
if (newsockfd < 0 && errno == EINTR)
continue; /* a signal might interrupt our accept() call */
else if (newsockfd < 0)
/* something quite amiss -- kill the server */
errorout("failed to accept connection");

/* fork a child to handle this connection */
if ((childpid = fork()) == 0) {
close(sockfd);
do_proxy(newsockfd);
exit(0);
}

/* if fork() failed, the connection is silently dropped -- oops! */

close(newsockfd);
}
}



/****************************************************************************
function: parse_args
description: parse the command line args.
arguments:
argc,argv you know what these are.

return value: none.
calls: none.
globals: writes proxy_port, writes hostaddr.
****************************************************************************/

void parse_args (argc,argv)
int argc;
char **argv;
{
int i;
struct hostent *hostp;
struct servent *servp;
unsigned long inaddr;
struct {
char proxy_port [16];
char isolated_host [64];
char service_name [32];
} pargs;


if (argc < 4) {
printf("usage: %s <proxy-port> <host> <service-name|port-number>/r/n",
argv[0]);
exit(1);
}

strcpy(pargs.proxy_port,argv[1]);
strcpy(pargs.isolated_host,argv[2]);
strcpy(pargs.service_name,argv[3]);

for (i = 0; i < strlen(pargs.proxy_port); i++)
if (!isdigit(*(pargs.proxy_port + i)))
break;

if (i == strlen(pargs.proxy_port))
proxy_port = htons(atoi(pargs.proxy_port));
else {
printf("%s: invalid proxy port/r/n",pargs.proxy_port);
exit(0);
}

bzero(&hostaddr,sizeof(hostaddr));
hostaddr.sin_family = AF_INET;
if ((inaddr = inet_addr(pargs.isolated_host)) != INADDR_NONE)
bcopy(&inaddr,&hostaddr.sin_addr,sizeof(inaddr));
else if ((hostp = gethostbyname(pargs.isolated_host)) != NULL)
bcopy(hostp->h_addr,&hostaddr.sin_addr,hostp->h_length);
else {
printf("%s: unknown host/r/n",pargs.isolated_host);
exit(1);
}

if ((servp = getservbyname(pargs.service_name,TCP_PROTO)) != NULL)
hostaddr.sin_port = servp->s_port;
else if (atoi(pargs.service_name) > 0)
hostaddr.sin_port = htons(atoi(pargs.service_name));
else {
printf("%s: invalid/unknown service name or port number/r/n",
pargs.service_name);
exit(1);
}
}



/****************************************************************************
function: daemonize
description: detach the server process from the current context,
creating a pristine, predictable environment in which it
will execute.
arguments:
servfd file descriptor in use by server.

return value: none.
calls: none.
globals: none.
****************************************************************************/

void daemonize (servfd)
int servfd;
{
int childpid, fd, fdtablesize;

/* ignore terminal I/O, stop signals */
signal(SIGTTOU,SIG_IGN);
signal(SIGTTIN,SIG_IGN);
signal(SIGTSTP,SIG_IGN);

/* fork to put us in the background (whether or not the user
specified '&' on the command line */

if ((childpid = fork()) < 0) {
fputs("failed to fork first child/r/n",stderr);
exit(1);
}
else if (childpid > 0)
exit(0); /* terminate parent, continue in child */

/* dissociate from process group */
if (setpgrp(0,getpid()) < 0) {
fputs("failed to become process group leader/r/n",stderr);
exit(1);
}

/* lose controlling terminal */
if ((fd = open("/dev/tty",O_RDWR)) >= 0) {
ioctl(fd,TIOCNOTTY,NULL);
close(fd);
}

/* close any open file descriptors */
for (fd = 0, fdtablesize = getdtablesize(); fd < fdtablesize; fd++)
if (fd != servfd)
close(fd);

/* set working directory to / to allow filesystems to be unmounted */
chdir("/");

/* clear the inherited umask */
umask(0);

/* setup zombie prevention */
signal(SIGCLD,reap_status);

}



/****************************************************************************
function: do_proxy
description: does the actual work of virtually connecting a client to
the telnet service on the isolated host.
arguments:
usersockfd socket to which the client is connected.

return value: none.
calls: none.
globals: reads hostaddr.
****************************************************************************/

void do_proxy (usersockfd)
int usersockfd;
{
int isosockfd;
fd_set rdfdset;
int connstat;
int iolen;
char buf [2048];

/* open a socket to connect to the isolated host */
if ((isosockfd = socket(AF_INET,SOCK_STREAM,0)) < 0)
errorout("failed to create socket to host");

/* attempt a connection */
connstat = connect(isosockfd,
(struct sockaddr *) &hostaddr,
sizeof(hostaddr));
switch (connstat) {
case 0:
break;
case ETIMEDOUT:
case ECONNREFUSED:
case ENETUNREACH:
strcpy(buf,sys_errlist[errno]);
strcat(buf,"/r/n");
write(usersockfd,buf,strlen(buf));
close(usersockfd);
exit(1); /* die peacefully if we can't establish a connection */
break;
default:
errorout("failed to connect to host");
}


/* now we're connected, serve fall into the data echo loop */
while (1) {
/* Select for readability on either of our two sockets */
FD_ZERO(&rdfdset);
FD_SET(usersockfd,&rdfdset);
FD_SET(isosockfd,&rdfdset);
if (select(FD_SETSIZE,&rdfdset,NULL,NULL,NULL) < 0)
errorout("select failed");

/* is the client sending data? */
if (FD_ISSET(usersockfd,&rdfdset)) {
if ((iolen = read(usersockfd,buf,sizeof(buf))) <= 0)
break; /* zero length means the client disconnected */

write(isosockfd,buf,iolen); /* copy to host -- blocking semantics */
}

/* is the host sending data? */
if (FD_ISSET(isosockfd,&rdfdset)) {
if ((iolen = read(isosockfd,buf,sizeof(buf))) <= 0)
break; /* zero length means the host disconnected */

write(usersockfd,buf,iolen); /* copy to client -- blocking semantics */
}
}

/* we're done with the sockets */
close(isosockfd);
close(usersockfd);
}



/****************************************************************************
function: errorout
description: displays an error message on the console and kills the
current process.
arguments:
msg message to be displayed.

return value: none -- does not return.
calls: none.
globals: none.
****************************************************************************/

void errorout (msg)
char *msg;
{
FILE *console;

console = fopen("/dev/console","a");
fprintf(console,"proxyd: %s/r/n",msg);
fclose(console);
exit(1);
}



/****************************************************************************
function: reap_status
description: handle a SIGCLD signal by reaping the exit status of the
perished child, and discarding it.
arguments: none.
return value: none.
calls: none.
globals: none.
****************************************************************************/

void reap_status ()
{
int pid;
union wait status;

while ((pid = wait3(&status,WNOHANG,NULL)) > 0)
; /* loop while there are more dead children */
}


--
※ 来源:·BBS 水木清华站 bbs.net.tsinghua.edu.cn·[FROM: 202.193.65.100]
发信人: stwzyang (hook), 信区: Winsock
标 题: About Proxy source code (转帖)
发信站: BBS 水木清华站 (Sat Jan 3 04:19:25 1998)

偶在网上得此proxyd,先post出来,再慢慢研究。。。

17 Dev 1997

Author: Carl Harris (ceharris@vt.edu)
Compiler: TjL <luomat@peak.org>

Compiled by:
cc -O2 -object -s /
-arch m68k -arch i386 -arch hppa -arch sparc /
proxyd.c -o proxyd


This is a little daemon I felt was useful and was able to compile, so I thought I would make it available.

I did not write this! I am just compiling and distributing. The source code had no restrictions on doing so.

All I know as far as how to use it is what it says:

usage: proxyd <proxy-port> <host> <service-name|port-number>

Which means:

proxyd localport-on-this-machine the-host-this-is-to port-or-name

EXAMPLE:

Say you have a machine named MYHOST want to bind your port #777 to the TELNET port of the host REMOTEHOST.

Use: proxyd 777 REMOTEHOST telnet

Then if you did 'telnet MYHOST 777' you would actually connect to the TELNET port of the host REMOTEHOST.

As far as the 'service-name/port-number' goes: services can be referred to either by a number or a name. For example, NNTP requests are usually on port 119, so if you wanted to connect directly to a machine to do NNTP you could do either:

telnet REMOTEHOST nntp
or
telnet REMOTEHOST 119


NOTE/WARNING: Make sure to use an unused port on your machine! If you are not sure, do this:

nidump services .

to see a listing of all the services known on your machine.

This program does NOT always have to be run as root... Some ports are available even to regular users, it appears.
 
tianhf:请将 "Proxy.h"也贴出吧。

谁有Delphi的Source?

 
  我来也问个问题吧,在我们公司里使用的proxy是微软的MS Proxy 2.0,它的账号管理是和NT本身的账号管理相联结的,即你只要拥有该NT的域账号,就能使用proxy。
如果我的主机在开机的时候已经用某账号登录到该域,则用IE浏览的时候不需要输入账号和密码了,反之,如果在开机要求输入密码的时候我按了cancel键,则我在用IE浏览的时候,除了要求输入账号和密码外,还要输入账号所在的域。在IE4.0里边,输入的是
用户名 : <所在域/账号名>
密码 : <密码>
在IE5.0里边输入的是
用户名 : <账号名>
密码 : <密码>
域 : <该用户所在域>
在这样的proxy系统中,我根本无法使用Netscape或是蚂蚁等任何非微软的产品,因此对微软的东西是深恶痛绝,我想知道的是该怎么解决这个问题?
 
后退
顶部