-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpacket.cpp
More file actions
93 lines (73 loc) · 1.71 KB
/
packet.cpp
File metadata and controls
93 lines (73 loc) · 1.71 KB
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
#include <string.h>
#include <thread>
#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <netdb.h>
#include <fstream>
#include <cassert>
#include <sys/time.h>
#include <vector>
#include <set>
using namespace std;
const uint32_t MAX_SEQ_NUM = 25600;
const uint16_t MAX_PKT_LEN = 524;
const uint16_t INIT_CWND_SIZE = 512;
const uint16_t INIT_SS_THRESH = 5120;
const uint16_t MIN_SS_THRESH = INIT_CWND_SIZE;
const uint16_t CWND_MAX_SIZE = 10240;
const uint32_t RETRANS_TIMEOUT = 500000;
const int abort_timeout = 10;
string flag_in_str = "";
#define SYN 0x2
#define ACK 0x4
#define FIN 0x1
#define SYN_ACK SYN|ACK
#define ACK_FIN ACK|FIN
#define MSS 524
#define DATA_SIZE 512
struct header
{
short seq;
short ack;
int flag;
int lendata;
//char extra[3];
};
struct packet
{
header head;
char data[DATA_SIZE];
};
struct packet_head
{
header head;
bool nul;
};
//current seq number should be current + data size
//current ack should be oppsite seq number + oppsite data size
void generate_packet(packet &pac, short seq, short ack, int flag, char*buf, int lendata)
{
// pac.head.seq = htonl(seq);
// pac.head.ack = htonl(ack);
// pac.head.flag = htonl(flag);
pac.head.seq = seq;
pac.head.ack = ack;
pac.head.flag = flag;
pac.head.lendata = lendata;
for (int i= 0; i < lendata; i++)
{
pac.data[i] = buf[i];
}
}
void generate_packet_head(packet_head &pac, short seq, short ack, int flag)
{
pac.head.seq = seq;
pac.head.ack = ack;
pac.head.flag = flag;
}