-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathheader.c
41 lines (37 loc) · 1.01 KB
/
header.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
#include "header.h"
#include <assert.h>
#include <string.h>
/* fill header without checksum */
int fill_header(u_short seq, u_short ack, u_short offset, u_short flag, packet_t* packet)
{
assert(offset<=1024);
assert(flag==ACK||flag==FIN||flag==(ACK|FIN));
assert(packet!=0);
packet->header.seq=seq;
packet->header.ack=ack;
packet->header.checksum=0;
packet->header.offset=offset;
packet->header.flag=flag;
return 0;
}
int fill_packet(u_char* src, packet_t* packet, u_short size)
{
assert(size<=PAYLOAD_SIZE);
memcpy(packet->payload,src,size);
return 0;
}
int read_header(header_t * p, packet_t* packet)
{
header_t * tmp= (header_t*)packet;
p->seq=tmp->seq;
p->ack=tmp->ack;
p->offset=tmp->offset;
p->flag=tmp->flag;
return 0;
}
int read_packet(u_char* dest, packet_t* packet, u_short size)
{
assert(size<=PAYLOAD_SIZE);
memcpy(dest,packet->payload,size);
return 0;
}