-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenframe.c
63 lines (55 loc) · 1.44 KB
/
genframe.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
#include "genframe.h"
frame_op* init_frame_op() {
frame_op* obj = malloc(sizeof(struct frame_op));
obj->frame_length = 0;
obj->typeL3 = 0;
obj->typeL4 = 0;
return obj;
}
void genframe(frame_op* options) {
switch (options->typeL3) {
case IPV4:
printf("\nGenerating IPV4 Header\n");
gen_ipv4_hdr(options);
break;
case IPV6:
printf("\nGenerating IPV6 Header\n");
}
switch (options->typeL4) {
case TCP:
printf("\nGenerating TCP Header\n");
break;
case UDP:
printf("\nGenerating UDP Header\n");
break;
}
}
void gen_ipv4_hdr(frame_op* options) {
ipv4_hdr* header = malloc(sizeof(struct ipv4_hdr));
header->version = 4;
header->ihl = 5;
header->tos = 0;
header->total_length = options->frame_length;
header->id = rand();
header->flags = 0;
header->frag_off = 0;
header->ttl = 255;
switch (options->typeL4) {
case (TCP):
header->protocol = 6;
break;
case (UDP):
header->protocol = 17;
break;
default:
header->protocol = 0;
break;
}
header->checksum = 0;
header->source_addr = rand();
header->dest_addr = rand();
header->checksum = ipv4_checksum(header);
}
uint16_t ipv4_checksum(ipv4_hdr* header) {
return 0;
}