2 // Copyright (c) 2010-2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
33 bool operator!=(const pkt_tuple& other) const
35 return src_addr != other.src_addr ||
36 dst_addr != other.dst_addr ||
37 proto_id != other.proto_id ||
38 src_port != other.src_port ||
39 dst_port != other.dst_port;
41 bool operator==(const pkt_tuple& other) const
43 return src_addr == other.src_addr &&
44 dst_addr == other.dst_addr &&
45 proto_id == other.proto_id &&
46 src_port == other.src_port &&
47 dst_port == other.dst_port;
49 friend ostream& operator<<(ostream& stream, const pkt_tuple &other);
50 struct pkt_tuple flip() const
55 ret.src_addr = dst_addr;
56 ret.src_port = dst_port;
57 ret.dst_addr = src_addr;
58 ret.dst_port = src_port;
62 } __attribute__((packed));
67 friend class PcapReader;
70 uint16_t src_port; /**< TCP source port. */
71 uint16_t dst_port; /**< TCP destination port. */
72 uint32_t sent_seq; /**< TX data sequence number. */
73 uint32_t recv_ack; /**< RX data acknowledgement sequence number. */
74 uint8_t data_off; /**< Data offset. */
75 uint8_t tcp_flags; /**< TCP flags */
76 uint16_t rx_win; /**< RX flow control window. */
77 uint16_t cksum; /**< TCP checksum. */
78 uint16_t tcp_urp; /**< TCP urgent pointer, if any. */
79 } __attribute__((__packed__));
81 static Allocator *allocator;
82 enum L4Proto {PROTO_TCP, PROTO_UDP};
84 void* operator new(size_t size);
85 static void operator delete(void *pointer);
86 PcapPkt(const PcapPkt& other);
87 PcapPkt(uint8_t *mem);
88 void toMem(uint8_t *mem) const;
89 void fromMem(uint8_t *mem);
90 void toFile(ofstream *file) const;
91 size_t memSize() const;
92 const struct timeval &ts() const {return header.ts;}
93 const uint16_t len() const {return header.len;}
94 pkt_tuple parsePkt(const uint8_t **l4_hdr = NULL, uint16_t *hdr_len = NULL, const uint8_t **l5 = NULL, uint32_t *l5_len = NULL) const;
95 const struct pcap_pkthdr &hdr() const {return header;}
96 const uint8_t *payload() const {return buf;}
97 enum L4Proto getProto() const;
100 struct pcap_pkthdr header;
104 #endif /* _PCAPPKT_H_ */