-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
55 lines (53 loc) · 1.49 KB
/
main.cpp
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
48
49
50
51
52
53
54
55
#include "tapLanServer.hpp"
#include "tapLanClient.hpp"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
bool isServer = false;
bool isClient = false;
char serverAddr[64];
uint16_t serverPort = 0;
uint16_t clientPort = 0;
int main(int argc, char* argv[]) {
if (argc < 2) {
printf("less argc!\n");
return 1;
}
int opt;
while ((opt = getopt(argc, argv, "s:c:a:p:")) != -1) {
switch (opt) {
case 's':
isServer = true;
serverPort = atoi(optarg);
printf("serverPort: %u\n", serverPort);
break;
case 'c':
isClient = true;
clientPort = atoi(optarg);
printf("clientPort: %u\n", clientPort);
break;
case 'a':
strcpy(serverAddr, optarg);
printf("serverAddr: %s\n", serverAddr);
break;
case 'p':
serverPort = atoi(optarg);
printf("serverPort: %u\n", serverPort);
break;
case '?':
// 无效选项或缺少参数
fprintf(stderr, "Usage: %s [-h] [-o <filename>]\n", argv[0]);
return 1;
}
}
if (isServer) {
TapLanServer tLS(serverPort);
tLS.start();
while (1);
} else if (isClient) {
TapLanClient tLC(serverAddr, serverPort, clientPort);
tLC.start();
while (1);
}
return 0;
}