Added GeoIP support

This commit is contained in:
Michiel Broek
2007-10-14 13:15:34 +00:00
parent dee7ecfce7
commit e58d20dc08
4 changed files with 58 additions and 32 deletions

View File

@@ -50,6 +50,32 @@ char *StartTime;
int cols = 80; /* Screen columns */
int rows = 80; /* Screen rows */
#ifdef HAVE_GEOIP_H
extern void _GeoIP_setup_dbfilename(void);
void geoiplookup(GeoIP* gi, char *hostname, int i)
{
const char * country_code;
const char * country_name;
const char * country_continent;
int country_id;
if (GEOIP_COUNTRY_EDITION == i) {
country_id = GeoIP_id_by_name(gi, hostname);
Syslog('b', "geoiplookup '%s', id=%d", hostname, country_id);
country_code = GeoIP_country_code[country_id];
country_name = GeoIP_country_name[country_id];
country_continent = GeoIP_country_continent[country_id];
if (country_code == NULL) {
Syslog('+', "%s: IP Address not found\n", GeoIPDBDescription[i]);
} else {
Syslog('+', "GeoIP location: %s, %s %s\n", country_name, country_code, country_continent);
}
}
}
#endif
int main(int argc, char **argv)
{
@@ -58,6 +84,10 @@ int main(int argc, char **argv)
int i, rc = 0;
struct passwd *pw;
struct winsize ws;
#ifdef HAVE_GEOIP_H
char *hostname;
GeoIP *gi;
#endif
pTTY = calloc(15, sizeof(char));
tty = ttyname(1);
@@ -185,6 +215,16 @@ int main(int argc, char **argv)
/*
* Network connection, no tty checking but fill a ttyinfo record.
*/
#ifdef HAVE_GEOIP_H
hostname = xstrcpy(p);
_GeoIP_setup_dbfilename();
if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION)) {
if ((gi = GeoIP_open_type(GEOIP_COUNTRY_EDITION, GEOIP_STANDARD)) != NULL) {
geoiplookup(gi, hostname, GEOIP_COUNTRY_EDITION);
}
GeoIP_delete(gi);
}
#endif
memset(&ttyinfo, 0, sizeof(ttyinfo));
snprintf(ttyinfo.comment, 41, "%s", p);
snprintf(ttyinfo.tty, 7, "%s", pTTY);

View File

@@ -346,7 +346,6 @@ int main(int argc, char **argv)
* Network connection, no tty checking but fill a ttyinfo record.
*/
#ifdef HAVE_GEOIP_H
// hostname = inet_ntoa(peeraddr.sin_addr);
hostname = xstrcpy(p);
_GeoIP_setup_dbfilename();
if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION)) {