Classes | |
class | WpcAdapterInfo |
smart pointer to libpcap's structure pcap_t More... | |
Public Member Functions | |
WpcAdapter () | |
Default constructor. | |
WpcAdapter (WpcAdapter const &) | |
Copy constructor. | |
WpcAdapter & | operator= (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. | |
WpcAddressList & | GetAddesses () |
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. | |
WpcAdapter & | operator<< (WpcPacket &packet) |
Alias for SendPacket. | |
WpcAdapter & | operator>> (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. | |
WpcMacAddr & | GetMacAddr () |
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 WpcAdapter & | GetIface (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 WpcMacAddr & | GetTargetMAC (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. | |
WpcAdapterInfo * | m_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. |
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.
wpcCapture.cpp, and wpcInit.cpp.
typedef map<string, WpcAdapterInfo*> WpcAdapter::WpcAdapterList [private] |
List of the wrapped libpcap's interfaces.
WpcAdapter::WpcAdapter | ( | ) |
Default constructor.
WpcAdapter::WpcAdapter | ( | WpcAdapter const & | copy | ) |
Copy constructor.
WpcAdapter::~WpcAdapter | ( | ) |
WpcAdapter::WpcAdapter | ( | string | name | ) | [protected] |
WpcAddressList & WpcAdapter::GetAddesses | ( | ) |
Returns list of the adapter's addresses.
WpcError | if the adapter doesn't initialized yet |
string WpcAdapter::GetError | ( | ) |
Gets last error description.
WpcAdapter & WpcAdapter::GetIface | ( | string | iface | ) | [static] |
Creates WpcAdapter object for the given interface.
WpcError | if the adapters list can't be generated |
string WpcAdapter::GetIfaceDesc | ( | ) |
Gets interface description.
WpcError | if the adapters list can't be generated |
string WpcAdapter::GetIfaceDesc | ( | string | iface | ) | [static] |
Gets interface description.
WpcError | if the adapters list can't be generated |
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
WpcError | if the adapters list can't be generated |
WpcMacAddr & WpcAdapter::GetMacAddr | ( | ) |
Gets adapter's MAC address.
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.
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.
WpcAdapter & WpcAdapter::operator<< | ( | WpcPacket & | packet | ) |
WpcAdapter & WpcAdapter::operator= | ( | WpcAdapter const & | copy | ) |
Copy operation.
WpcAdapter & WpcAdapter::operator>> | ( | WpcPacket & | packet | ) |
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.
pkt | Initialized WpcPacket object to store data |
WpcError |
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.
pkt | The WpcPacket to be sent | |
autoComplete | Whether to perform packet finalization before send |
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
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 |
void WpcAdapter::SetFilter | ( | string const & | expression, | |
bool | optimize = false , |
|||
bpf_u_int32 | netmask = 0 | |||
) |
Apply a filter given by a BPF expression.
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 |
WpcError |
bool WpcAdapter::StartCapture | ( | string | filter = "" |
) |
Starts capture for adapter.
WpcError | if the adapter doesn't initialized yet |
WpcState WpcAdapter::State | ( | ) | [inline] |
bool WpcAdapter::StopCapture | ( | ) |
Stops capture for adapter.
WpcError | if the adapter doesn't initialized yet |
WpcAdapter::WpcAdapterList WpcAdapter::m_adapterList [static, private] |
List of adapters available to use with libpcap.
WpcAdapterInfo* WpcAdapter::m_iface [private] |
wrapped libpcap's interface
bool WpcAdapter::m_inCapture [private] |
Is in capture process.
WpcPacketList WpcAdapter::m_pktList [private] |
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 |
|