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
/**
* @file protoCap.cpp
* @brief Protolib Generic base class for simple link layer packet capture (ala libpcap) and raw link layer packet transmission.
*/
/**
* @class ProtoCap
*
* @brief Generic base class for simple link layer packet capture (ala libpcap) and raw link layer packet transmission.
*/
#include "protoCap.h"
#include "protoDebug.h"
// (TBD) How bad would it really be to inline these in the "ProtoCap" class definition?
// (The we could get rid of this file)
/**
* @brief Enables input notification by default
*
*/
ProtoCap::ProtoCap()
: if_index(0), if_type(ProtoNet::IFACE_INVALID_TYPE), user_data(NULL)
{
// Enable input notification by default for ProtoCap
StartInputNotification();
}
ProtoCap::~ProtoCap()
{
if (IsOpen()) Close();
}
/**
* @brief Changes the source mac addr to our own and writes packet to the pcap device
*
* 802.3 frames are not yet supported
*
* @param buffer
* @param buflen
*
* @return success or failure indicator
*/
bool ProtoCap::Forward(char* buffer, unsigned int& numBytes)
{
// Change the src MAC addr to our own
// (TBD) allow caller to specify dst MAC addr ???
memcpy(buffer+6, if_addr.GetRawHostAddress(), 6);
return Send(buffer, numBytes);
} // end ProtoCap::Forward()
/**
* @brief Changes the source mac addr to specified srcMacAddr and writes packet pcap device
*
* 802.3 frames are not yet supported
*
* @param buffer
* @param buflen
*
* @return success or failure indicator
*/
bool ProtoCap::ForwardFrom(char* buffer, unsigned int& numBytes, const ProtoAddress& srcMacAddr)
{
// Change the src MAC addr to our own
// (TBD) allow caller to specify dst MAC addr ???
memcpy(buffer+6, srcMacAddr.GetRawHostAddress(), 6);
return Send(buffer, numBytes);
} // end ProtoCap::ForwardFrom()