Debian Codegraph @

protolib/include/protoCap.h

raw
1 #ifndef _PROTO_CAP
2 #define _PROTO_CAP
3
4 /**
5 * @class ProtoCap
6 * @brief This class is a generic base class for simple
7 * link layer packet capture (ala libpcap) and
8 * raw link layer packet transmission.
9 */
10
11 #include "protoChannel.h"
12 #include "protoAddress.h"
13
14 class ProtoCap : public ProtoChannel
15 {
16 public:
17 static ProtoCap* Create();
18 virtual ~ProtoCap();
19
20 // Packet capture "direction"
21 enum Direction
22 {
23 UNSPECIFIED,
24 INBOUND,
25 OUTBOUND
26 };
27
28 // These must be overridden for different implementations
29 // ProtoCap::Open() MUST also be called at the _end_ of derived
30 // implementations' Open() method
31 virtual bool Open(const char* interfaceName = NULL)
32 {return ProtoChannel::Open();}
33 virtual bool IsOpen()
34 {return ProtoChannel::IsOpen();}
35 // ProtoCap::Close() should also be called at the _beginning_ of
36 // derived implementations' Close() method
37 virtual void Close()
38 {
39 ProtoChannel::Close();
40 if_index = -1;
41 }
42
43 unsigned int GetInterfaceIndex() const
44 {return if_index;}
45
46 const ProtoAddress& GetInterfaceAddr() const
47 {return if_addr;}
48
49 virtual bool Recv(char* buffer, unsigned int& numBytes, Direction* direction = NULL) = 0;
50 virtual bool Send(const char* buffer, unsigned int& numBytes) = 0;
51
52 bool Forward(char* buffer, unsigned int& numBytes);
53
54 bool ForwardFrom(char* buffer, unsigned int& numBytes, const ProtoAddress& srcMacAddr);
55
56 void SetUserData(const void* userData)
57 {user_data = userData;}
58 const void* GetUserData() const
59 {return user_data;}
60
61 protected:
62 ProtoCap();
63 unsigned int if_index; // interface index (if applicable)
64 ProtoAddress if_addr; // interface MAC addr (if applicable)
65
66 private:
67 const void* user_data;
68
69 }; // end class ProtoCap
70
71 #endif // _PROTO_CAP