Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

iprange.c File Reference


Detailed Description

Needs brief description here.

Load, parse and lookup IP addresses from a set of IP ranges defined by a list of addresses in CIDR (Classless Internet Domain Routing) format.

Author:
Raphael Manfredi
Date:
2004

#include "common.h"
#include "iprange.h"
#include "misc.h"
#include "walloc.h"
#include "override.h"

Data Structures

struct  iprange_db
struct  iprange_net
 A CIDR network description. More...


Defines

#define IPRANGE_MARK   1 /**< Magic tagging of user values */
 Magic tagging of user values.

#define IPRANGE_MAGIC   0x01b3a59e
#define IPAGESZ   256

Functions

 RCSID ("$Id:iprange.c, v 1.9 2005/06/29 14:24:26 daichik Exp $")
const gchar * iprange_strerror (iprange_err_t errnum)
void iprange_free_nop (gpointer unused_value, gpointer unused_updata)
 Null free callback, when values held in database are not pointers and we need to force insertion.

gpointer iprange_clone_nop (gpointer value)
 Identity clone callback, when values are not pointers and not meant to be freed.

gpointer iprange_make (iprange_free_t freecb, iprange_clone_t clonecb)
 Create a new IP range database.

void iprange_free_each (gpointer db, gpointer udata)
 Free values stored in the IP range database, then destroy database.

iprange_err_t iprange_add_level1 (struct iprange_db *idb, guint32 net, guint bits, gpointer udata, gboolean force)
 Add network in the level-1 page of the database.

iprange_err_t iprange_add_level2 (struct iprange_db *idb, guint32 net, guint bits, gpointer *lvl2, gpointer udata, gboolean force)
 Add network in the level-2 page of the database.

iprange_err_t iprange_add_cidr_internal (gpointer db, guint32 net, guint bits, gpointer udata, gboolean force, gpointer cdata)
 Add CIDR network to the database (common routine for both plain and forced database insertions).

iprange_err_t iprange_add_cidr (gpointer db, guint32 net, guint bits, gpointer udata)
 Add CIDR network to the database.

iprange_err_t iprange_add_cidr_force (gpointer db, guint32 net, guint bits, gpointer udata, gpointer cdata)
 Add CIDR network to the database, forcing entry if new range supersedes an older range.

gpointer iprange_get (gpointer db, guint32 ip)
 Retrieve value associated with an IP address, i.e.

void iprange_get_stats (gpointer db, iprange_stats_t *stats)
 Get statistics about the database.


Variables

const gchar * iprange_errstr []
 Error code stings.


Define Documentation

#define IPAGESZ   256
 

#define IPRANGE_MAGIC   0x01b3a59e
 

#define IPRANGE_MARK   1 /**< Magic tagging of user values */
 

Magic tagging of user values.


Function Documentation

iprange_err_t iprange_add_cidr gpointer  db,
guint32  net,
guint  bits,
gpointer  udata
 

Add CIDR network to the database.

Parameters:
db the IP range database
net the network prefix
bits the amount of bits in the network prefix
udata value associated to this IP network
Returns:
IPR_ERR_OK if successful, an error code otherwise.

iprange_err_t iprange_add_cidr_force gpointer  db,
guint32  net,
guint  bits,
gpointer  udata,
gpointer  cdata
 

Add CIDR network to the database, forcing entry if new range supersedes an older range.

Parameters:
db the IP range database
net the network prefix
bits the amount of bits in the network prefix
udata value associated to this IP network
cdata extra parameter to pass to free callback, if invoked
Returns:
IPR_ERR_OK if successful, an error code otherwise.

iprange_err_t iprange_add_cidr_internal gpointer  db,
guint32  net,
guint  bits,
gpointer  udata,
gboolean  force,
gpointer  cdata
[static]
 

Add CIDR network to the database (common routine for both plain and forced database insertions).

Parameters:
db the IP range database
net the network prefix
bits the amount of bits in the network prefix
udata value associated to this IP network
force force insertion, possibly freeing subnets already registered
cdata extra parameter to pass to free callback, if invoked
Returns:
IPR_ERR_OK if successful, an error code otherwise.

iprange_err_t iprange_add_level1 struct iprange_db idb,
guint32  net,
guint  bits,
gpointer  udata,
gboolean  force
[static]
 

Add network in the level-1 page of the database.

iprange_err_t iprange_add_level2 struct iprange_db idb,
guint32  net,
guint  bits,
gpointer *  lvl2,
gpointer  udata,
gboolean  force
[static]
 

Add network in the level-2 page of the database.

gpointer iprange_clone_nop gpointer  value  )  [static]
 

Identity clone callback, when values are not pointers and not meant to be freed.

void iprange_free_each gpointer  db,
gpointer  udata
 

Free values stored in the IP range database, then destroy database.

Parameters:
db the database
udata trailing user-supplied data, passed to freeing callback

void iprange_free_nop gpointer  unused_value,
gpointer  unused_updata
[static]
 

Null free callback, when values held in database are not pointers and we need to force insertion.

gpointer iprange_get gpointer  db,
guint32  ip
 

Retrieve value associated with an IP address, i.e.

that of the range containing it.

void iprange_get_stats gpointer  db,
iprange_stats_t stats
 

Get statistics about the database.

Parameters:
db the database
stats the supplied structure to fill

gpointer iprange_make iprange_free_t  freecb,
iprange_clone_t  clonecb
 

Create a new IP range database.

const gchar* iprange_strerror iprange_err_t  errnum  ) 
 

Returns:
human-readable error string for given error code.

RCSID "$Id:iprange.  c,
v 1.9 2005/06/29 14:24:26 daichik Exp $" 
 


Variable Documentation

const gchar* iprange_errstr[] [static]
 

Initial value:

 {
    "OK",                                   
    "Incorrect network prefix",             
    "CIDR range clash",                     
    "Duplicate range",                      
    "Range is subnet of existing range",    
    "Range is overlapping existing range",  
}
Error code stings.


Generated on Sun Feb 12 10:50:03 2006 for Gtk-Gnutella by doxygen 1.3.6