-
Notifications
You must be signed in to change notification settings - Fork 0
/
Project1Skeleton.c
59 lines (45 loc) · 1.14 KB
/
Project1Skeleton.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
48
49
50
51
52
53
54
55
56
#include "NetworkHeader.h"
/* function declarations */
main (int argc, char *argv[]) {
/* There are certainly slicker ways of doing this,
* but I figured there's no need to make the code
* any more confusing than it has to be at this point.
*/
/* Argument parsing variables */
char *firstName;
char *lastName;
char *serverHost = SERVER_HOST;
unsigned short serverPort = atoi(SERVER_PORT);
char *servPortString;
char c;
int i;
if ((argc < 5) || (argc > 7)) {
printf("Error: Usage Project0Client [-s <server IP>[:<port>]] -f <firstName> -l <lastName>\n");
exit(1);
}
for (i = 1; i < argc; ++i) {
if (argv[i][0] == '-') {
c = argv[i][1];
/* found an option, so look at next
* argument to get the value of
* the option */
switch (c) {
case 'f':
firstName = argv[i+1];
break;
case 'l':
lastName = argv[i+1];
break;
case 's':
serverHost = strtok(argv[i+1],":");
if ((servPortString = strtok(NULL, ":")) != NULL) {
serverPort = htons(atoi(servPortString));
}
break;
default:
break;
}
}
}
/* Your networking code starts here */
}