-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.c
127 lines (112 loc) · 2.81 KB
/
options.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <netdb.h>
#include <string.h>
#include "options.h"
int setaddr(char * name, struct sockaddr_in * sin) {
struct addrinfo * res;
struct addrinfo * info;
struct addrinfo hints = {0};
int error;
hints.ai_socktype = SOCK_RAW;
error = getaddrinfo(name,NULL,&hints,&res);
if (error != 0)
{
if (error == EAI_SYSTEM)
{
perror("getaddrinfo");
}
else
{
fprintf(stderr, "error in getaddrinfo: %s\n", gai_strerror(error));
}
exit(EXIT_FAILURE);
}
else {
for(info = res;info != NULL; info = info->ai_next) {
if(info->ai_addr->sa_family == AF_INET) {
memcpy(sin,info->ai_addr,info->ai_addrlen);
break;
}
}
freeaddrinfo(res);
}
}
int setopt(int argc, char** argv, struct options * opt) {
int c;
short ver = 4;
opt->sin_src_mask.sin_addr.s_addr = htonl(0xff000000);
opt->wait = 10;
opt->file = NULL;
opt->pps = 1;
while ((c = getopt(argc, argv, "v:s:d:m:w:f:p:")) != -1)
switch (c) {
case 's' :
setaddr(optarg,&(opt->sin_src));
break;
case 'm' :
setaddr(optarg,&(opt->sin_src_mask));
break;
case 'd' :
setaddr(optarg,&(opt->sin_dst));
break;
case 'v' :
ver = atoi(optarg);
break;
case 'w' :
opt->wait = atoi(optarg);
break;
case 'f':
opt->file = malloc(sizeof(char)*strlen(optarg)+1);
memcpy(opt->file,optarg,strlen(optarg)+1);
break;
case 'p':
opt->pps = atoi(optarg);
}
}
int syn_s = 0;
int syn_r = 0;
int psh_s = 0;
int psh_r = 0;
int fin_s = 0;
int fin_r = 0;
void syn_sent(){
syn_s++;
}
void syn_received(){
syn_r++;
}
void psh_sent(){
psh_s++;
}
void psh_received(){
psh_r++;
}
void fin_sent(){
fin_s++;
}
void fin_received(){
fin_r++;
}
int syn_lost() {
return syn_s-syn_r;
}
void print_stat(){
int _syn_s = syn_s;
int _syn_r = syn_r;
int _psh_s = psh_s;
int _psh_r = psh_r;
int _fin_s = fin_s;
int _fin_r = fin_r;
printf("lost syn %d\n",_syn_s-_syn_r);
printf("lost psh %d\n",_psh_s-_psh_r);
printf("syn sent %d\n",_syn_s);
printf("packet sent %d\n",_psh_s);
printf("packet received %d\n",_psh_r);
}
int toogle;
int pause_(int t) {
toogle = toogle ^ t;
return toogle;
}