-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverMain.c
47 lines (41 loc) · 918 Bytes
/
serverMain.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* 此处添加头文件
* */
#include "ftpServer.h"
void callBack()
{
destroyLock(&mutex);
}
int main(char argc, char *argv[])
{
char serverIp[IPV4_LEN + 1]; //IPV4_LEN长度为15,但是字符串必须以0结尾
unsigned short serverPort;
//处理命令行参数
if(argc == 1)
{
strcpy(serverIp, "0.0.0.0");
serverPort = 21;
}
else if(argc == 2)
{
if(strlen(argv[1]) > IPV4_LEN)
printf("ip addr is illegal\n"), exit(-1);
strcpy(serverIp, argv[1]);
serverPort = 21;
}
else if(argc == 3)
{
if(strlen(argv[1]) > IPV4_LEN)
printf("ip addr is illegal\n"), exit(-1);
strcpy(serverIp, argv[1]);
serverPort = atoi(argv[2]);
}
//初始化服务器
struct FtpServer *server = (struct FtpServer *)malloc(sizeof(struct FtpServer));
initFtpServer(server, serverIp, serverPort);
//初始化全局锁
initLock(&mutex);
atexit(callBack);
//运行服务器
runFtpServer(server);
}