www.pudn.com > Ftpwork > main.cpp
/***************************************************************************
main.cpp - description
-------------------
begin : ÈÕ 10ÔÂ 20 16:27:08 CST 2002
copyright : (C) 2002 by root
email : root@localhost.localdomain
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include
int main(int argc, char *argv[])
{
struct sockaddr_in sin;
int s,new_s ;
socklen_t len;
pthread_t ThreadID;
int ret;
printf("Please input shared directory:\n");
for(;;){
fgets(RootPath, sizeof(RootPath), stdin);
*(RootPath+strlen(RootPath)-1)='\0';
if( DirExist(RootPath)==DIR_EXIST )break;
printf("The directory does not exist!\n");
}
if( *(RootPath+strlen(RootPath)-1)!='/'){
*(RootPath+strlen(RootPath))='/';
*(RootPath+strlen(RootPath)+1)='\0';
}
printf("%s\n",RootPath);
bzero((char *)&sin, sizeof(sin));
sin.sin_family =AF_INET;
sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = htons(SERVER_PORT);
s = socket(PF_INET, SOCK_STREAM, 0);
if (s < 0 ){
perror("FTPServer:socket error!\n");
exit(1);
}
if ((bind(s, (struct sockaddr *)&sin, sizeof(sin))) <0){
perror("FTPServer: bind error!\n");
exit(1);
}
listen(s, MAX_PENDING);
sem_init( &sem, 0, 1);
clrscr();
printf("FTPServer is running ");
printf("\033[01;32m ^_^\033[01;0m\n");
for(;;){
new_s = accept(s, (struct sockaddr *)&sin, &len);
if(new_s <0){
perror("FTPServer: accept error!\n");
exit(1);
}
Parameter.SockID=new_s;
Flag=0;
ret=pthread_create(&ThreadID,NULL, thread, NULL);
if(ret !=0){
printf("Create pthread error!\n");
exit(1);
}
for(;;)
if(Flag==1)break;
}
sem_destroy(&sem);
return EXIT_SUCCESS;
}