Main Page | Data Structures | File List | Data Fields | Globals

libipg_init.c File Reference

ipgeo initialization routines More...

#include "./libipg.h"

Go to the source code of this file.

Functions

ipgeo_tipgeo_init (char *file, u_int8_t flags, char *err_buf)
void ipgeo_destroy (ipgeo_t *ipg)
char * ipgeo_geterror (ipgeo_t *ipg)
int ipgeo_getdbt (ipgeo_t *ipg)
int ipgeo_getfd (ipgeo_t *ipg)


Detailed Description

ipgeo initialization routines

Author:
Mike Schiffman

Definition in file libipg_init.c.


Function Documentation

ipgeo_t* ipgeo_init char *  file,
u_int8_t  flags,
char *  err_buf
 

only CSV db type currently supported

control flags are currently undefined

Definition at line 49 of file libipg_init.c.

References ipgeo_context::db, ipgeo_context::dbt, ipgeo_context::flags, and ipgeo_t.

00050 {
00051     ipgeo_t *ipg = NULL;
00052 
00053     ipg = (ipgeo_t *)malloc(sizeof (ipgeo_t));
00054     if (ipg == NULL)
00055     {
00056         snprintf(err_buf, IPGEO_ERRBUF_SIZE, "malloc(): %s\n", strerror(errno));
00057         goto bad;
00058     }
00059 
00060     memset(ipg, 0, sizeof (ipg));
00061 
00062     ipg->db = fopen(file, "r");
00063     if (ipg->db == NULL)
00064     {
00065         snprintf(err_buf, IPGEO_ERRBUF_SIZE, "fopen() (%s): %s\n", file, 
00066                 strerror(errno));
00067         goto bad;
00068     }
00069 
00071     ipg->dbt = 6;
00072 
00074     ipg->flags = flags;
00075 
00076     return (ipg);
00077 
00078 bad:
00079     if (ipg)
00080     {
00081         if (ipg->db)
00082         {
00083             fclose(ipg->db);
00084         }
00085         free (ipg);
00086     }
00087     return (NULL);
00088 }

void ipgeo_destroy ipgeo_t ipg  ) 
 

Shuts down the libipg session and frees all memory referenced by ipg.

Parameters:
ipg pointer to a ipgeo context

Definition at line 91 of file libipg_init.c.

References ipgeo_context::db, and ipgeo_t.

00092 {
00093     if (ipg)
00094     {
00095         if (ipg->db)
00096         {
00097             fclose(ipg->db);
00098         }
00099         free (ipg);
00100     }
00101 }

char* ipgeo_geterror ipgeo_t ipg  ) 
 

Returns the last error set inside of the referenced libipg context. This function should be called anytime a function fails or an error condition is detected inside of libipg.

Parameters:
ipg pointer to a libipg context
Returns:
an error string or NULL if no error has occured

Definition at line 104 of file libipg_init.c.

References ipgeo_context::err_buf, and ipgeo_t.

00105 {
00106     return (ipg->err_buf);
00107 }

int ipgeo_getdbt ipgeo_t ipg  ) 
 

Returns the type of IP2LOCATION db libipg has open.

Parameters:
ipg pointer to a ipgeo context
Returns:
the type of db open

Definition at line 110 of file libipg_init.c.

References ipgeo_context::db, ipgeo_context::dbt, and ipgeo_t.

00111 {
00112     if (ipg == NULL || ipg->db == NULL)
00113     {
00114         return (-1);
00115     }
00116     return (ipg->dbt);
00117 }

int ipgeo_getfd ipgeo_t ipg  ) 
 

we should not return -1 here since any error should be caught during initialization

Definition at line 120 of file libipg_init.c.

References ipgeo_context::db, and ipgeo_t.

00121 {
00122     if (ipg == NULL || ipg->db == NULL)
00123     {
00124         return (-1);
00125     }
00126 
00131     return (fileno(ipg->db));
00132 }


Generated on Wed Dec 31 12:06:49 2003 for libipg by doxygen 1.3.4