Ethernet.h

Go to the documentation of this file.
00001 /* ES40 emulator.
00002  * Copyright (C) 2007-2008 by the ES40 Emulator Project
00003  *
00004  * WWW    : http://sourceforge.net/projects/es40
00005  * E-mail : camiel@camicom.com
00006  * 
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  * 
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00020  * 
00021  * Although this is not required, the author would appreciate being notified of, 
00022  * and receiving any modifications you may make to the source code that might serve
00023  * the general public.
00024  *
00025  * Parts of this file based upon GXemul, which is Copyright (C) 2004-2007  
00026  * Anders Gavare.  All rights reserved.
00027  */
00028 
00044 #if !defined(INCLUDED_ETHERNET_H)
00045 #define INCLUDED_ETHERNET_H
00046 
00047 #define ETH_MAX_PACKET_RAW  1514
00048 #define ETH_MAX_PACKET_CRC  1518
00049 
00050 struct eth_frame
00051 { // ethernet (wire) frame
00052   u8  src[6];       // source address
00053   u8  dst[6];       // destination address
00054   u8  protocol[2];  // protocol
00055   u8  data[1500];   // data: variable 46-1500 bytes
00056   u8  crc_fill[4];  // space for max packet crc
00057 };
00058 
00059 struct eth_packet
00060 {           // ethernet packet
00061   int len;  // size of packet
00062   int used; // bytes used (consumed)
00063   u8  frame[ETH_MAX_PACKET_CRC];  // ethernet frame
00064 };
00065 
00069 class CPacketQueue
00070 { // Ethernet Packet Queue
00071 
00072   //private:
00073   public:
00074     const char*         name;       // queue name
00075     int           max;        // maximum items allowed in queue
00076     int           head;       // first item in queue
00077     int           tail;       // last item in queue
00078     int           cnt;        // current item count
00079     int           highwater;  // highwater mark (statistics)
00080     int           dropped;    // packets dropped because queue was full
00081     eth_packet*   packets;    // packet array; dynamically allocated
00082   public:
00083     inline int  count() { return cnt; }
00084 
00085     // get current count
00086     inline int  lost()  { return dropped; }
00087 
00088     // get number of lost packets
00089     void        flush();  // empties packet queue
00090     bool        add_tail(const u8*  packet_data, int packet_len, bool calc_crc,
00091                          bool need_crc);      // adds pcap packet to queue
00092     bool        get_head(eth_packet& packet); // get packet at head
00093     CPacketQueue(const char* name, int max);        // constructor
00094     ~           CPacketQueue(); // destructor
00095 };
00096 #endif // !defined(INCLUDED_ETHERNET_H)

SourceForge.net Logo
Project space on SourceForge.net