0.95.12 develop 1, a lot of systems calls changed to universal IPv4/IPv6 functions
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* $Id: mbnntp.c,v 1.24 2007/10/14 15:29:58 mbse Exp $
|
||||
* Purpose ...............: MBSE NNTP Server
|
||||
*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 1997-2007
|
||||
* Copyright (C) 1997-2011
|
||||
*
|
||||
* Michiel Broek FIDO: 2:280/2802
|
||||
* Beekmansbos 10
|
||||
@@ -42,7 +41,8 @@
|
||||
time_t t_start;
|
||||
time_t t_end;
|
||||
char *envptr = NULL;
|
||||
struct sockaddr_in peeraddr;
|
||||
struct sockaddr_in peeraddr4;
|
||||
struct sockaddr_in6 peeraddr6;
|
||||
pid_t mypid;
|
||||
unsigned int rcvdbytes = 0L;
|
||||
unsigned int sentbytes = 0L;
|
||||
@@ -124,6 +124,17 @@ void geoiplookup(GeoIP* gi, char *hostname, int i)
|
||||
Syslog('+', "GeoIP location: %s, %s %s\n", country_name, country_code, country_continent);
|
||||
}
|
||||
}
|
||||
if (GEOIP_COUNTRY_EDITION_V6 == i) {
|
||||
country_id = GeoIP_id_by_name_v6(gi, hostname);
|
||||
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
|
||||
|
||||
@@ -133,9 +144,9 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
struct passwd *pw;
|
||||
int i, rc;
|
||||
socklen_t addrlen = sizeof(struct sockaddr_in);
|
||||
socklen_t addrlen = sizeof(struct sockaddr_in6);
|
||||
char str[INET6_ADDRSTRLEN];
|
||||
#ifdef HAVE_GEOIP_H
|
||||
char *hostname;
|
||||
GeoIP *gi;
|
||||
#endif
|
||||
|
||||
@@ -190,18 +201,34 @@ int main(int argc, char *argv[])
|
||||
if ((rc = rawport()) != 0)
|
||||
WriteError("Unable to set raw mode");
|
||||
else {
|
||||
if (getpeername(0,(struct sockaddr*)&peeraddr,&addrlen) == 0) {
|
||||
Syslog('s', "TCP connection: len=%d, family=%hd, port=%hu, addr=%s",
|
||||
addrlen,peeraddr.sin_family, peeraddr.sin_port, inet_ntoa(peeraddr.sin_addr));
|
||||
Syslog('+', "Incoming connection from %s", inet_ntoa(peeraddr.sin_addr));
|
||||
if (getpeername(0,(struct sockaddr*)&peeraddr6,&addrlen) == 0) {
|
||||
/*
|
||||
* Copy IPv4 part into the IPv6 structure. There has to be a better way
|
||||
* to deal with mixed incoming sockets ???
|
||||
*/
|
||||
memcpy(&peeraddr4, &peeraddr6, sizeof(struct sockaddr_in));
|
||||
if ((peeraddr6.sin6_family == AF_INET6) && (inet_ntop(AF_INET6, &peeraddr6.sin6_addr, str, sizeof(str)))) {
|
||||
Syslog('+', "Incoming IPv6 connection from %s", str);
|
||||
} else if ((peeraddr4.sin_family == AF_INET) && (inet_ntop(AF_INET, &peeraddr4.sin_addr, str, sizeof(str)))) {
|
||||
Syslog('+', "Incoming IPv4 connection from %s", str);
|
||||
}
|
||||
|
||||
#ifdef HAVE_GEOIP_H
|
||||
hostname = inet_ntoa(peeraddr.sin_addr);
|
||||
_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);
|
||||
if (peeraddr6.sin6_family == AF_INET6) {
|
||||
if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION_V6)) {
|
||||
if ((gi = GeoIP_open_type(GEOIP_COUNTRY_EDITION_V6, GEOIP_STANDARD)) != NULL) {
|
||||
geoiplookup(gi, str, GEOIP_COUNTRY_EDITION_V6);
|
||||
}
|
||||
GeoIP_delete(gi);
|
||||
}
|
||||
} else if (peeraddr6.sin6_family == AF_INET) {
|
||||
if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION)) {
|
||||
if ((gi = GeoIP_open_type(GEOIP_COUNTRY_EDITION, GEOIP_STANDARD)) != NULL) {
|
||||
geoiplookup(gi, str, GEOIP_COUNTRY_EDITION);
|
||||
}
|
||||
GeoIP_delete(gi);
|
||||
}
|
||||
GeoIP_delete(gi);
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_NEWSGATE
|
||||
|
Reference in New Issue
Block a user