"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "apps/geoiplookup6.c" between
GeoIP-1.6.11.tar.gz and GeoIP-1.6.12.tar.gz

About: GeoIP is a C library that enables the user to find the country that any IP address or hostname originates from (contains an initial free GeoIP Country database).

geoiplookup6.c  (GeoIP-1.6.11):geoiplookup6.c  (GeoIP-1.6.12)
skipping to change at line 18 skipping to change at line 18
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version. * version 2.1 of the License, or (at your option) any later version.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 US A * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "GeoIP.h" #include "GeoIP.h"
#include "GeoIPCity.h" #include "GeoIPCity.h"
#include "GeoIP_internal.h" #include "GeoIP_internal.h"
void geoiplookup(GeoIP * gi, char *hostname, int i); void geoiplookup(GeoIP *gi, char *hostname, int i);
void usage() void usage(void) {
{ fprintf(stderr,
fprintf( "Usage: geoiplookup [-h] [-d custom_dir] [-f custom_file] "
stderr, "[-v] <ipaddress|hostname>\n");
"Usage: geoiplookup [-h] [-d custom_dir] [-f custom_file] [-v] <ipaddres
s|hostname>\n");
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[]) {
{ char *hostname = NULL;
char * hostname = NULL; char *db_info;
char * db_info; GeoIP *gi;
GeoIP * gi;
int i; int i;
char *custom_directory = NULL; char *custom_directory = NULL;
char *custom_file = NULL; char *custom_file = NULL;
int version_flag = 0; int version_flag = 0;
if (argc < 2) { if (argc < 2) {
usage(); usage();
exit(1); exit(1);
} }
i = 1; i = 1;
while (i < argc) { while (i < argc) {
if (strcmp(argv[i], "-v") == 0) { if (strcmp(argv[i], "-v") == 0) {
version_flag = 1; version_flag = 1;
} else if (strcmp(argv[i], "-h") == 0 } else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-?") == 0) {
|| strcmp(argv[i], "-?") == 0) {
usage(); usage();
exit(0); exit(0);
} else if (strcmp(argv[i], "-f") == 0) { } else if (strcmp(argv[i], "-f") == 0) {
if ((i + 1) < argc) { if ((i + 1) < argc) {
i++; i++;
custom_file = argv[i]; custom_file = argv[i];
} }
} else if (strcmp(argv[i], "-d") == 0) { } else if (strcmp(argv[i], "-d") == 0) {
if ((i + 1) < argc) { if ((i + 1) < argc) {
i++; i++;
skipping to change at line 88 skipping to change at line 85
_GeoIP_setup_dbfilename(); _GeoIP_setup_dbfilename();
if (custom_file != NULL) { if (custom_file != NULL) {
gi = GeoIP_open(custom_file, GEOIP_STANDARD | GEOIP_SILENCE); gi = GeoIP_open(custom_file, GEOIP_STANDARD | GEOIP_SILENCE);
if (NULL == gi) { if (NULL == gi) {
printf("%s not available, skipping...\n", custom_file); printf("%s not available, skipping...\n", custom_file);
} else { } else {
i = GeoIP_database_edition(gi); i = GeoIP_database_edition(gi);
if (version_flag == 1) { if (version_flag == 1) {
db_info = GeoIP_database_info(gi); db_info = GeoIP_database_info(gi);
printf("%s: %s\n", GeoIPDBDescription[i], printf("%s: %s\n",
db_info == NULL ? "" : db_info ); GeoIPDBDescription[i],
db_info == NULL ? "" : db_info);
free(db_info); free(db_info);
} else { } else {
geoiplookup(gi, hostname, i); geoiplookup(gi, hostname, i);
} }
} }
GeoIP_delete(gi); GeoIP_delete(gi);
} else { } else {
/* iterate through different database types */ /* iterate through different database types */
for (i = 0; i < NUM_DB_TYPES; ++i) { for (i = 0; i < NUM_DB_TYPES; ++i) {
if (GeoIP_db_avail(i)) { if (GeoIP_db_avail(i)) {
skipping to change at line 123 skipping to change at line 121
geoiplookup(gi, hostname, i); geoiplookup(gi, hostname, i);
} }
} }
GeoIP_delete(gi); GeoIP_delete(gi);
} }
} }
} }
return 0; return 0;
} }
static const char * _mk_NA( const char * p ) static const char *_mk_NA(const char *p) { return p ? p : "N/A"; }
{
return p ? p : "N/A";
}
void void geoiplookup(GeoIP *gi, char *hostname, int i) {
geoiplookup(GeoIP * gi, char *hostname, int i)
{
const char *country_code; const char *country_code;
const char *country_name; const char *country_name;
const char *asnum_name; const char *asnum_name;
int country_id; int country_id;
GeoIPRecord *gir; GeoIPRecord *gir;
geoipv6_t ipnum; geoipv6_t ipnum;
ipnum = _GeoIP_lookupaddress_v6(hostname); ipnum = _GeoIP_lookupaddress_v6(hostname);
if (__GEOIP_V6_IS_NULL(ipnum)) { if (__GEOIP_V6_IS_NULL(ipnum)) {
printf("%s: can't resolve hostname ( %s )\n", GeoIPDBDescription[i], printf("%s: can't resolve hostname ( %s )\n",
GeoIPDBDescription[i],
hostname); hostname);
}else { } else {
if (GEOIP_LOCATIONA_EDITION_V6 == i || GEOIP_ASNUM_EDITION_V6 == i || if (GEOIP_LOCATIONA_EDITION_V6 == i || GEOIP_ASNUM_EDITION_V6 == i ||
GEOIP_USERTYPE_EDITION_V6 == i || GEOIP_REGISTRAR_EDITION_V6 == GEOIP_USERTYPE_EDITION_V6 == i || GEOIP_REGISTRAR_EDITION_V6 == i ||
i ||
GEOIP_DOMAIN_EDITION_V6 == i || GEOIP_ORG_EDITION_V6 == i || GEOIP_DOMAIN_EDITION_V6 == i || GEOIP_ORG_EDITION_V6 == i ||
GEOIP_ISP_EDITION_V6 == i || GEOIP_NETSPEED_EDITION_REV1_V6 == i) { GEOIP_ISP_EDITION_V6 == i || GEOIP_NETSPEED_EDITION_REV1_V6 == i) {
asnum_name = GeoIP_name_by_ipnum_v6(gi, ipnum); asnum_name = GeoIP_name_by_ipnum_v6(gi, ipnum);
if (asnum_name == NULL) { if (asnum_name == NULL) {
printf("%s: IP Address not found\n", GeoIPDBDescription[i]); printf("%s: IP Address not found\n", GeoIPDBDescription[i]);
}else { } else {
printf("%s: %s\n", GeoIPDBDescription[i], asnum_name); printf("%s: %s\n", GeoIPDBDescription[i], asnum_name);
} }
}else if (GEOIP_CITY_EDITION_REV0_V6 == i) { } else if (GEOIP_CITY_EDITION_REV0_V6 == i) {
gir = GeoIP_record_by_ipnum_v6(gi, ipnum); gir = GeoIP_record_by_ipnum_v6(gi, ipnum);
if (NULL == gir) { if (NULL == gir) {
printf("%s: IP Address not found\n", GeoIPDBDescription[i]); printf("%s: IP Address not found\n", GeoIPDBDescription[i]);
}else { } else {
printf("%s: %s, %s, %s, %s, %f, %f\n", GeoIPDBDescription[i], printf("%s: %s, %s, %s, %s, %f, %f\n",
gir->country_code, _mk_NA( GeoIPDBDescription[i],
gir->region), gir->country_code,
_mk_NA(gir->city), _mk_NA( _mk_NA(gir->region),
gir->postal_code), gir->latitude, gir->longitude); _mk_NA(gir->city),
_mk_NA(gir->postal_code),
gir->latitude,
gir->longitude);
} }
}else if (GEOIP_CITY_EDITION_REV1_V6 == i) { } else if (GEOIP_CITY_EDITION_REV1_V6 == i) {
gir = GeoIP_record_by_ipnum_v6(gi, ipnum); gir = GeoIP_record_by_ipnum_v6(gi, ipnum);
if (NULL == gir) { if (NULL == gir) {
printf("%s: IP Address not found\n", GeoIPDBDescription[i]); printf("%s: IP Address not found\n", GeoIPDBDescription[i]);
}else { } else {
printf("%s: %s, %s, %s, %s, %f, %f, %d, %d\n", printf("%s: %s, %s, %s, %s, %f, %f, %d, %d\n",
GeoIPDBDescription[i], gir->country_code, _mk_NA( GeoIPDBDescription[i],
gir->region), _mk_NA(gir->city), _mk_NA( gir->country_code,
gir->postal_code), _mk_NA(gir->region),
gir->latitude, gir->longitude, gir->metro_code, _mk_NA(gir->city),
_mk_NA(gir->postal_code),
gir->latitude,
gir->longitude,
gir->metro_code,
gir->area_code); gir->area_code);
} }
}else if (GEOIP_COUNTRY_EDITION_V6 == i) { } else if (GEOIP_COUNTRY_EDITION_V6 == i) {
country_id = GeoIP_id_by_ipnum_v6(gi, ipnum); country_id = GeoIP_id_by_ipnum_v6(gi, ipnum);
if (country_id < 0 || country_id >= (int)GeoIP_num_countries()) { if (country_id < 0 || country_id >= (int)GeoIP_num_countries()) {
printf("%s: Invalid database\n", GeoIPDBDescription[i]); printf("%s: Invalid database\n", GeoIPDBDescription[i]);
return; return;
} }
country_code = GeoIP_country_code[country_id]; country_code = GeoIP_country_code[country_id];
country_name = GeoIP_country_name[country_id]; country_name = GeoIP_country_name[country_id];
if (country_id == 0) { if (country_id == 0) {
printf("%s: IP Address not found\n", GeoIPDBDescription[i]); printf("%s: IP Address not found\n", GeoIPDBDescription[i]);
}else { } else {
printf("%s: %s, %s\n", GeoIPDBDescription[i], country_code, printf("%s: %s, %s\n",
GeoIPDBDescription[i],
country_code,
country_name); country_name);
} }
} }
} }
} }
 End of changes. 19 change blocks. 
45 lines changed or deleted 46 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)