The Assimilation Project
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
GSource_Pcap class

Class representing a pcap GSource object - for capturing packets in the g_main_loop paradigm. More...

Collaboration diagram for GSource_Pcap class:

Functions

FSTATIC gboolean g_source_pcap_prepare (GSource *source,gint *timeout)
 The GMainLoop prepare function for libpcap packet capturing. More...
 
FSTATIC gboolean g_source_pcap_check (GSource *src)
 The GMainLoop check function for libpcap packet capturing. More...
 
FSTATIC gboolean g_source_pcap_dispatch (GSource *src,GSourceFunc callback,gpointer user_data)
 The GMainLoop dispatch function for libpcap packet capturing. More...
 
FSTATIC void g_source_pcap_finalize (GSource *src)
 The GMainLoop finalize function for libpcap packet capturing Called when this object is 'finalized' (destroyed) More...
 
FSTATIC guint64 proj_timeval_to_g_real_time (const struct timeval *tv)
 Convert struct timeval to g_get_real_time() style value. More...
 
GSource * g_source_pcap_new (const char *dev, unsigned listenmask, gboolean(*dispatch)(GSource_pcap_t *gsource, pcap_t *capstruct, gconstpointer pkt, gconstpointer pend, const struct pcap_pkthdr *pkthdr, const char *capturedev, gpointer userdata), GDestroyNotify notify, gint priority, gboolean can_recurse, GMainContext *context, gsize objectsize, gpointer userdata)
 Construct new GSource from a newly constructed pcap capture object. More...
 
FrameSetconstruct_pcap_frameset (guint16 framesettype, gconstpointer pkt, gconstpointer pktend, const struct pcap_pkthdr *pkthdr, const char *interfacep)
 Construct a PCAP capture FrameSet from a PCAP packet. More...
 

Detailed Description

Class representing a pcap GSource object - for capturing packets in the g_main_loop paradigm.

This is technically a subclass of GSource (which isn't part of this project).

Function Documentation

FrameSet* construct_pcap_frameset ( guint16  framesettype,
gconstpointer  pkt,
gconstpointer  pktend,
const struct pcap_pkthdr *  pkthdr,
const char *  interfacep 
)

Construct a PCAP capture FrameSet from a PCAP packet.

Parameters
[in]framesettypetype to create FrameSet with
[in]pktcaptured packet
[in]pktendone byte past end of pkt
[in]pkthdrlibpcap packet header
[in]interfacepinterface it was captured on

Definition at line 237 of file pcap_GSource.c.

References _CstringFrame::baseclass, _IntFrame::baseclass, cstringframe_new(), frame_new(), frameset_append_frame(), frameset_new(), FRAMETYPE_HOSTNAME, FRAMETYPE_INTERFACE, FRAMETYPE_PKTDATA, FRAMETYPE_WALLCLOCK, intframe_new(), MALLOC0, proj_get_sysname(), proj_timeval_to_g_real_time(), _IntFrame::setint, _Frame::setvalue, UNREF, and UNREF2.

Referenced by _switchdiscovery_dispatch().

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean g_source_pcap_check ( GSource *  src)

The GMainLoop check function for libpcap packet capturing.

Parameters
[in]srcsource being checked

Definition at line 170 of file pcap_GSource.c.

References CASTTOCLASS, and _GSource_pcap::gfd.

gboolean g_source_pcap_dispatch ( GSource *  src,
GSourceFunc  callback,
gpointer  user_data 
)

The GMainLoop dispatch function for libpcap packet capturing.

Parameters
[in]srcsource being dispatched
[in]callbackdispatch function (ignored)
[in]user_datauser data (ignored)

Definition at line 180 of file pcap_GSource.c.

References _GSource_pcap::capture, _GSource_pcap::capturedev, CASTTOCLASS, _GSource_pcap::dispatch, _GSource_pcap::gfd, and _GSource_pcap::userdata.

void g_source_pcap_finalize ( GSource *  source)

The GMainLoop finalize function for libpcap packet capturing Called when this object is 'finalized' (destroyed)

Definition at line 209 of file pcap_GSource.c.

References _GSource_pcap::capture, _GSource_pcap::capturedev, CASTTOCLASS, close_pcap_listener(), _GSource_pcap::destroynote, _GSource_pcap::listenmask, _GSource_pcap::pcprog, and proj_class_dissociate().

Here is the call graph for this function:

GSource* g_source_pcap_new ( const char *  dev,
unsigned  listenmask,
gboolean(*)(GSource_pcap_t *gsource, pcap_t *capstruct, gconstpointer pkt, gconstpointer pend, const struct pcap_pkthdr *pkthdr, const char *capturedev, gpointer userdata)  dispatch,
GDestroyNotify  notify,
gint  priority,
gboolean  can_recurse,
GMainContext *  context,
gsize  objectsize,
gpointer  userdata 
)

Construct new GSource from a newly constructed pcap capture object.

We use create_pcap_listener() to construct the pcap capture object. This code is based on the the Glib main event loop (g_main_loop) event scheduler/dispatcher concept.

Todo:
investigate whether create_pcap_listener() might need more parameters to allow for non-blocking reads... (?)
Parameters
[in]devCapture device name
[in]listenmaskbit mask of supported protocols [in] called when new pcap data has arrived
[in,out]dispatchuser-object
[in]notifyCalled when this object is being destroyed - can be NULL.
[in]priorityg_main_loop dispatch priority
[in]can_recurseTRUE if dispatch recursion is allowed
[in]contextGMainContext or NULL
[in]objectsizesize of pcap_g_source object to create (or zero)
[in,out]userdatapointer to user object for dispatch function

Definition at line 86 of file pcap_GSource.c.

References _GSource_pcap::capture, _GSource_pcap::capturedev, _GSource_pcap::capturefd, CASTTOCLASS, create_pcap_listener(), _GSource_pcap::destroynote, _GSource_pcap::dispatch, _GSource_pcap::gfd, _GSource_pcap::gsourceid, _GSource_pcap::listenmask, _GSource_pcap::pcprog, proj_class_register_object(), proj_class_register_subclassed(), and _GSource_pcap::userdata.

Referenced by switchdiscovery_new().

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean g_source_pcap_prepare ( GSource *  source,
gint *  timeout 
)

The GMainLoop prepare function for libpcap packet capturing.

Parameters
[in]sourceGsource being prepared for
[in,out]timeouttimeout - neither referenced nor set

Definition at line 160 of file pcap_GSource.c.

FSTATIC guint64 proj_timeval_to_g_real_time ( const struct timeval *  tv)

Convert struct timeval to g_get_real_time() style value.

Definition at line 227 of file pcap_GSource.c.

Referenced by construct_pcap_frameset().

Here is the caller graph for this function: