system.c
上传用户:sdtbys
上传日期:2009-12-06
资源大小:13k
文件大小:1k
- #include <stdio.h>
- #include <stdlib.h>
- static int ListenSock;
- void DownListen(int Sig)
- {
- sockClose(ListenSock);
- ShowMsg("DownListenn");
- exit(0);
- }
- int main(int argc,char *argv[])
- {
- int ChildPid;
- int sock; char Sock[20];
- SIGNAL(DownListen);
- if ((ListenSock=sockServerOpen(atoi(argv[1]),atoi(argv[2])))<=0)
- {ShowMsg("Listen Sock failedn"); exit(0);}
- sockLook(ListenSock);
- while(1)
- {
- if ((sock=sockListen(ListenSock))<=0)
- { printf("listen sock failedn");continue;}
- sockLook(sock);
-
- switch (ChildPid=fork())
- {
- case -1: sockClose(sock);
- printf("fork failedn");
- break;
- case 0:
- sockClose(ListenSock);
- sprintf(Sock,"%d",sock);
- execlp("tcpconnect","tcpconnect",Sock,NULL);
- printf("execl failedn");
- sockClose(sock);
- exit(0);
- break;
- default:
- sockClose(sock);
- break;
- }
-
- }
- }