-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfake_tcp.h
More file actions
46 lines (33 loc) · 1.04 KB
/
fake_tcp.h
File metadata and controls
46 lines (33 loc) · 1.04 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
#ifndef __FAKE_TCP_20220828__
#define __FAKE_TCP_20220828__
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
struct pkt_info {
uint8_t proto;
uint8_t syn:1;
uint8_t ack:1;
uint8_t rst:1;
uint16_t port_src;
uint16_t port_dst;
uint32_t seq;
uint32_t ack_seq;
uint32_t data_len;
struct in_addr ip_src;
struct in_addr ip_dst;
};
char* ReserveHdrSize(char *buf);
char* ParsePkt(char *buf, ssize_t len, struct pkt_info *info);
int BuildPkt(char* data, int len,
struct in_addr *ip_src, short port_src,
struct in_addr *ip_dst, short port_dst,
uint32_t seq, uint32_t ack_seq, uint8_t syn, uint8_t ack);
void SetAddr(const char *ip, short port, struct sockaddr_in*addr);
int StartFakeTcp(const char *ip, short port);
int StartServer(const char *ip, short port);
int StartClient(const char *ip, short port);
void Stop(int fd);
ssize_t recv_from_addr(int sockfd, void *buf, size_t len, int flags,
struct sockaddr_in *src_addr, socklen_t *addrlen, struct pkt_info *info);
#endif