summaryrefslogtreecommitdiff
path: root/common/include/packet_construct.h
blob: 8d30b02e4d869a8cf67149f042d6896369465fa5 (plain)
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 _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, const char *options, uint16_t options_len);
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 Header
    const char *tcp_options, uint16_t tcp_options_len, // TCP Options
    const char *payload, uint16_t payload_len); // Payload

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 Header
    const char *tcp_options, uint16_t tcp_options_len, // TCP Options
    const char *payload, uint16_t payload_len); // Payload

#ifdef __cpluscplus
}
#endif

#endif