Experimental GeoIP code
This commit is contained in:
parent
5870b3cceb
commit
dee7ecfce7
@ -55,6 +55,33 @@ int cols = 80; /* Screen columns */
|
|||||||
int rows = 24; /* Screen rows */
|
int rows = 24; /* 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)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
FILE *pTty;
|
FILE *pTty;
|
||||||
@ -63,6 +90,10 @@ int main(int argc, char **argv)
|
|||||||
struct stat sb;
|
struct stat sb;
|
||||||
struct winsize ws;
|
struct winsize ws;
|
||||||
unsigned char ch = 0;
|
unsigned char ch = 0;
|
||||||
|
#ifdef HAVE_GEOIP_H
|
||||||
|
char *hostname;
|
||||||
|
GeoIP *gi;
|
||||||
|
#endif
|
||||||
|
|
||||||
pTTY = calloc(15, sizeof(char));
|
pTTY = calloc(15, sizeof(char));
|
||||||
tty = ttyname(1);
|
tty = ttyname(1);
|
||||||
@ -314,6 +345,17 @@ int main(int argc, char **argv)
|
|||||||
/*
|
/*
|
||||||
* Network connection, no tty checking but fill a ttyinfo record.
|
* 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)) {
|
||||||
|
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));
|
memset(&ttyinfo, 0, sizeof(ttyinfo));
|
||||||
snprintf(ttyinfo.comment, 41, "%s", p);
|
snprintf(ttyinfo.comment, 41, "%s", p);
|
||||||
snprintf(ttyinfo.tty, 7, "%s", pTTY);
|
snprintf(ttyinfo.tty, 7, "%s", pTTY);
|
||||||
|
Reference in New Issue
Block a user