TSG-13042 构造三次握手报文,通过原始套接字注入tap_client和tap_server

This commit is contained in:
luwenpeng
2022-12-20 14:00:46 +08:00
parent 42dded52ac
commit 7978e74321
6 changed files with 672 additions and 1 deletions

View File

@@ -0,0 +1,44 @@
#ifndef _CONSTRUCT_PACKET_H
#define _CONSTRUCT_PACKET_H
#ifdef __cpluscplus
extern "C"
{
#endif
#include <stdint.h>
#include <sys/types.h>
#define TCP_URG_FLAG 0x20
#define TCP_ACK_FLAG 0x10
#define TCP_PSH_FLAG 0x08
#define TCP_RST_FLAG 0x04
#define TCP_SYN_FLAG 0x02
#define TCP_FIN_FLAG 0x01
#define TCP_FLAG_ALL 0x3F
int tcp_header_construct(char *buffer, uint16_t src_port, uint16_t dst_port, uint32_t seq, uint32_t ack, u_char flags, uint16_t window, uint16_t urgent);
int ipv4_header_construct(char *buffer, uint16_t carry_layer_len, struct in_addr *src_addr, struct in_addr *dst_addr, u_char tos, uint16_t id, uint16_t frag, u_char ttl, u_char protocol);
int ipv6_header_construct(char *buffer, uint16_t carry_layer_len, struct in6_addr *src_addr, struct in6_addr *dst_addr, u_char ttl, u_char protocol);
int vlan_header_construct(char *buffer, uint16_t tci, uint16_t type);
int ether_header_construct(char *buffer, struct ether_addr *src_mac, struct ether_addr *dst_mac, uint16_t type);
int tcp_packet_v4_construct(
char *buffer, // buffer
struct ether_addr *src_mac, struct ether_addr *dst_mac, uint16_t vlan_tci, uint16_t l3_protocol, // Ether
struct in_addr *src_addr, struct in_addr *dst_addr, u_char tos, u_char ttl, uint16_t id, // IPv4
uint16_t src_port, uint16_t dst_port, uint32_t seq, uint32_t ack, u_char flags, uint16_t window, // TCP
const char *payload, uint16_t payload_len);
int tcp_packet_v6_construct(
char *buffer, // buffer
struct ether_addr *src_mac, struct ether_addr *dst_mac, uint16_t vlan_tci, uint16_t l3_protocol, // Ether
struct in6_addr *src_addr, struct in6_addr *dst_addr, u_char ttl, // IPv6
uint16_t src_port, uint16_t dst_port, uint32_t seq, uint32_t ack, u_char flags, uint16_t window, // TCP
const char *payload, uint16_t payload_len);
#ifdef __cpluscplus
}
#endif
#endif