Added experimental GeoIP code

This commit is contained in:
Michiel Broek 2007-08-21 20:48:06 +00:00
parent 1559b17713
commit 7986f415f7

View File

@ -79,13 +79,61 @@ char *typestr(int tp)
} }
#ifdef HAVE_GEOIP_H
void geoiplookup(GeoIP* gi,char *hostname,int i)
{
const char * country_code;
const char * country_name;
// const char * domain_name;
// int netspeed;
int country_id;
// GeoIPRegion * region;
GeoIPRecord * gir;
// const char * org;
if (GEOIP_COUNTRY_EDITION == i) {
country_id = GeoIP_id_by_name(gi, hostname);
country_code = GeoIP_country_code[country_id];
country_name = GeoIP_country_name[country_id];
if (country_code == NULL) {
Syslog('+', "%s: IP Address not found\n", GeoIPDBDescription[i]);
} else {
Syslog('+', "%s: %s, %s\n", GeoIPDBDescription[i], country_code, country_name);
}
} else if (GEOIP_CITY_EDITION_REV0 == i) {
gir = GeoIP_record_by_name(gi, hostname);
if (NULL == gir) {
Syslog('+', "%s: IP Address not found\n", GeoIPDBDescription[i]);
} else {
Syslog('+', "%s: %s, %s, %s, %s, %f, %f\n", GeoIPDBDescription[i], gir->country_code, gir->region,
gir->city, gir->postal_code,gir->latitude, gir->longitude);
}
} else if (GEOIP_CITY_EDITION_REV1 == i) {
gir = GeoIP_record_by_name(gi, hostname);
if (NULL == gir) {
Syslog('+', "%s: IP Address not found\n", GeoIPDBDescription[i]);
} else {
Syslog('+', "%s: %s, %s, %s, %s, %f, %f, %d, %d\n", GeoIPDBDescription[i], gir->country_code, gir->region, gir->city,
gir->postal_code, gir->latitude, gir->longitude, gir->dma_code, gir->area_code);
}
}
}
#endif
int session(faddr *a, node *nl, int role, int tp, char *dt) int session(faddr *a, node *nl, int role, int tp, char *dt)
{ {
int rc = MBERR_OK, addrlen = sizeof(struct sockaddr_in); int rc = MBERR_OK;
socklen_t addrlen = sizeof(struct sockaddr_in);
fa_list *tmpl; fa_list *tmpl;
int Fdo = -1, input_pipe[2], output_pipe[2]; int Fdo = -1, input_pipe[2], output_pipe[2];
pid_t ipid, opid; pid_t ipid, opid;
#ifdef HAVE_GEOIP_H
char *hostname;
int i;
GeoIP *gi;
#endif
session_flags = 0; session_flags = 0;
session_type = tp; session_type = tp;
@ -111,6 +159,24 @@ int session(faddr *a, node *nl, int role, int tp, char *dt)
} }
session_flags |= SESSION_TCP; session_flags |= SESSION_TCP;
#ifdef HAVE_GEOIP_H
hostname = inet_ntoa(peeraddr.sin_addr);
_GeoIP_setup_dbfilename();
Syslog('-', "Start GeoIP %s", hostname);
for (i = 0; i < NUM_DB_TYPES; ++i) {
if (GeoIP_db_avail(i)) {
Syslog('-', "Doing %s", GeoIPDBDescription[i]);
gi = GeoIP_open_type(i, GEOIP_STANDARD);
if (NULL == gi) {
// Syslog('+', "%s not available, skipping", GeoIPDBDescription[i]);
} else {
geoiplookup(gi,hostname,i);
}
GeoIP_delete(gi);
}
}
#endif
if (tcp_mode == TCPMODE_ITN) { if (tcp_mode == TCPMODE_ITN) {
Syslog('s', "Installing telnet filter..."); Syslog('s', "Installing telnet filter...");