| 1 |
/** |
| 2 |
* @file protoCap.cpp |
| 3 |
* @brief Protolib Generic base class for simple link layer packet capture (ala libpcap) and raw link layer packet transmission. |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* @class ProtoCap |
| 8 |
* |
| 9 |
* @brief Generic base class for simple link layer packet capture (ala libpcap) and raw link layer packet transmission. |
| 10 |
*/ |
| 11 |
|
| 12 |
#include "protoCap.h" |
| 13 |
#include "protoDebug.h" |
| 14 |
|
| 15 |
// (TBD) How bad would it really be to inline these in the "ProtoCap" class definition? |
| 16 |
// (The we could get rid of this file) |
| 17 |
|
| 18 |
/** |
| 19 |
* @brief Enables input notification by default |
| 20 |
* |
| 21 |
*/ |
| 22 |
ProtoCap::ProtoCap() |
| 23 |
: if_index(0), user_data(NULL) |
| 24 |
{ |
| 25 |
// Enable input notification by default for ProtoCap |
| 26 |
StartInputNotification(); |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
ProtoCap::~ProtoCap() |
| 31 |
{ |
| 32 |
if (IsOpen()) Close(); |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
/** |
| 37 |
* @brief Changes the source mac addr to our own and writes packet to the pcap device |
| 38 |
* |
| 39 |
* 802.3 frames are not supported |
| 40 |
* |
| 41 |
* @param buffer |
| 42 |
* @param buflen |
| 43 |
* |
| 44 |
* @return success or failure indicator |
| 45 |
*/ |
| 46 |
bool ProtoCap::Forward(char* buffer, unsigned int& numBytes) |
| 47 |
{ |
| 48 |
// Change the src MAC addr to our own |
| 49 |
// (TBD) allow caller to specify dst MAC addr ??? |
| 50 |
memcpy(buffer+6, if_addr.GetRawHostAddress(), 6); |
| 51 |
return Send(buffer, numBytes); |
| 52 |
} // end ProtoCap::Forward() |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
/** |
| 57 |
* @brief Changes the source mac addr to specified srcMacAddr and writes packet pcap device |
| 58 |
* |
| 59 |
* 802.3 frames are not supported |
| 60 |
* |
| 61 |
* @param buffer |
| 62 |
* @param buflen |
| 63 |
* |
| 64 |
* @return success or failure indicator |
| 65 |
*/ |
| 66 |
bool ProtoCap::ForwardFrom(char* buffer, unsigned int& numBytes, const ProtoAddress& srcMacAddr) |
| 67 |
{ |
| 68 |
// Change the src MAC addr to our own |
| 69 |
// (TBD) allow caller to specify dst MAC addr ??? |
| 70 |
memcpy(buffer+6, srcMacAddr.GetRawHostAddress(), 6); |
| 71 |
return Send(buffer, numBytes); |
| 72 |
} // end ProtoCap::ForwardFrom() |