forked from westlab/negi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Packet.H
125 lines (102 loc) · 4.15 KB
/
Packet.H
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* ** Copyright (C) 2012 Shinichi Ishida, All Rights Reserved.
* **
* ** Please see the LICENSE file distributed with this source
* ** code archive for information covering the modification and
* ** redistribution of this file and binaries built from it.
* */
/*
* $Id: Packet.H,v 5.9 2012/08/23 04:04:07 sin Exp $
*/
#pragma once
#include "Include.H"
#include "Stream.H"
class Stream;
#ifdef PACKET_DEBUG_EN
#define PACKET_DEBUG(x) x ;
#else
#define PACKET_DEBUG(x) ;
#endif
typedef struct PacketCnt_t{
struct pcap_pkthdr pcap_hdr;
u_char pcap_pkt[];
}PacketCnt;
class Packet
{
private:
PacketCnt *packet_cnt; // pointer to libpcap packet structure(w/ header)
Stream *stream; // pointer to stream that packet belong to
unsigned char* packet; // ponter to packet binary
struct ip* ip_header; // pointer to IP header structure
struct tcphdr* tcp_header; // pointer to TCP header structure
unsigned int l2_header_size; // L2(MAC) header size
unsigned int l3_header_size; // L3(IP) header size
unsigned int l4_header_size; // L4(TCP/UDP) header size
unsigned int packet_size; // packet size (caliculated from IP header) <- nomally use this!
unsigned int packet_size_cap; // captured packet size(returned by libpcap)
unsigned int packet_size_org; // original packet size(returned by libpcap)
unsigned int content_size; // payload size
unsigned int l7_content_size; // Layer 7 content size(with HTTP/1.1 decode, etc)
unsigned char* l3_header; // pointer to L3(MAC) header
unsigned char* l4_header; // pointer to L4(TCP/UDP) header
unsigned char* content; // pointer to payload begin
unsigned char* l7_content; // pointer to Layer7 content begin
struct timeval timestamp; // Packet reached timestamp(returnd by libpcap)
unsigned int protocol; // Transport Protocol(ex: TCP:6)
bool ack; // TCP ACK flag
bool fin; // TCP FIN flag
bool syn; // TCP SYN flag
bool urg; // TCP URG flag
bool psh; // TCP PUSH flag
bool rst; // TCP RESET flag
struct in_addr src_ip; // Source IP
struct in_addr dst_ip; // Destination IP
unsigned int src_port; // Source Port
unsigned int dst_port; // Destination Port
unsigned int seq_no; // TCP sequence number
size_t mem_size; // not used.
list<Packet*>::iterator packet_pool_it; // used for gabage collect
list<Packet*>::iterator stream_packet_list_it; // used for gabage collect
int error; // error number
public:
Packet(PacketCnt *pcnt);
Packet(string timestamp_str, string content_size_str, string src_ip_str, string src_port_str, string dst_ip_str, string dst_port_str, string flag_str, string content_str);
~Packet();
void SetStream(Stream *p_stream);
Stream *GetStream();
unsigned char *GetPacket();
PacketCnt *GetPacketContainer(){return packet_cnt;}
unsigned char *GetL3Header();
unsigned char *GetL4Header();
struct in_addr GetSrcIP(){return src_ip;}
struct in_addr GetDstIP(){return dst_ip;}
unsigned int GetSrcPort(){return src_port;}
unsigned int GetDstPort(){return dst_port;}
unsigned int GetSeqNo(){return seq_no;}
unsigned char *GetContent();
unsigned int GetPacketSize(){return packet_size;}
unsigned int GetPacketSizeOrg(){return packet_size_org;}
unsigned char * GetL7Content(){return l7_content;}
void SetL7Content(unsigned char *l7c){l7_content = l7c;}
unsigned int GetContentSize(){return content_size;}
void SetL7ContentSize(unsigned int size);
u_int GetL7ContentSize(){return l7_content_size;}
struct timeval GetTimestamp();
u_int GetProtocol(){return protocol;}
bool GetAck(){return ack;}
bool GetFin(){return fin;}
bool GetSyn(){return syn;}
bool GetUrg(){return urg;}
bool GetPsh(){return psh;}
bool GetRst(){return rst;}
list<Packet*>::iterator GetPacketPoolIt(){return packet_pool_it;}
void SetPacketPoolIt(list<Packet*>::iterator it){packet_pool_it = it;}
list<Packet*>::iterator GetStreamIt(){return stream_packet_list_it;}
void SetStreamIt(list<Packet*>::iterator it){stream_packet_list_it = it;}
void SetError(){error = 1;}
int GetError(){return error;}
void ShowContent();
void Show();
//for Test.C
void SetContentSize(u_int size);
};