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

iprange.c File Reference


Detailed Description

Lookup IPv4 addresses from a set of IPv4 ranges defined by a list of addresses in CIDR (Classless Internet Domain Routing) format.

Author:
Raphael Manfredi
Date:
2004
Author:
Christian Biere
Date:
2007

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

Data Structures

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

Enumerations

enum  iprange_db_magic { IPRANGE_DB_MAGIC = 0x01b3a59e }

Functions

void iprange_db_check (const struct iprange_db *const idb)
const gchar * iprange_strerror (iprange_err_t errnum)
int iprange_net_cmp (const void *p, const void *q)
iprange_dbiprange_new (void)
 Create a new IP range database.
void iprange_free (struct iprange_db **idb_ptr)
 Destroy the database.
void * iprange_get (const struct iprange_db *idb, guint32 ip)
 Retrieve value associated with an IPv4 address, i.e.
iprange_err_t iprange_add_cidr (struct iprange_db *idb, guint32 net, guint bits, void *value)
 Add CIDR network to the database.
int iprange_net_collision (const void *p, const void *q)
void iprange_sync (struct iprange_db *idb)
 This function must be called after iprange_add_cidr() to make the changes effective.
guint iprange_get_item_count (const struct iprange_db *idb)
 Get the number of ranges in the database.
guint iprange_get_host_count (const struct iprange_db *idb)
 Calculate the number of hosts covered by the ranges in the database.

Variables

const gchar * iprange_errstr []
 Error code stings.


Enumeration Type Documentation

enum iprange_db_magic
 

Enumeration values:
IPRANGE_DB_MAGIC 


Function Documentation

iprange_err_t iprange_add_cidr struct iprange_db idb,
guint32  net,
guint  bits,
void *  value
 

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
value value associated to this IP network
Returns:
IPR_ERR_OK if successful, an error code otherwise.

void iprange_db_check const struct iprange_db *const   idb  )  [inline, static]
 

void iprange_free struct iprange_db **  idb_ptr  ) 
 

Destroy the database.

Parameters:
db the database

void* iprange_get const struct iprange_db idb,
guint32  ip
 

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

that of the range containing it.

Parameters:
db the IP range database
ip the IPv4 address to lookup
Returns:
The data associated with the IPv address or NULL if not found.

guint iprange_get_host_count const struct iprange_db idb  ) 
 

Calculate the number of hosts covered by the ranges in the database.

Parameters:
db the IP range database
Returns:
The number of hosts listed.

guint iprange_get_item_count const struct iprange_db idb  ) 
 

Get the number of ranges in the database.

Parameters:
db the IP range database
Returns:
The number of items.

int iprange_net_cmp const void *  p,
const void *  q
[inline, static]
 

int iprange_net_collision const void *  p,
const void *  q
[inline, static]
 

struct iprange_db* iprange_new void   ) 
 

Create a new IP range database.

const gchar* iprange_strerror iprange_err_t  errnum  ) 
 

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

void iprange_sync struct iprange_db idb  ) 
 

This function must be called after iprange_add_cidr() to make the changes effective.

As this function is costly, it should not be called each time but rather after the complete list of addresses has been added to the database.

Parameters:
db the IP range database


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 Sat Jun 30 17:53:28 2007 for gtk-gnutella by  doxygen 1.3.9.1