-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_opts.c
71 lines (66 loc) · 1.82 KB
/
test_opts.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* =====================================================================================
*
* Filename: test_opts.c
*
* Description: test to learn get_opts in C
*
* Version: 1.0
* Created: 03/17/2015 02:31:47 PM
* Revision: none
* Compiler: gcc
*
* Author: nikkolasg (mn),
* Company:
*
* =====================================================================================
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
void
usage ( )
{
printf("opts: [mitm|flood] -i interface -a hostA -b hostB");
return ;
} /* ----- end of function usage ----- */
int
main ( int argc, char *argv[] )
{
char * operation = NULL;
char * interface = NULL;
char * hostA = NULL;
char * hostB = NULL;
int c;
while((c = getopt(argc,argv,"m:i:a:b:")) != -1){
switch(c){
case 'm':
operation = optarg;
if (strncmp(operation,"mitm",4) != 0 &&
strncmp(operation,"flood",5) != 0) {
fprintf(stderr,"Operation %s is unknown.Abort\n",operation);
abort();
}
break;
case 'i':
interface = optarg;
break;
case 'a':
hostA = optarg;
break;
case 'b':
hostB = optarg;
break;
case '?':
fprintf(stderr,"Option %c requires an argument",optopt);
abort();
}
}
printf("Arguments are :");
printf("\n\tMethod : %s",operation);
printf("\n\tInterface : %s",interface);
printf("\n\thostA : %s",hostA);
printf("\n\thostB : %s\n",hostB);
return EXIT_SUCCESS;
} /* ---------- end of function main ---------- */