WpcAdapter Class Reference
[Classes hierarchy]

Main class for libpcap operations. More...

List of all members.

Classes

class  WpcAdapterInfo
 smart pointer to libpcap's structure pcap_t More...

Public Member Functions

 WpcAdapter ()
 Default constructor.
 WpcAdapter (WpcAdapter const &)
 Copy constructor.
WpcAdapteroperator= (WpcAdapter const &)
 Copy operation.
 ~WpcAdapter ()
string GetIfaceDesc ()
 Gets interface description.
WpcState State ()
 Gets the state of the WpcAdapter.
 operator bool ()
 Gets the state of the WpcAdapter.
string GetError ()
 Gets last error description.
bool IsLoopback () const
 Returns whether the device is a loopback one.
WpcAddressListGetAddesses ()
 Returns list of the adapter's addresses.
bool StartCapture (string filter="")
 Starts capture for adapter.
bool StopCapture ()
 Stops capture for adapter.
void SendPacket (WpcPacket &pkt, bool autoComplete=false)
 Puts the packet tor the sending queue.
bool ReadPacket (WpcPacket &pkt)
 Reads the next packet available from the interface.
WpcAdapteroperator<< (WpcPacket &packet)
 Alias for SendPacket.
WpcAdapteroperator>> (WpcPacket &packet)
 Alias for ReadPacket.
void SetFilter (string const &expression, bool optimize=false, bpf_u_int32 netmask=0)
 Apply a filter given by a BPF expression.
WpcMacAddrGetMacAddr ()
 Gets adapter's MAC address.

Static Public Member Functions

static WpcState GetIfaceList (WpcStringList *lst)
 Gets interfaces list.
static string GetIfaceDesc (string iface)
 Gets interface description.
static WpcAdapterGetIface (string iface)
 Creates WpcAdapter object for the given interface.
static void SetAdaptersOptions (int snaplen=WPC_MAXSNAPLEN, bool promisc=true, int timeout=0)
 Sets the options for open libpcap's interfaces.
static WpcMacAddrGetTargetMAC (WpcAddress *addr=NULL)
 Gets MAC address of the target.

Protected Member Functions

 WpcAdapter (string)
 Creates adapter object for given name.
void PushPacket (WpcPacket *pkt)
 Adds packet to the adapter's queue.

Private Types

typedef map< string,
WpcAdapterInfo * > 
WpcAdapterList
 List of the wrapped libpcap's interfaces.

Static Private Member Functions

static void InitAdapterList (bool force=false)
 Fills the list of adapters and creates adapters smart pointers.

Private Attributes

WpcState m_status
 WpcObj status.
WpcAdapterInfom_iface
 wrapped libpcap's interface
string m_smbName
 adapter symbolic name
WpcPacketList m_pktList
 Receiving queue.
bool m_inCapture
 Is in capture process.

Static Private Attributes

static WpcAdapterList m_adapterList
 List of adapters available to use with libpcap.
static int m_snaplen = WPC_MAXSNAPLEN
 length of the packet that has to be retained.
static bool m_promisc = true
 Whether the interface is to be put into promiscuous mode.
static int m_timeout = 1
 The read timeout, in miliseconds.


Detailed Description

Main class for libpcap operations.

This class wraps the libpcap's C structure pcap_t, and it is the main class An Adapter object is an abstraction for any network device suitable to be used to make packet capture with PcapLive.

Examples:

wpcCapture.cpp, and wpcInit.cpp.


Member Typedef Documentation

typedef map<string, WpcAdapterInfo*> WpcAdapter::WpcAdapterList [private]

List of the wrapped libpcap's interfaces.


Constructor & Destructor Documentation

WpcAdapter::WpcAdapter (  ) 

Default constructor.

WpcAdapter::WpcAdapter ( WpcAdapter const &  copy  ) 

Copy constructor.

WpcAdapter::~WpcAdapter (  ) 

WpcAdapter::WpcAdapter ( string  name  )  [protected]

Creates adapter object for given name.

Exceptions:
WpcError if the adapters list can't be generated


Member Function Documentation

WpcAddressList & WpcAdapter::GetAddesses (  ) 

Returns list of the adapter's addresses.

Exceptions:
WpcError if the adapter doesn't initialized yet
Examples:
wpcInit.cpp.

string WpcAdapter::GetError (  ) 

Gets last error description.

Returns:
string that describes last occurred error

WpcAdapter & WpcAdapter::GetIface ( string  iface  )  [static]

Creates WpcAdapter object for the given interface.

Returns:
the WpcAdapter object or generates exception
Exceptions:
WpcError if the adapters list can't be generated
Examples:
wpcInit.cpp.

string WpcAdapter::GetIfaceDesc (  ) 

Gets interface description.

Returns:
the human readable interface name, or empty string if error occurred
Exceptions:
WpcError if the adapters list can't be generated
Examples:
wpcInit.cpp.

string WpcAdapter::GetIfaceDesc ( string  iface  )  [static]

Gets interface description.

Returns:
the human readable interface name, or empty string if error occurred
Exceptions:
WpcError if the adapters list can't be generated
Examples:
wpcCapture.cpp.

WpcState WpcAdapter::GetIfaceList ( WpcStringList *  lst  )  [static]

Gets interfaces list.

Builds list of symbolic names of available interfaces. These names are useful for internal operation. To obtain descriptions of the interfaces call GetIfaceDesc

Returns:
WPC_OK if no error occurred, or error code otherwise
Exceptions:
WpcError if the adapters list can't be generated
Examples:
wpcInit.cpp.

WpcMacAddr & WpcAdapter::GetMacAddr (  ) 

Gets adapter's MAC address.

Todo:
implement this operation at least for linux also, not Win32 only
Examples:
wpcInit.cpp.

static WpcMacAddr& WpcAdapter::GetTargetMAC ( WpcAddress addr = NULL  )  [static]

Gets MAC address of the target.

If the target is NULL then the default gateway address is returned. For the given address the ARP request will be performed to obtain hardware address of the host. ARP responses are cached to improve performance.

void WpcAdapter::InitAdapterList ( bool  force = false  )  [static, private]

Fills the list of adapters and creates adapters smart pointers.

Exceptions:
WpcError if the adapters list can't be generated

bool WpcAdapter::IsLoopback (  )  const

Returns whether the device is a loopback one.

WpcAdapter::operator bool (  )  [inline]

Gets the state of the WpcAdapter.

Returns:
true if the last operation was successful, and false otherwise

WpcAdapter & WpcAdapter::operator<< ( WpcPacket packet  ) 

Alias for SendPacket.

Puts the packet tor the sending queue.

Exceptions:
WpcError 

WpcAdapter & WpcAdapter::operator= ( WpcAdapter const &  copy  ) 

Copy operation.

WpcAdapter & WpcAdapter::operator>> ( WpcPacket packet  ) 

Alias for ReadPacket.

Reads the next packet available from the interface.

Exceptions:
WpcError 

void WpcAdapter::PushPacket ( WpcPacket pkt  )  [inline, protected]

Adds packet to the adapter's queue.

bool WpcAdapter::ReadPacket ( WpcPacket pkt  ) 

Reads the next packet available from the interface.

The read may fail if the timeout expires before any packet is captured.

Parameters:
pkt Initialized WpcPacket object to store data
Returns:
true if packet successfully read, false otherwise
Exceptions:
WpcError 
Examples:
wpcCapture.cpp.

void WpcAdapter::SendPacket ( WpcPacket pkt,
bool  autoComplete = false 
)

Puts the packet tor the sending queue.

Note that, even if you successfully open the network interface, you might not have permission to send packets on it, or it might not support sending packets; as the WpcAdapter constructor doesn't have a flag to indicate whether to open for capturing, sending, or capturing and sending, you cannot request a WpcAdapter that supports sending and be notified at construction time whether sending will be possible. Note also that some devices might not support sending packets.

On some platforms, the link-layer header of the packet that's sent might not be the same as the link-layer header of the packet supplied to SendPacket(), as the source link-layer address, if the header contains such an address, might be changed to be the address assigned to the interface on which the packet it sent, if the platform doesn't support sending completely raw and unchanged packets. Even worse, some drivers on some platforms might change the link-layer type field to whatever value libpcap used when attaching to the device, even on platforms that do nominally support sending completely raw and unchanged packets.

Parameters:
pkt The WpcPacket to be sent
autoComplete Whether to perform packet finalization before send
Exceptions:
WpcError 

void WpcAdapter::SetAdaptersOptions ( int  snaplen = WPC_MAXSNAPLEN,
bool  promisc = true,
int  timeout = 0 
) [static]

Sets the options for open libpcap's interfaces.

Options will be used on all interfaces which will be opened after this call

Parameters:
snaplen length of the packet that has to be retained. For each packet received by the filter, only the first 'snaplen' bytes are stored in the buffer and passed to the user application. For instance, snaplen equal to 100 means that only the first 100 bytes of each packet are stored.
promisc Whether the interface is to be put into promiscuous mode. (Note that even if this parameter is false, the interface could well be in promiscuous mode for some other reason.) For now, this doesn't work on the "any" device; if an argument of "any" or empty is supplied, the promisc parameter is ignored
timeout The read timeout, in miliseconds. It is used to arrange that the read not necessarily returns immediately when a packet is seen, but that it waits for some amount of time to allow more packets to arrive and to read multiple packets from the OS kernel in one operation. Not all platforms support a read timeout; on platforms that don't, the read timeout is ignored. A timeout of zero, on platforms that support a read timeout, will cause a read to wait forever to allow enough packets to arrive, with no timeout
Examples:
wpcInit.cpp.

void WpcAdapter::SetFilter ( string const &  expression,
bool  optimize = false,
bpf_u_int32  netmask = 0 
)

Apply a filter given by a BPF expression.

Parameters:
expression The filter expression
optimize Whether optimization on the resulting code is performed
netmask Specifies the IPv4 netmask of the network on which packets are being captured. It is used only when checking for IPv4 broadcast addresses in the filter program. If the netmask of the network on which packets are being captured isn't known to the program, or if packets are being captured on the Linux "any" pseudo-interface that can capture on more than one network, a value of 0 can be supplied; tests for IPv4 broadcast addresses won’t be done correctly, but all other tests in the filter program will be OK
Exceptions:
WpcError 

bool WpcAdapter::StartCapture ( string  filter = ""  ) 

Starts capture for adapter.

Returns:
true if capture process started, false - otherwise
Exceptions:
WpcError if the adapter doesn't initialized yet
Examples:
wpcCapture.cpp.

WpcState WpcAdapter::State (  )  [inline]

Gets the state of the WpcAdapter.

Returns:
current state of WpcAdapter

bool WpcAdapter::StopCapture (  ) 

Stops capture for adapter.

Returns:
true if capture process stopped, false - if capture doesn't started
Exceptions:
WpcError if the adapter doesn't initialized yet
Examples:
wpcCapture.cpp.


Member Data Documentation

List of adapters available to use with libpcap.

wrapped libpcap's interface

bool WpcAdapter::m_inCapture [private]

Is in capture process.

Receiving queue.

bool WpcAdapter::m_promisc = true [static, private]

Whether the interface is to be put into promiscuous mode.

string WpcAdapter::m_smbName [private]

adapter symbolic name

int WpcAdapter::m_snaplen = WPC_MAXSNAPLEN [static, private]

length of the packet that has to be retained.

WpcState WpcAdapter::m_status [private]

WpcObj status.

int WpcAdapter::m_timeout = 1 [static, private]

The read timeout, in miliseconds.



 
©2009 Positive Technologies
 
Generated on Fri May 22 18:17:01 2009 for wpcObj by 
 
 
1.5.7
 
Get wpcObj at SourceForge.net. Fast, secure and Free Open Source software downloads