-
Notifications
You must be signed in to change notification settings - Fork 1
/
Ethernet.h
86 lines (76 loc) · 2.97 KB
/
Ethernet.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
/* ES40 emulator.
* Copyright (C) 2007-2008 by the ES40 Emulator Project
*
* WWW : http://sourceforge.net/projects/es40
* E-mail : [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Although this is not required, the author would appreciate being notified of,
* and receiving any modifications you may make to the source code that might serve
* the general public.
*
* Parts of this file based upon GXemul, which is Copyright (C) 2004-2007
* Anders Gavare. All rights reserved.
*/
/**
* \file
* Contains the definitions for the packet queue and other NIC support routines.
*
* $Id: Ethernet.h,v 1.1 2008/02/26 15:54:57 iamcamiel Exp $
*
* X-1.1 David Hittner 26-FEB-2008
* File creation.
**/
#if !defined(INCLUDED_ETHERNET_H)
#define INCLUDED_ETHERNET_H
#define ETH_MAX_PACKET_RAW 1514
#define ETH_MAX_PACKET_CRC 1518
struct eth_frame { // ethernet (wire) frame
u8 src[6]; // source address
u8 dst[6]; // destination address
u8 protocol[2]; // protocol
u8 data[1500]; // data: variable 46-1500 bytes
u8 crc_fill[4]; // space for max packet crc
};
struct eth_packet { // ethernet packet
int len; // size of packet
int used; // bytes used (consumed)
u8 frame[ETH_MAX_PACKET_CRC]; // ethernet frame
};
/**
* \brief Packet Queue for Ethernet packets.
**/
class CPacketQueue { // Ethernet Packet Queue
//private:
public:
char* name; // queue name
int max; // maximum items allowed in queue
int head; // first item in queue
int tail; // last item in queue
int cnt; // current item count
int highwater; // highwater mark (statistics)
int dropped; // packets dropped because queue was full
eth_packet* packets; // packet array; dynamically allocated
public:
inline int count() {return cnt;} // get current count
inline int lost() {return dropped;} // get number of lost packets
void flush(); // empties packet queue
bool add_tail(const u8* packet_data, int packet_len, bool calc_crc, bool need_crc); // adds pcap packet to queue
bool get_head(eth_packet& packet); // get packet at head
CPacketQueue(char* name, int max); // constructor
~CPacketQueue(); // destructor
};
#endif // !defined(INCLUDED_ETHERNET_H)