pxar
 All Classes Namespaces Functions Variables Typedefs Friends
EthernetInterface.h
1 #ifndef PXAR_ETHERNET_H
2 #define PXAR_ETHERNET_H
3 
4 #include <deque>
5 #include <string>
6 #include <vector>
7 #include <ctime>
8 
9 #include <unistd.h> //needed for unique pid
10 
11 #include <pcap.h>
12 
13 #include "rpc_io.h"
14 
15 
16 #define RX_FRAME_SIZE 2048
17 #define TX_FRAME_SIZE 2048
18 
19 #define MAX_TX_DATA 1500
20 #define ETH_HEADER_SIZE 19
21 
22 
23 class CEthernet : public CRpcIo
24 {
25  void InitInterface();
26 
27  void Hello();
28  bool Claim(const unsigned char* MAC, bool force);
29  bool Unclaim();
30 
31  //pcap data structures
32  pcap_t* descr;
33  struct pcap_pkthdr header;
34 
35  std::string interface;
36  std::vector<std::string > MAC_addresses;
37  int MAC_counter;
38 
39  unsigned char host_pid[2];
40 
41  std::deque<unsigned char> rx_buffer;
42  unsigned char tx_frame[TX_FRAME_SIZE];
43  unsigned char dtb_mac[6];
44  unsigned char host_mac[6];
45 
46  unsigned int tx_payload_size;//data in tx buffer minus header(14 bytes)
47  bool is_open;
48 public:
49  CEthernet();
50  ~CEthernet();
51 
52  const char* Name() { return "Ethernet";};
53 
54  int GetLastError() { return 0; }
55  const char* GetErrorMsg(int /*error*/){return NULL;};
56 
57  void SetTimeout(unsigned int /*timeout*/) {};
58 
59  bool EnumFirst(unsigned int &nDevices);
60  bool EnumNext(char name[]);
61  bool Enum(char name[], unsigned int pos);
62  bool Open(char MAC_address[]);
63  bool Connected() { return is_open; };
64 
65  void Write(const void *buffer, unsigned int size);
66  void Flush();
67  void Clear();
68  void Read(void *buffer, unsigned int size);
69  void Close(CRpcIo* io);
70  void Close();
71  bool IsOpen();
72 };
73 
74 #endif