The Assimilation Project
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pcap_min.c File Reference

Simple pcap interface code. More...

#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <projectcommon.h>
#include <cdp.h>
#include <lldp.h>
#include <pcap_min.h>
#include <addrframe.h>
#include <proj_classes.h>
Include dependency graph for pcap_min.c:

Go to the source code of this file.

Data Structures

struct  pcap_filter_info
 Structure mapping Protocols known to (supported by) create_pcap_listener(). bits to the corresponding pcap filter expressions.
 

Macros

#define DIMOF(a)   (sizeof(a)/sizeof(a[0]))
 

Functions

DEBUGDECLARATIONS FSTATIC gboolean _enable_mcast_address (const char *addrstring, const char *dev, gboolean enable)
 Function to enable listening to a particular ethernet multicast address. More...
 
pcap_t * create_pcap_listener (const char *dev, gboolean blocking, unsigned listenmask, struct bpf_program *prog)
 Set up pcap listener for the given interfaces and protocols. More...
 
void close_pcap_listener (pcap_t *pcapdev, const char *dev, unsigned listenmask)
 Close this pcap_listener, and undo listens for multicast addresses. More...
 

Detailed Description

Simple pcap interface code.

This file is part of the Assimilation Project.

Author
Copyright © 2011, 2012 - Alan Robertson alanr.nosp@m.@uni.nosp@m.x.sh
The Assimilation software is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

The Assimilation software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the Assimilation Project software. If not, see http://www.gnu.org/licenses/

Todo:

In general, need to exclude sent packets from received packets even on those platforms (like Linux) where libpcap won't filter that for us. This will probably involve filtering by source MAC address.

convert all the messaging over to use the various glib logging functions.

Todo:
To figure out what the MAC address of an interface on Windows is, use the GetAdapterAddresses function - http://msdn.microsoft.com/en-us/library/aa365915(v=vs.85).aspx

Definition in file pcap_min.c.

Macro Definition Documentation

#define DIMOF (   a)    (sizeof(a)/sizeof(a[0]))

Definition at line 41 of file pcap_min.c.

Referenced by _enable_mcast_address(), close_pcap_listener(), and create_pcap_listener().

Function Documentation

FSTATIC gboolean _enable_mcast_address ( const char *  addrstring,
const char *  dev,
gboolean  enable 
)

Function to enable listening to a particular ethernet multicast address.

This is a highly non-portable function. I wonder how you do this on BSD or Slowlaris?

Parameters
[in]addrstringmulticast MAC address string suitable for giving to 'ip'
[in]devethernet device
[in]enableTRUE to enable, FALSE to disable

Definition at line 210 of file pcap_min.c.

References DEBUGMSG1, and DIMOF.

Referenced by close_pcap_listener(), and create_pcap_listener().

Here is the caller graph for this function:

void close_pcap_listener ( pcap_t *  pcapdev,
const char *  dev,
unsigned  listenmask 
)

Close this pcap_listener, and undo listens for multicast addresses.

Parameters
pcapdevPcap device structure
devdevice that this is opened on
listenmaskThe 'listenmask' given to create_pcap_listener

Definition at line 192 of file pcap_min.c.

References _enable_mcast_address(), and DIMOF.

Referenced by create_pcap_listener(), and g_source_pcap_finalize().

Here is the call graph for this function:

Here is the caller graph for this function:

pcap_t* create_pcap_listener ( const char *  dev,
gboolean  blocking,
unsigned  listenmask,
struct bpf_program *  prog 
)

Set up pcap listener for the given interfaces and protocols.

Returns
a properly configured pcap_t* object for listening for the given protocols - NULL on error
See Also
Protocols known to (supported by) create_pcap_listener().
Todo:
deal with pcap_set_timeout() call here.
Parameters
[in]devDevice name to listen on
[in]blockingTRUE if this is a blocking connection
[in]listenmaskBit mask of protocols to listen for (see list of valid bits)
[out]progCompiled PCAP program

Definition at line 66 of file pcap_min.c.

References _enable_mcast_address(), BINDDEBUG, close_pcap_listener(), DEBUGMSG1, and DIMOF.

Referenced by g_source_pcap_new().

Here is the call graph for this function:

Here is the caller graph for this function: