1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */ 2/* test-geoip-netspeed.c 3 * 4 * Copyright (C) 2006 MaxMind LLC 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 */ 20 21#include "GeoIP.h" 22 23int main(int argc, char *argv[]) 24{ 25 FILE *f; 26 GeoIP *gi; 27 int netspeed; 28 char host[50]; 29 30 gi = GeoIP_open("../data/GeoIPNetSpeed.dat", GEOIP_STANDARD); 31 32 if (gi == NULL) { 33 fprintf(stderr, "Error opening database\n"); 34 exit(1); 35 } 36 37 f = fopen("netspeed_test.txt", "r"); 38 39 if (f == NULL) { 40 fprintf(stderr, "Error opening netspeed_test.txt\n"); 41 exit(1); 42 } 43 44 while (fscanf(f, "%s", host) != EOF) { 45 netspeed = GeoIP_id_by_name(gi, (const char *)host); 46 if (netspeed == GEOIP_UNKNOWN_SPEED) { 47 printf("%s\tUnknown\n", host); 48 } else if (netspeed == GEOIP_DIALUP_SPEED) { 49 printf("%s\tDialup\n", host); 50 } else if (netspeed == GEOIP_CABLEDSL_SPEED) { 51 printf("%s\tCable/DSL\n", host); 52 } else if (netspeed == GEOIP_CORPORATE_SPEED) { 53 printf("%s\tCorporate\n", host); 54 } 55 } 56 fclose(f); 57 GeoIP_delete(gi); 58 59 return 0; 60} 61