| 1 |
#ifndef _PROTO_VIF |
| 2 |
#define _PROTO_VIF |
| 3 |
|
| 4 |
#include "protoChannel.h" |
| 5 |
#include "protoAddress.h" |
| 6 |
|
| 7 |
/** |
| 8 |
* @class ProtoVif |
| 9 |
* |
| 10 |
* @brief Supports virtual interfaces. |
| 11 |
*/ |
| 12 |
class ProtoVif : public ProtoChannel |
| 13 |
{ |
| 14 |
public: |
| 15 |
static ProtoVif* Create(); // for our "factory" pattern |
| 16 |
virtual ~ProtoVif(); |
| 17 |
|
| 18 |
enum {VIF_NAME_MAX = 255}; |
| 19 |
|
| 20 |
// Overrides of "Open()" and "Close()" MUST call the ProtoChannel |
| 21 |
// Open/Close base class methods last/first, respectively |
| 22 |
// Note: on some OS's, you may not get your requested "vifName" |
| 23 |
virtual bool Open(const char* vifName, |
| 24 |
const ProtoAddress& ipAddr, // optional IP addr for interface |
| 25 |
unsigned int maskLen) // maskLen for optional IP addr |
| 26 |
{return ProtoChannel::Open();} |
| 27 |
|
| 28 |
virtual void Close() |
| 29 |
{ProtoChannel::Close();} |
| 30 |
|
| 31 |
const ProtoAddress& GetHardwareAddress() const |
| 32 |
{return hw_addr;} |
| 33 |
|
| 34 |
// This lets us set a MAC addr. |
| 35 |
// (vif MUST be open and iface is brought down/up to change) |
| 36 |
virtual bool SetHardwareAddress(const ProtoAddress& hwAddr) = 0; |
| 37 |
|
| 38 |
virtual bool SetARP(bool status) = 0; |
| 39 |
|
| 40 |
virtual bool Write(const char* buffer, unsigned int buflen) = 0; |
| 41 |
|
| 42 |
virtual bool Read(char* buffer, unsigned int& numBytes) = 0; |
| 43 |
const char* GetName() const |
| 44 |
{return vif_name;} |
| 45 |
|
| 46 |
void SetUserData(const void* userData) |
| 47 |
{user_data = userData;} |
| 48 |
const void* GetUserData() const |
| 49 |
{return user_data;} |
| 50 |
|
| 51 |
protected: |
| 52 |
ProtoVif(); |
| 53 |
|
| 54 |
// Implementations SHOULD fill this in with the whatever name |
| 55 |
// the virtual interface gets, whether equal to requested name or not |
| 56 |
char vif_name[VIF_NAME_MAX+1]; |
| 57 |
ProtoAddress hw_addr; // should be filled in with device hardware addr on Open() |
| 58 |
|
| 59 |
private: |
| 60 |
const void* user_data; |
| 61 |
|
| 62 |
}; // end class ProtoVif |
| 63 |
|
| 64 |
#endif // _PROTO_VIF |