Please fill in your credentials to login.
pec(dllexport)+#else+#defineGEOIP_API+#endif/*_WIN32*/-char*GeoIP_database_info(GeoIP*gi);-shortintGeoIP_update_database(GeoIP*gi,char*license_key,intverbose);+GEOIP_APIGeoIP*GeoIP_new(intflags);+GEOIP_APIGeoIP*GeoIP_open(char*filename,intflags);GEOIP_APIvoidGeoIP_delete(GeoIP*gi);+GEOIP_APIconstcha r*GeoIP_country_code_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIconstchar*GeoIP_country_code_by_name(GeoIP*gi,constchar*host);+GEOIP_APIconstchar*GeoIP_country_code3_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIconstchar*GeoIP_country_code3_by_name(GeoIP*gi,constchar*host);+GEOIP_APIconstchar*GeoIP_co untry_name_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIconstchar*GeoIP_country_name_by_name(GeoIP*gi,constchar*host);+GEOIP_APIshortintGeoIP_country_id_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIshortintGeoIP_country_id_by_name(GeoIP*gi,constchar*host);-int_seek_country(GeoIP*gi,constintoffset,unsign edlongipnum,intdepth);-unsignedlong_addr_to_num(constchar*addr);-unsignedlong_h_addr_to_num(unsignedchar*addr);-shortint_is_ipaddr(constchar*name);+GEOIP_APIchar*GeoIP_database_info(GeoIP*gi);+GEOIP_APIshortintGeoIP_update_database(GeoIP*gi,char*license_key,intverbose);++GEOIP_APIint_seek_country(Ge oIP*gi,constintoffset,unsignedlongipnum,intdepth);+GEOIP_APIunsignedlong_addr_to_num(constchar*addr);+GEOIP_APIunsignedlong_h_addr_to_num(unsignedchar*addr);#ifdef__cplusplus}Index:GeoIP.c===================================================================RCSfile:/home/maxmind/geoip/c/libGeoIP/GeoIP. c,vretrievingrevision1.32retrievingrevision1.33diff-u-r1.32-r1.33---GeoIP.c25Aug200222:42:48-00001.32+++GeoIP.c27Aug200206:50:02-00001.33@@-23,16+23,24@@#include<stdio.h>#include<stdlib.h>#include<string.h>+#ifndef_WIN32#include<netdb.h>+#endif/*_WIN32*/#include<assert.h>#include<sys/types.h>/*forfs tat*/#include<sys/stat.h>/*forfstat*/#include"zlib.h"#include"time.h"+#ifndef_WIN32+#include<unistd.h>#include<netinet/in.h>#include<arpa/inet.h>#include<sys/socket.h>+#else+#include<io.h>+#include<windows.h>+#endif/*_WIN32*/#defineCOUNTRY_BEGIN16776960;constintRECORD_LENGTH=3;@@-57,9+65,66@@constch ar*GeoIPUpdateHost="updates.maxmind.com";constchar*GeoIPHTTPRequest="GET/app/update?license_key=%sHTTP/1.0\nHost:updates.maxmind.com\n\n";+#ifdef_WIN32+char*_dat_in_module_path(){+HMODULEGeoIPdll;+struct_statst;+inti;+char*buf;++buf=(char*)malloc(MAX_PATH);++GeoIPdll=GetModuleHandle("GeoIP.dll");+if (!GeoIPdll)+{+GeoIPdll=GetModuleHandle(NULL);+if(!GeoIPdll)+returnNULL;+}+GetModuleFileName(GeoIPdll,buf,MAX_PATH);+for(i=strlen(buf);(i>=0)&&(buf[i]!='\\');i--);+if(i)+{+buf[i]='\0';+strcat(buf,"\\");+strcat(buf,GeoIPDBFileName);+if(_stat(buf,&st)==0)+returnbuf;+}++free(buf);+returnNULL;+}++char*_d at_path_in_regkey(){+DWORDlpdwDisposition,type,size=MAX_PATH;+HKEYhkGeoIP;+char*buf,*filename;++buf=(char*)malloc(MAX_PATH);+filename=(char*)malloc(MAX_PATH);++if(RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\MaxMind\\GeoIP",0,NULL,0,KEY_ALL_ACCESS,NULL,&hkGeoIP,&lpdwDisposition)!=ERROR_SUCCESS)+retu rnNULL;+if(RegQueryValueEx(hkGeoIP,"DATADIR",0,&type,buf,&size)!=ERROR_SUCCESS)+strcpy(buf,"%SystemRoot%\\SYSTEM32");+if(RegSetValueEx(hkGeoIP,"DATADIR",0,REG_EXPAND_SZ,buf,strlen(buf))!=ERROR_SUCCESS)+returnNULL;+ExpandEnvironmentStrings(buf,filename,MAX_PATH);++free(buf);+strcat(filename,"\\");+st rcat(filename,GeoIPDBFileName);++returnfilename;+}+#endif/*_WIN32*/+GeoIP*GeoIP_new(intflags){char*filename;GeoIP*gi;++#ifndef_WIN32filename=malloc(sizeof(char)*(strlen(DATADIR)+strlen(GeoIPDBFileName)+2));if(filename==NULL)returnNULL;@@-67,6+132,17@@strcat(filename,DATADIR);strcat(filename,"/");str cat(filename,GeoIPDBFileName);+#else+filename=_dat_in_module_path();+if(filename==NULL)+filename=_dat_path_in_regkey();+if(filename==NULL)+{+fprintf(stderr,"Unabletoqueryregistryfordatabaselocation\n");+returnNULL;+}+#endif/*_WIN32*/+gi=GeoIP_open(filename,flags);free(filename);returngi;@@-96,7+172, 7@@}gi->cache=(unsignedchar*)malloc(sizeof(unsignedchar)*buf.st_size);if(gi->cache!=NULL){-if(fread(gi->cache,sizeof(unsignedchar),buf.st_size,gi->GeoIPDatabase)!=buf.st_size){+if(fread(gi->cache,sizeof(unsignedchar),buf.st_size,gi->GeoIPDatabase)!=(unsigned)buf.st_size){fprintf(stderr,"Errorreading file%s\n",filename);free(gi->cache);free(gi);Index:GeoIP.h===================================================================RCSfile:/home/maxmind/geoip/c/libGeoIP/GeoIP.h,vretrievingrevision1.19retrievingrevision1.20diff-u-r1.19-r1.20---GeoIP.h20Aug200200:52:00-00001.19+++GeoIP.h27Aug200206:50:02-0 0001.20@@-45,25+45,31@@externconstchar*GeoIP_country_name[246];externconstchar*GeoIPConfFile;-GeoIP*GeoIP_new(intflags);-GeoIP*GeoIP_open(char*filename,intflags);-voidGeoIP_delete(GeoIP*gi);-constchar*GeoIP_country_code_by_addr(GeoIP*gi,constchar*addr);-constchar*GeoIP_country_code_by_name(GeoIP*gi, constchar*host);-constchar*GeoIP_country_code3_by_addr(GeoIP*gi,constchar*addr);-constchar*GeoIP_country_code3_by_name(GeoIP*gi,constchar*host);-constchar*GeoIP_country_name_by_addr(GeoIP*gi,constchar*addr);-constchar*GeoIP_country_name_by_name(GeoIP*gi,constchar*host);-shortintGeoIP_country_id_by_a ddr(GeoIP*gi,constchar*addr);-shortintGeoIP_country_id_by_name(GeoIP*gi,constchar*host);+#ifdef_WIN32+#defineGEOIP_API__declspec(dllexport)+#else+#defineGEOIP_API+#endif/*_WIN32*/-char*GeoIP_database_info(GeoIP*gi);-shortintGeoIP_update_database(GeoIP*gi,char*license_key,intverbose);+GEOIP_APIGeoIP* GeoIP_new(intflags);+GEOIP_APIGeoIP*GeoIP_open(char*filename,intflags);GEOIP_APIvoidGeoIP_delete(GeoIP*gi);+GEOIP_APIconstchar*GeoIP_country_code_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIconstchar*GeoIP_country_code_by_name(GeoIP*gi,constchar*host);+GEOIP_APIconstchar*GeoIP_country_code3_by_addr(G eoIP*gi,constchar*addr);+GEOIP_APIconstchar*GeoIP_country_code3_by_name(GeoIP*gi,constchar*host);+GEOIP_APIconstchar*GeoIP_country_name_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIconstchar*GeoIP_country_name_by_name(GeoIP*gi,constchar*host);+GEOIP_APIshortintGeoIP_country_id_by_addr(GeoIP*gi,constch ar*addr);+GEOIP_APIshortintGeoIP_country_id_by_name(GeoIP*gi,constchar*host);-int_seek_country(GeoIP*gi,constintoffset,unsignedlongipnum,intdepth);-unsignedlong_addr_to_num(constchar*addr);-unsignedlong_h_addr_to_num(unsignedchar*addr);-shortint_is_ipaddr(constchar*name);+GEOIP_APIchar*GeoIP_databas e_info(GeoIP*gi);+GEOIP_APIshortintGeoIP_update_database(GeoIP*gi,char*license_key,intverbose);++GEOIP_APIint_seek_country(GeoIP*gi,constintoffset,unsignedlongipnum,intdepth);+GEOIP_APIunsignedlong_addr_to_num(constchar*addr);+GEOIP_APIunsignedlong_h_addr_to_num(unsignedchar*addr);#ifdef__cplusplus} Index:GeoIP.c===================================================================RCSfile:/home/maxmind/geoip/c/libGeoIP/GeoIP.c,vretrievingrevision1.32retrievingrevision1.33diff-u-r1.32-r1.33---GeoIP.c25Aug200222:42:48-00001.32+++GeoIP.c27Aug200206:50:02-00001.33@@-23,16+23,24@@#include<stdio.h>#incl ude<stdlib.h>#include<string.h>+#ifndef_WIN32#include<netdb.h>+#endif/*_WIN32*/#include<assert.h>#include<sys/types.h>/*forfstat*/#include<sys/stat.h>/*forfstat*/#include"zlib.h"#include"time.h"+#ifndef_WIN32+#include<unistd.h>#include<netinet/in.h>#include<arpa/inet.h>#include<sys/socket.h>+#else+# include<io.h>+#include<windows.h>+#endif/*_WIN32*/#defineCOUNTRY_BEGIN16776960;constintRECORD_LENGTH=3;@@-57,9+65,66@@constchar*GeoIPUpdateHost="updates.maxmind.com";constchar*GeoIPHTTPRequest="GET/app/update?license_key=%sHTTP/1.0\nHost:updates.maxmind.com\n\n";+#ifdef_WIN32+char*_dat_in_module_pat h(){+HMODULEGeoIPdll;+struct_statst;+inti;+char*buf;++buf=(char*)malloc(MAX_PATH);++GeoIPdll=GetModuleHandle("GeoIP.dll");+if(!GeoIPdll)+{+GeoIPdll=GetModuleHandle(NULL);+if(!GeoIPdll)+returnNULL;+}+GetModuleFileName(GeoIPdll,buf,MAX_PATH);+for(i=strlen(buf);(i>=0)&&(buf[i]!='\\');i--);+if(i)+{+buf[ i]='\0';+strcat(buf,"\\");+strcat(buf,GeoIPDBFileName);+if(_stat(buf,&st)==0)+returnbuf;+}++free(buf);+returnNULL;+}++char*_dat_path_in_regkey(){+DWORDlpdwDisposition,type,size=MAX_PATH;+HKEYhkGeoIP;+char*buf,*filename;++buf=(char*)malloc(MAX_PATH);+filename=(char*)malloc(MAX_PATH);++if(RegCreateKey Ex(HKEY_LOCAL_MACHINE,"SOFTWARE\\MaxMind\\GeoIP",0,NULL,0,KEY_ALL_ACCESS,NULL,&hkGeoIP,&lpdwDisposition)!=ERROR_SUCCESS)+returnNULL;+if(RegQueryValueEx(hkGeoIP,"DATADIR",0,&type,buf,&size)!=ERROR_SUCCESS)+strcpy(buf,"%SystemRoot%\\SYSTEM32");+if(RegSetValueEx(hkGeoIP,"DATADIR",0,REG_EXPAND_SZ,buf,st rlen(buf))!=ERROR_SUCCESS)+returnNULL;+ExpandEnvironmentStrings(buf,filename,MAX_PATH);++free(buf);+strcat(filename,"\\");+strcat(filename,GeoIPDBFileName);++returnfilename;+}+#endif/*_WIN32*/+GeoIP*GeoIP_new(intflags){char*filename;GeoIP*gi;++#ifndef_WIN32filename=malloc(sizeof(char)*(strlen(DATADI R)+strlen(GeoIPDBFileName)+2));if(filename==NULL)returnNULL;@@-67,6+132,17@@strcat(filename,DATADIR);strcat(filename,"/");strcat(filename,GeoIPDBFileName);+#else+filename=_dat_in_module_path();+if(filename==NULL)+filename=_dat_path_in_regkey();+if(filename==NULL)+{+fprintf(stderr,"Unabletoqueryregis tryfordatabaselocation\n");+returnNULL;+}+#endif/*_WIN32*/+gi=GeoIP_open(filename,flags);free(filename);returngi;@@-96,7+172,7@@}gi->cache=(unsignedchar*)malloc(sizeof(unsignedchar)*buf.st_size);if(gi->cache!=NULL){-if(fread(gi->cache,sizeof(unsignedchar),buf.st_size,gi->GeoIPDatabase)!=buf.st_size) {+if(fread(gi->cache,sizeof(unsignedchar),buf.st_size,gi->GeoIPDatabase)!=(unsigned)buf.st_size){fprintf(stderr,"Errorreadingfile%s\n",filename);free(gi->cache);free(gi);Index:GeoIP.h===================================================================RCSfile:/home/maxmind/geoip/c/libGeoIP/GeoIP.h,vre trievingrevision1.19retrievingrevision1.20diff-u-r1.19-r1.20---GeoIP.h20Aug200200:52:00-00001.19+++GeoIP.h27Aug200206:50:02-00001.20@@-45,25+45,31@@externconstchar*GeoIP_country_name[246];externconstchar*GeoIPConfFile;-GeoIP*GeoIP_new(intflags);-GeoIP*GeoIP_open(char*filename,intflags);-voidGeoIP_de lete(GeoIP*gi);-constchar*GeoIP_country_code_by_addr(GeoIP*gi,constchar*addr);-constchar*GeoIP_country_code_by_name(GeoIP*gi,constchar*host);-constchar*GeoIP_country_code3_by_addr(GeoIP*gi,constchar*addr);-constchar*GeoIP_country_code3_by_name(GeoIP*gi,constchar*host);-constchar*GeoIP_country_name_b y_addr(GeoIP*gi,constchar*addr);-constchar*GeoIP_country_name_by_name(GeoIP*gi,constchar*host);-shortintGeoIP_country_id_by_addr(GeoIP*gi,constchar*addr);-shortintGeoIP_country_id_by_name(GeoIP*gi,constchar*host);+#ifdef_WIN32+#defineGEOIP_API__declspec(dllexport)+#else+#defineGEOIP_API+#endif/*_WIN 32*/-char*GeoIP_database_info(GeoIP*gi);-shortintGeoIP_update_database(GeoIP*gi,char*license_key,intverbose);+GEOIP_APIGeoIP*GeoIP_new(intflags);+GEOIP_APIGeoIP*GeoIP_open(char*filename,intflags);GEOIP_APIvoidGeoIP_delete(GeoIP*gi);+GEOIP_APIconstchar*GeoIP_country_code_by_addr(GeoIP*gi,constchar*ad dr);+GEOIP_APIconstchar*GeoIP_country_code_by_name(GeoIP*gi,constchar*host);+GEOIP_APIconstchar*GeoIP_country_code3_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIconstchar*GeoIP_country_code3_by_name(GeoIP*gi,constchar*host);+GEOIP_APIconstchar*GeoIP_country_name_by_addr(GeoIP*gi,constchar*addr);+GEOIP _APIconstchar*GeoIP_country_name_by_name(GeoIP*gi,constchar*host);+GEOIP_APIshortintGeoIP_country_id_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIshortintGeoIP_country_id_by_name(GeoIP*gi,constchar*host);-int_seek_country(GeoIP*gi,constintoffset,unsignedlongipnum,intdepth);-unsignedlong_addr_to_num(co nstchar*addr);-unsignedlong_h_addr_to_num(unsignedchar*addr);-shortint_is_ipaddr(constchar*name);+GEOIP_APIchar*GeoIP_database_info(GeoIP*gi);+GEOIP_APIshortintGeoIP_update_database(GeoIP*gi,char*license_key,intverbose);++GEOIP_APIint_seek_country(GeoIP*gi,constintoffset,unsignedlongipnum,intdepth); +GEOIP_APIunsignedlong_addr_to_num(constchar*addr);+GEOIP_APIunsignedlong_h_addr_to_num(unsignedchar*addr);#ifdef__cplusplus}Index:GeoIP.c===================================================================RCSfile:/home/maxmind/geoip/c/libGeoIP/GeoIP.c,vretrievingrevision1.32retrievingrevision1.33dif f-u-r1.32-r1.33---GeoIP.c25Aug200222:42:48-00001.32+++GeoIP.c27Aug200206:50:02-00001.33@@-23,16+23,24@@#include<stdio.h>#include<stdlib.h>#include<string.h>+#ifndef_WIN32#include<netdb.h>+#endif/*_WIN32*/#include<assert.h>#include<sys/types.h>/*forfstat*/#include<sys/stat.h>/*forfstat*/#include"zlib .h"#include"time.h"+#ifndef_WIN32+#include<unistd.h>#include<netinet/in.h>#include<arpa/inet.h>#include<sys/socket.h>+#else+#include<io.h>+#include<windows.h>+#endif/*_WIN32*/#defineCOUNTRY_BEGIN16776960;constintRECORD_LENGTH=3;@@-57,9+65,66@@constchar*GeoIPUpdateHost="updates.maxmind.com";constchar *GeoIPHTTPRequest="GET/app/update?license_key=%sHTTP/1.0\nHost:updates.maxmind.com\n\n";+#ifdef_WIN32+char*_dat_in_module_path(){+HMODULEGeoIPdll;+struct_statst;+inti;+char*buf;++buf=(char*)malloc(MAX_PATH);++GeoIPdll=GetModuleHandle("GeoIP.dll");+if(!GeoIPdll)+{+GeoIPdll=GetModuleHandle(NULL);+if(! GeoIPdll)+returnNULL;+}+GetModuleFileName(GeoIPdll,buf,MAX_PATH);+for(i=strlen(buf);(i>=0)&&(buf[i]!='\\');i--);+if(i)+{+buf[i]='\0';+strcat(buf,"\\");+strcat(buf,GeoIPDBFileName);+if(_stat(buf,&st)==0)+returnbuf;+}++free(buf);+returnNULL;+}++char*_dat_path_in_regkey(){+DWORDlpdwDisposition,type,siz e=MAX_PATH;+HKEYhkGeoIP;+char*buf,*filename;++buf=(char*)malloc(MAX_PATH);+filename=(char*)malloc(MAX_PATH);++if(RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\MaxMind\\GeoIP",0,NULL,0,KEY_ALL_ACCESS,NULL,&hkGeoIP,&lpdwDisposition)!=ERROR_SUCCESS)+returnNULL;+if(RegQueryValueEx(hkGeoIP,"DATADIR",0,&ty pe,buf,&size)!=ERROR_SUCCESS)+strcpy(buf,"%SystemRoot%\\SYSTEM32");+if(RegSetValueEx(hkGeoIP,"DATADIR",0,REG_EXPAND_SZ,buf,strlen(buf))!=ERROR_SUCCESS)+returnNULL;+ExpandEnvironmentStrings(buf,filename,MAX_PATH);++free(buf);+strcat(filename,"\\");+strcat(filename,GeoIPDBFileName);++returnfilename;+} +#endif/*_WIN32*/+GeoIP*GeoIP_new(intflags){char*filename;GeoIP*gi;++#ifndef_WIN32filename=malloc(sizeof(char)*(strlen(DATADIR)+strlen(GeoIPDBFileName)+2));if(filename==NULL)returnNULL;@@-67,6+132,17@@strcat(filename,DATADIR);strcat(filename,"/");strcat(filename,GeoIPDBFileName);+#else+filename=_dat _in_module_path();+if(filename==NULL)+filename=_dat_path_in_regkey();+if(filename==NULL)+{+fprintf(stderr,"Unabletoqueryregistryfordatabaselocation\n");+returnNULL;+}+#endif/*_WIN32*/+gi=GeoIP_open(filename,flags);free(filename);returngi;@@-96,7+172,7@@}gi->cache=(unsignedchar*)malloc(sizeof(unsigne dchar)*buf.st_size);if(gi->cache!=NULL){-if(fread(gi->cache,sizeof(unsignedchar),buf.st_size,gi->GeoIPDatabase)!=buf.st_size){+if(fread(gi->cache,sizeof(unsignedchar),buf.st_size,gi->GeoIPDatabase)!=(unsigned)buf.st_size){fprintf(stderr,"Errorreadingfile%s\n",filename);free(gi->cache);free(gi);Index :GeoIP.h===================================================================RCSfile:/home/maxmind/geoip/c/libGeoIP/GeoIP.h,vretrievingrevision1.19retrievingrevision1.20diff-u-r1.19-r1.20---GeoIP.h20Aug200200:52:00-00001.19+++GeoIP.h27Aug200206:50:02-00001.20@@-45,25+45,31@@externconstchar*GeoIP_count ry_name[246];externconstchar*GeoIPConfFile;-GeoIP*GeoIP_new(intflags);-GeoIP*GeoIP_open(char*filename,intflags);-voidGeoIP_delete(GeoIP*gi);-constchar*GeoIP_country_code_by_addr(GeoIP*gi,constchar*addr);-constchar*GeoIP_country_code_by_name(GeoIP*gi,constchar*host);-constchar*GeoIP_country_code3_by_ addr(GeoIP*gi,constchar*addr);-constchar*GeoIP_country_code3_by_name(GeoIP*gi,constchar*host);-constchar*GeoIP_country_name_by_addr(GeoIP*gi,constchar*addr);-constchar*GeoIP_country_name_by_name(GeoIP*gi,constchar*host);-shortintGeoIP_country_id_by_addr(GeoIP*gi,constchar*addr);-shortintGeoIP_countr y_id_by_name(GeoIP*gi,constchar*host);+#ifdef_WIN32+#defineGEOIP_API__declspec(dllexport)+#else+#defineGEOIP_API+#endif/*_WIN32*/-char*GeoIP_database_info(GeoIP*gi);-shortintGeoIP_update_database(GeoIP*gi,char*license_key,intverbose);+GEOIP_APIGeoIP*GeoIP_new(intflags);+GEOIP_APIGeoIP*GeoIP_open(cha r*filename,intflags);GEOIP_APIvoidGeoIP_delete(GeoIP*gi);+GEOIP_APIconstchar*GeoIP_country_code_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIconstchar*GeoIP_country_code_by_name(GeoIP*gi,constchar*host);+GEOIP_APIconstchar*GeoIP_country_code3_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIconstchar*GeoIP_ country_code3_by_name(GeoIP*gi,constchar*host);+GEOIP_APIconstchar*GeoIP_country_name_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIconstchar*GeoIP_country_name_by_name(GeoIP*gi,constchar*host);+GEOIP_APIshortintGeoIP_country_id_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIshortintGeoIP_country_id_by_nam e(GeoIP*gi,constchar*host);-int_seek_country(GeoIP*gi,constintoffset,unsignedlongipnum,intdepth);-unsignedlong_addr_to_num(constchar*addr);-unsignedlong_h_addr_to_num(unsignedchar*addr);-shortint_is_ipaddr(constchar*name);+GEOIP_APIchar*GeoIP_database_info(GeoIP*gi);+GEOIP_APIshortintGeoIP_update_da tabase(GeoIP*gi,char*license_key,intverbose);++GEOIP_APIint_seek_country(GeoIP*gi,constintoffset,unsignedlongipnum,intdepth);+GEOIP_APIunsignedlong_addr_to_num(constchar*addr);+GEOIP_APIunsignedlong_h_addr_to_num(unsignedchar*addr);#ifdef__cplusplus}Index:GeoIP.c===================================== ==============================RCSfile:/home/maxmind/geoip/c/libGeoIP/GeoIP.c,vretrievingrevision1.32retrievingrevision1.33diff-u-r1.32-r1.33---GeoIP.c25Aug200222:42:48-00001.32+++GeoIP.c27Aug200206:50:02-00001.33@@-23,16+23,24@@#include<stdio.h>#include<stdlib.h>#include<string.h>+#ifndef_WIN32#incl ude<netdb.h>+#endif/*_WIN32*/#include<assert.h>#include<sys/types.h>/*forfstat*/#include<sys/stat.h>/*forfstat*/#include"zlib.h"#include"time.h"+#ifndef_WIN32+#include<unistd.h>#include<netinet/in.h>#include<arpa/inet.h>#include<sys/socket.h>+#else+#include<io.h>+#include<windows.h>+#endif/*_WIN32*/ #defineCOUNTRY_BEGIN16776960;constintRECORD_LENGTH=3;@@-57,9+65,66@@constchar*GeoIPUpdateHost="updates.maxmind.com";constchar*GeoIPHTTPRequest="GET/app/update?license_key=%sHTTP/1.0\nHost:updates.maxmind.com\n\n";+#ifdef_WIN32+char*_dat_in_module_path(){+HMODULEGeoIPdll;+struct_statst;+inti;+char*bu f;++buf=(char*)malloc(MAX_PATH);++GeoIPdll=GetModuleHandle("GeoIP.dll");+if(!GeoIPdll)+{+GeoIPdll=GetModuleHandle(NULL);+if(!GeoIPdll)+returnNULL;+}+GetModuleFileName(GeoIPdll,buf,MAX_PATH);+for(i=strlen(buf);(i>=0)&&(buf[i]!='\\');i--);+if(i)+{+buf[i]='\0';+strcat(buf,"\\");+strcat(buf,GeoIPDBFileN ame);+if(_stat(buf,&st)==0)+returnbuf;+}++free(buf);+returnNULL;+}++char*_dat_path_in_regkey(){+DWORDlpdwDisposition,type,size=MAX_PATH;+HKEYhkGeoIP;+char*buf,*filename;++buf=(char*)malloc(MAX_PATH);+filename=(char*)malloc(MAX_PATH);++if(RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\MaxMind\\GeoIP",0 ,NULL,0,KEY_ALL_ACCESS,NULL,&hkGeoIP,&lpdwDisposition)!=ERROR_SUCCESS)+returnNULL;+if(RegQueryValueEx(hkGeoIP,"DATADIR",0,&type,buf,&size)!=ERROR_SUCCESS)+strcpy(buf,"%SystemRoot%\\SYSTEM32");+if(RegSetValueEx(hkGeoIP,"DATADIR",0,REG_EXPAND_SZ,buf,strlen(buf))!=ERROR_SUCCESS)+returnNULL;+ExpandEnvir onmentStrings(buf,filename,MAX_PATH);++free(buf);+strcat(filename,"\\");+strcat(filename,GeoIPDBFileName);++returnfilename;+}+#endif/*_WIN32*/+GeoIP*GeoIP_new(intflags){char*filename;GeoIP*gi;++#ifndef_WIN32filename=malloc(sizeof(char)*(strlen(DATADIR)+strlen(GeoIPDBFileName)+2));if(filename==NULL)r eturnNULL;@@-67,6+132,17@@strcat(filename,DATADIR);strcat(filename,"/");strcat(filename,GeoIPDBFileName);+#else+filename=_dat_in_module_path();+if(filename==NULL)+filename=_dat_path_in_regkey();+if(filename==NULL)+{+fprintf(stderr,"Unabletoqueryregistryfordatabaselocation\n");+returnNULL;+}+#endif/* _WIN32*/+gi=GeoIP_open(filename,flags);free(filename);returngi;@@-96,7+172,7@@}gi->cache=(unsignedchar*)malloc(sizeof(unsignedchar)*buf.st_size);if(gi->cache!=NULL){-if(fread(gi->cache,sizeof(unsignedchar),buf.st_size,gi->GeoIPDatabase)!=buf.st_size){+if(fread(gi->cache,sizeof(unsignedchar),buf.st_s ize,gi->GeoIPDatabase)!=(unsigned)buf.st_size){fprintf(stderr,"Errorreadingfile%s\n",filename);free(gi->cache);free(gi);Index:GeoIP.h===================================================================RCSfile:/home/maxmind/geoip/c/libGeoIP/GeoIP.h,vretrievingrevision1.19retrievingrevision1.20diff-u-r 1.19-r1.20---GeoIP.h20Aug200200:52:00-00001.19+++GeoIP.h27Aug200206:50:02-00001.20@@-45,25+45,31@@externconstchar*GeoIP_country_name[246];externconstchar*GeoIPConfFile;-GeoIP*GeoIP_new(intflags);-GeoIP*GeoIP_open(char*filename,intflags);-voidGeoIP_delete(GeoIP*gi);-constchar*GeoIP_country_code_by_ad dr(GeoIP*gi,constchar*addr);-constchar*GeoIP_country_code_by_name(GeoIP*gi,constchar*host);-constchar*GeoIP_country_code3_by_addr(GeoIP*gi,constchar*addr);-constchar*GeoIP_country_code3_by_name(GeoIP*gi,constchar*host);-constchar*GeoIP_country_name_by_addr(GeoIP*gi,constchar*addr);-constchar*GeoIP_c ountry_name_by_name(GeoIP*gi,constchar*host);-shortintGeoIP_country_id_by_addr(GeoIP*gi,constchar*addr);-shortintGeoIP_country_id_by_name(GeoIP*gi,constchar*host);+#ifdef_WIN32+#defineGEOIP_API__declspec(dllexport)+#else+#defineGEOIP_API+#endif/*_WIN32*/-char*GeoIP_database_info(GeoIP*gi);-shortintG eoIP_update_database(GeoIP*gi,char*license_key,intverbose);+GEOIP_APIGeoIP*GeoIP_new(intflags);+GEOIP_APIGeoIP*GeoIP_open(char*filename,intflags);GEOIP_APIvoidGeoIP_delete(GeoIP*gi);+GEOIP_APIconstchar*GeoIP_country_code_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIconstchar*GeoIP_country_code_by_name (GeoIP*gi,constchar*host);+GEOIP_APIconstchar*GeoIP_country_code3_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIconstchar*GeoIP_country_code3_by_name(GeoIP*gi,constchar*host);+GEOIP_APIconstchar*GeoIP_country_name_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIconstchar*GeoIP_country_name_by_name(GeoIP*gi, constchar*host);+GEOIP_APIshortintGeoIP_country_id_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIshortintGeoIP_country_id_by_name(GeoIP*gi,constchar*host);-int_seek_country(GeoIP*gi,constintoffset,unsignedlongipnum,intdepth);-unsignedlong_addr_to_num(constchar*addr);-unsignedlong_h_addr_to_num(unsigned char*addr);-shortint_is_ipaddr(constchar*name);+GEOIP_APIchar*GeoIP_database_info(GeoIP*gi);+GEOIP_APIshortintGeoIP_update_database(GeoIP*gi,char*license_key,intverbose);++GEOIP_APIint_seek_country(GeoIP*gi,constintoffset,unsignedlongipnum,intdepth);+GEOIP_APIunsignedlong_addr_to_num(constchar*addr) ;+GEOIP_APIunsignedlong_h_addr_to_num(unsignedchar*addr);#ifdef__cplusplus}Index:GeoIP.c===================================================================RCSfile:/home/maxmind/geoip/c/libGeoIP/GeoIP.c,vretrievingrevision1.32retrievingrevision1.33diff-u-r1.32-r1.33---GeoIP.c25Aug200222:42:48-00001.3 2+++GeoIP.c27Aug200206:50:02-00001.33@@-23,16+23,24@@#include<stdio.h>#include<stdlib.h>#include<string.h>+#ifndef_WIN32#include<netdb.h>+#endif/*_WIN32*/#include<assert.h>#include<sys/types.h>/*forfstat*/#include<sys/stat.h>/*forfstat*/#include"zlib.h"#include"time.h"+#ifndef_WIN32+#include<unistd. h>#include<netinet/in.h>#include<arpa/inet.h>#include<sys/socket.h>+#else+#include<io.h>+#include<windows.h>+#endif/*_WIN32*/#defineCOUNTRY_BEGIN16776960;constintRECORD_LENGTH=3;@@-57,9+65,66@@constchar*GeoIPUpdateHost="updates.maxmind.com";constchar*GeoIPHTTPRequest="GET/app/update?license_key=%sHT TP/1.0\nHost:updates.maxmind.com\n\n";+#ifdef_WIN32+char*_dat_in_module_path(){+HMODULEGeoIPdll;+struct_statst;+inti;+char*buf;++buf=(char*)malloc(MAX_PATH);++GeoIPdll=GetModuleHandle("GeoIP.dll");+if(!GeoIPdll)+{+GeoIPdll=GetModuleHandle(NULL);+if(!GeoIPdll)+returnNULL;+}+GetModuleFileName(GeoIPdll ,buf,MAX_PATH);+for(i=strlen(buf);(i>=0)&&(buf[i]!='\\');i--);+if(i)+{+buf[i]='\0';+strcat(buf,"\\");+strcat(buf,GeoIPDBFileName);+if(_stat(buf,&st)==0)+returnbuf;+}++free(buf);+returnNULL;+}++char*_dat_path_in_regkey(){+DWORDlpdwDisposition,type,size=MAX_PATH;+HKEYhkGeoIP;+char*buf,*filename;++buf= (char*)malloc(MAX_PATH);+filename=(char*)malloc(MAX_PATH);++if(RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\MaxMind\\GeoIP",0,NULL,0,KEY_ALL_ACCESS,NULL,&hkGeoIP,&lpdwDisposition)!=ERROR_SUCCESS)+returnNULL;+if(RegQueryValueEx(hkGeoIP,"DATADIR",0,&type,buf,&size)!=ERROR_SUCCESS)+strcpy(buf,"%SystemR oot%\\SYSTEM32");+if(RegSetValueEx(hkGeoIP,"DATADIR",0,REG_EXPAND_SZ,buf,strlen(buf))!=ERROR_SUCCESS)+returnNULL;+ExpandEnvironmentStrings(buf,filename,MAX_PATH);++free(buf);+strcat(filename,"\\");+strcat(filename,GeoIPDBFileName);++returnfilename;+}+#endif/*_WIN32*/+GeoIP*GeoIP_new(intflags){char*f ilename;GeoIP*gi;++#ifndef_WIN32filename=malloc(sizeof(char)*(strlen(DATADIR)+strlen(GeoIPDBFileName)+2));if(filename==NULL)returnNULL;@@-67,6+132,17@@strcat(filename,DATADIR);strcat(filename,"/");strcat(filename,GeoIPDBFileName);+#else+filename=_dat_in_module_path();+if(filename==NULL)+filename=_da t_path_in_regkey();+if(filename==NULL)+{+fprintf(stderr,"Unabletoqueryregistryfordatabaselocation\n");+returnNULL;+}+#endif/*_WIN32*/+gi=GeoIP_open(filename,flags);free(filename);returngi;@@-96,7+172,7@@}gi->cache=(unsignedchar*)malloc(sizeof(unsignedchar)*buf.st_size);if(gi->cache!=NULL){-if(fread( gi->cache,sizeof(unsignedchar),buf.st_size,gi->GeoIPDatabase)!=buf.st_size){+if(fread(gi->cache,sizeof(unsignedchar),buf.st_size,gi->GeoIPDatabase)!=(unsigned)buf.st_size){fprintf(stderr,"Errorreadingfile%s\n",filename);free(gi->cache);free(gi);Index:GeoIP.h========================================== =========================RCSfile:/home/maxmind/geoip/c/libGeoIP/GeoIP.h,vretrievingrevision1.19retrievingrevision1.20diff-u-r1.19-r1.20---GeoIP.h20Aug200200:52:00-00001.19+++GeoIP.h27Aug200206:50:02-00001.20@@-45,25+45,31@@externconstchar*GeoIP_country_name[246];externconstchar*GeoIPConfFile;-GeoIP* GeoIP_new(intflags);-GeoIP*GeoIP_open(char*filename,intflags);-voidGeoIP_delete(GeoIP*gi);-constchar*GeoIP_country_code_by_addr(GeoIP*gi,constchar*addr);-constchar*GeoIP_country_code_by_name(GeoIP*gi,constchar*host);-constchar*GeoIP_country_code3_by_addr(GeoIP*gi,constchar*addr);-constchar*GeoIP_cou ntry_code3_by_name(GeoIP*gi,constchar*host);-constchar*GeoIP_country_name_by_addr(GeoIP*gi,constchar*addr);-constchar*GeoIP_country_name_by_name(GeoIP*gi,constchar*host);-shortintGeoIP_country_id_by_addr(GeoIP*gi,constchar*addr);-shortintGeoIP_country_id_by_name(GeoIP*gi,constchar*host);+#ifdef_WIN3 2+#defineGEOIP_API__declspec(dllexport)+#else+#defineGEOIP_API+#endif/*_WIN32*/-char*GeoIP_database_info(GeoIP*gi);-shortintGeoIP_update_database(GeoIP*gi,char*license_key,intverbose);+GEOIP_APIGeoIP*GeoIP_new(intflags);+GEOIP_APIGeoIP*GeoIP_open(char*filename,intflags);GEOIP_APIvoidGeoIP_delete(Geo IP*gi);+GEOIP_APIconstchar*GeoIP_country_code_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIconstchar*GeoIP_country_code_by_name(GeoIP*gi,constchar*host);+GEOIP_APIconstchar*GeoIP_country_code3_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIconstchar*GeoIP_country_code3_by_name(GeoIP*gi,constchar*host);+GE OIP_APIconstchar*GeoIP_country_name_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIconstchar*GeoIP_country_name_by_name(GeoIP*gi,constchar*host);+GEOIP_APIshortintGeoIP_country_id_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIshortintGeoIP_country_id_by_name(GeoIP*gi,constchar*host);-int_seek_country(GeoIP *gi,constintoffset,unsignedlongipnum,intdepth);-unsignedlong_addr_to_num(constchar*addr);-unsignedlong_h_addr_to_num(unsignedchar*addr);-shortint_is_ipaddr(constchar*name);+GEOIP_APIchar*GeoIP_database_info(GeoIP*gi);+GEOIP_APIshortintGeoIP_update_database(GeoIP*gi,char*license_key,intverbose);++GEO IP_APIint_seek_country(GeoIP*gi,constintoffset,unsignedlongipnum,intdepth);+GEOIP_APIunsignedlong_addr_to_num(constchar*addr);+GEOIP_APIunsignedlong_h_addr_to_num(unsignedchar*addr);#ifdef__cplusplus}Index:GeoIP.c===================================================================RCSfile:/home/maxmin d/geoip/c/libGeoIP/GeoIP.c,vretrievingrevision1.32retrievingrevision1.33diff-u-r1.32-r1.33---GeoIP.c25Aug200222:42:48-00001.32+++GeoIP.c27Aug200206:50:02-00001.33@@-23,16+23,24@@#include<stdio.h>#include<stdlib.h>#include<string.h>+#ifndef_WIN32#include<netdb.h>+#endif/*_WIN32*/#include<assert.h>#in clude<sys/types.h>/*forfstat*/#include<sys/stat.h>/*forfstat*/#include"zlib.h"#include"time.h"+#ifndef_WIN32+#include<unistd.h>#include<netinet/in.h>#include<arpa/inet.h>#include<sys/socket.h>+#else+#include<io.h>+#include<windows.h>+#endif/*_WIN32*/#defineCOUNTRY_BEGIN16776960;constintRECORD_LENGTH =3;@@-57,9+65,66@@constchar*GeoIPUpdateHost="updates.maxmind.com";constchar*GeoIPHTTPRequest="GET/app/update?license_key=%sHTTP/1.0\nHost:updates.maxmind.com\n\n";+#ifdef_WIN32+char*_dat_in_module_path(){+HMODULEGeoIPdll;+struct_statst;+inti;+char*buf;++buf=(char*)malloc(MAX_PATH);++GeoIPdll=GetModu leHandle("GeoIP.dll");+if(!GeoIPdll)+{+GeoIPdll=GetModuleHandle(NULL);+if(!GeoIPdll)+returnNULL;+}+GetModuleFileName(GeoIPdll,buf,MAX_PATH);+for(i=strlen(buf);(i>=0)&&(buf[i]!='\\');i--);+if(i)+{+buf[i]='\0';+strcat(buf,"\\");+strcat(buf,GeoIPDBFileName);+if(_stat(buf,&st)==0)+returnbuf;+}++free(buf );+returnNULL;+}++char*_dat_path_in_regkey(){+DWORDlpdwDisposition,type,size=MAX_PATH;+HKEYhkGeoIP;+char*buf,*filename;++buf=(char*)malloc(MAX_PATH);+filename=(char*)malloc(MAX_PATH);++if(RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\MaxMind\\GeoIP",0,NULL,0,KEY_ALL_ACCESS,NULL,&hkGeoIP,&lpdwDisposit ion)!=ERROR_SUCCESS)+returnNULL;+if(RegQueryValueEx(hkGeoIP,"DATADIR",0,&type,buf,&size)!=ERROR_SUCCESS)+strcpy(buf,"%SystemRoot%\\SYSTEM32");+if(RegSetValueEx(hkGeoIP,"DATADIR",0,REG_EXPAND_SZ,buf,strlen(buf))!=ERROR_SUCCESS)+returnNULL;+ExpandEnvironmentStrings(buf,filename,MAX_PATH);++free(buf);+ strcat(filename,"\\");+strcat(filename,GeoIPDBFileName);++returnfilename;+}+#endif/*_WIN32*/+GeoIP*GeoIP_new(intflags){char*filename;GeoIP*gi;++#ifndef_WIN32filename=malloc(sizeof(char)*(strlen(DATADIR)+strlen(GeoIPDBFileName)+2));if(filename==NULL)returnNULL;@@-67,6+132,17@@strcat(filename,DATADIR) ;strcat(filename,"/");strcat(filename,GeoIPDBFileName);+#else+filename=_dat_in_module_path();+if(filename==NULL)+filename=_dat_path_in_regkey();+if(filename==NULL)+{+fprintf(stderr,"Unabletoqueryregistryfordatabaselocation\n");+returnNULL;+}+#endif/*_WIN32*/+gi=GeoIP_open(filename,flags);free(filena me);returngi;@@-96,7+172,7@@}gi->cache=(unsignedchar*)malloc(sizeof(unsignedchar)*buf.st_size);if(gi->cache!=NULL){-if(fread(gi->cache,sizeof(unsignedchar),buf.st_size,gi->GeoIPDatabase)!=buf.st_size){+if(fread(gi->cache,sizeof(unsignedchar),buf.st_size,gi->GeoIPDatabase)!=(unsigned)buf.st_size){fpr intf(stderr,"Errorreadingfile%s\n",filename);free(gi->cache);free(gi);Index:GeoIP.h===================================================================RCSfile:/home/maxmind/geoip/c/libGeoIP/GeoIP.h,vretrievingrevision1.19retrievingrevision1.20diff-u-r1.19-r1.20---GeoIP.h20Aug200200:52:00-00001.19+++G eoIP.h27Aug200206:50:02-00001.20@@-45,25+45,31@@externconstchar*GeoIP_country_name[246];externconstchar*GeoIPConfFile;-GeoIP*GeoIP_new(intflags);-GeoIP*GeoIP_open(char*filename,intflags);-voidGeoIP_delete(GeoIP*gi);-constchar*GeoIP_country_code_by_addr(GeoIP*gi,constchar*addr);-constchar*GeoIP_count ry_code_by_name(GeoIP*gi,constchar*host);-constchar*GeoIP_country_code3_by_addr(GeoIP*gi,constchar*addr);-constchar*GeoIP_country_code3_by_name(GeoIP*gi,constchar*host);-constchar*GeoIP_country_name_by_addr(GeoIP*gi,constchar*addr);-constchar*GeoIP_country_name_by_name(GeoIP*gi,constchar*host);-shor tintGeoIP_country_id_by_addr(GeoIP*gi,constchar*addr);-shortintGeoIP_country_id_by_name(GeoIP*gi,constchar*host);+#ifdef_WIN32+#defineGEOIP_API__declspec(dllexport)+#else+#defineGEOIP_API+#endif/*_WIN32*/-char*GeoIP_database_info(GeoIP*gi);-shortintGeoIP_update_database(GeoIP*gi,char*license_key,int verbose);+GEOIP_APIGeoIP*GeoIP_new(intflags);+GEOIP_APIGeoIP*GeoIP_open(char*filename,intflags);GEOIP_APIvoidGeoIP_delete(GeoIP*gi);+GEOIP_APIconstchar*GeoIP_country_code_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIconstchar*GeoIP_country_code_by_name(GeoIP*gi,constchar*host);+GEOIP_APIconstchar*GeoI P_country_code3_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIconstchar*GeoIP_country_code3_by_name(GeoIP*gi,constchar*host);+GEOIP_APIconstchar*GeoIP_country_name_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIconstchar*GeoIP_country_name_by_name(GeoIP*gi,constchar*host);+GEOIP_APIshortintGeoIP_country_id _by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIshortintGeoIP_country_id_by_name(GeoIP*gi,constchar*host);-int_seek_country(GeoIP*gi,constintoffset,unsignedlongipnum,intdepth);-unsignedlong_addr_to_num(constchar*addr);-unsignedlong_h_addr_to_num(unsignedchar*addr);-shortint_is_ipaddr(constchar*name);+GE OIP_APIchar*GeoIP_database_info(GeoIP*gi);+GEOIP_APIshortintGeoIP_update_database(GeoIP*gi,char*license_key,intverbose);++GEOIP_APIint_seek_country(GeoIP*gi,constintoffset,unsignedlongipnum,intdepth);+GEOIP_APIunsignedlong_addr_to_num(constchar*addr);+GEOIP_APIunsignedlong_h_addr_to_num(unsignedchar *addr);#ifdef__cplusplus}Index:GeoIP.c===================================================================RCSfile:/home/maxmind/geoip/c/libGeoIP/GeoIP.c,vretrievingrevision1.32retrievingrevision1.33diff-u-r1.32-r1.33---GeoIP.c25Aug200222:42:48-00001.32+++GeoIP.c27Aug200206:50:02-00001.33@@-23,16+23,2 4@@#include<stdio.h>#include<stdlib.h>#include<string.h>+#ifndef_WIN32#include<netdb.h>+#endif/*_WIN32*/#include<assert.h>#include<sys/types.h>/*forfstat*/#include<sys/stat.h>/*forfstat*/#include"zlib.h"#include"time.h"+#ifndef_WIN32+#include<unistd.h>#include<netinet/in.h>#include<arpa/inet.h>#incl ude<sys/socket.h>+#else+#include<io.h>+#include<windows.h>+#endif/*_WIN32*/#defineCOUNTRY_BEGIN16776960;constintRECORD_LENGTH=3;@@-57,9+65,66@@constchar*GeoIPUpdateHost="updates.maxmind.com";constchar*GeoIPHTTPRequest="GET/app/update?license_key=%sHTTP/1.0\nHost:updates.maxmind.com\n\n";+#ifdef_WIN3 2+char*_dat_in_module_path(){+HMODULEGeoIPdll;+struct_statst;+inti;+char*buf;++buf=(char*)malloc(MAX_PATH);++GeoIPdll=GetModuleHandle("GeoIP.dll");+if(!GeoIPdll)+{+GeoIPdll=GetModuleHandle(NULL);+if(!GeoIPdll)+returnNULL;+}+GetModuleFileName(GeoIPdll,buf,MAX_PATH);+for(i=strlen(buf);(i>=0)&&(buf[i]! ='\\');i--);+if(i)+{+buf[i]='\0';+strcat(buf,"\\");+strcat(buf,GeoIPDBFileName);+if(_stat(buf,&st)==0)+returnbuf;+}++free(buf);+returnNULL;+}++char*_dat_path_in_regkey(){+DWORDlpdwDisposition,type,size=MAX_PATH;+HKEYhkGeoIP;+char*buf,*filename;++buf=(char*)malloc(MAX_PATH);+filename=(char*)malloc(MA X_PATH);++if(RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\MaxMind\\GeoIP",0,NULL,0,KEY_ALL_ACCESS,NULL,&hkGeoIP,&lpdwDisposition)!=ERROR_SUCCESS)+returnNULL;+if(RegQueryValueEx(hkGeoIP,"DATADIR",0,&type,buf,&size)!=ERROR_SUCCESS)+strcpy(buf,"%SystemRoot%\\SYSTEM32");+if(RegSetValueEx(hkGeoIP,"DATADI R",0,REG_EXPAND_SZ,buf,strlen(buf))!=ERROR_SUCCESS)+returnNULL;+ExpandEnvironmentStrings(buf,filename,MAX_PATH);++free(buf);+strcat(filename,"\\");+strcat(filename,GeoIPDBFileName);++returnfilename;+}+#endif/*_WIN32*/+GeoIP*GeoIP_new(intflags){char*filename;GeoIP*gi;++#ifndef_WIN32filename=malloc(si zeof(char)*(strlen(DATADIR)+strlen(GeoIPDBFileName)+2));if(filename==NULL)returnNULL;@@-67,6+132,17@@strcat(filename,DATADIR);strcat(filename,"/");strcat(filename,GeoIPDBFileName);+#else+filename=_dat_in_module_path();+if(filename==NULL)+filename=_dat_path_in_regkey();+if(filename==NULL)+{+fprintf(s tderr,"Unabletoqueryregistryfordatabaselocation\n");+returnNULL;+}+#endif/*_WIN32*/+gi=GeoIP_open(filename,flags);free(filename);returngi;@@-96,7+172,7@@}gi->cache=(unsignedchar*)malloc(sizeof(unsignedchar)*buf.st_size);if(gi->cache!=NULL){-if(fread(gi->cache,sizeof(unsignedchar),buf.st_size,gi->Geo IPDatabase)!=buf.st_size){+if(fread(gi->cache,sizeof(unsignedchar),buf.st_size,gi->GeoIPDatabase)!=(unsigned)buf.st_size){fprintf(stderr,"Errorreadingfile%s\n",filename);free(gi->cache);free(gi);Index:GeoIP.h===================================================================RCSfile:/home/maxmind/geo ip/c/libGeoIP/GeoIP.h,vretrievingrevision1.19retrievingrevision1.20diff-u-r1.19-r1.20---GeoIP.h20Aug200200:52:00-00001.19+++GeoIP.h27Aug200206:50:02-00001.20@@-45,25+45,31@@externconstchar*GeoIP_country_name[246];externconstchar*GeoIPConfFile;-GeoIP*GeoIP_new(intflags);-GeoIP*GeoIP_open(char*filenam e,intflags);-voidGeoIP_delete(GeoIP*gi);-constchar*GeoIP_country_code_by_addr(GeoIP*gi,constchar*addr);-constchar*GeoIP_country_code_by_name(GeoIP*gi,constchar*host);-constchar*GeoIP_country_code3_by_addr(GeoIP*gi,constchar*addr);-constchar*GeoIP_country_code3_by_name(GeoIP*gi,constchar*host);-const char*GeoIP_country_name_by_addr(GeoIP*gi,constchar*addr);-constchar*GeoIP_country_name_by_name(GeoIP*gi,constchar*host);-shortintGeoIP_country_id_by_addr(GeoIP*gi,constchar*addr);-shortintGeoIP_country_id_by_name(GeoIP*gi,constchar*host);+#ifdef_WIN32+#defineGEOIP_API__declspec(dllexport)+#else+#def ineGEOIP_API+#endif/*_WIN32*/-char*GeoIP_database_info(GeoIP*gi);-shortintGeoIP_update_database(GeoIP*gi,char*license_key,intverbose);+GEOIP_APIGeoIP*GeoIP_new(intflags);+GEOIP_APIGeoIP*GeoIP_open(char*filename,intflags);GEOIP_APIvoidGeoIP_delete(GeoIP*gi);+GEOIP_APIconstchar*GeoIP_country_code_by_a ddr(GeoIP*gi,constchar*addr);+GEOIP_APIconstchar*GeoIP_country_code_by_name(GeoIP*gi,constchar*host);+GEOIP_APIconstchar*GeoIP_country_code3_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIconstchar*GeoIP_country_code3_by_name(GeoIP*gi,constchar*host);+GEOIP_APIconstchar*GeoIP_country_name_by_addr(GeoIP* gi,constchar*addr);+GEOIP_APIconstchar*GeoIP_country_name_by_name(GeoIP*gi,constchar*host);+GEOIP_APIshortintGeoIP_country_id_by_addr(GeoIP*gi,constchar*addr);+GEOIP_APIshortintGeoIP_country_id_by_name(GeoIP*gi,constchar*host);-int_seek_country(GeoIP*gi,constintoffset,unsignedlongipnum,intdepth);-un signedlong_addr_to_num(constchar*addr);-unsignedlong_h_addr_to_num(unsignedchar*addr);-shortint_is_ipaddr(constchar*name);+GEOIP_APIchar*GeoIP_database_info(GeoIP*gi);+GEOIP_APIshortintGeoIP_update_database(GeoIP*gi,char*license_key,intverbose);++GEOIP_APIint_seek_country(GeoIP*gi,constintoffset,uns ignedlongipnum,intdepth);+GEOIP_APIunsignedlong_addr_to_num(constchar*addr);+GEOIP_APIunsignedlong_h_addr_to_num(unsignedchar*addr);#ifdef__cplusplus}Index:GeoIP.c===================================================================RCSfile:/home/maxmind/geoip/c/libGeoIP/GeoIP.c,vretrievingrevision1.32 retrievingrevision1.33diff-u-r1.32-r1.33---GeoIP.c25Aug200222:42:48-00001.32+++GeoIP.c27Aug200206:50:02-00001.33@@-23,16+23,24@@#include<stdio.h>#include<stdlib.h>#include<string.h>+#ifndef_WIN32#include<netdb.h>+#endif/*_WIN32*/#include<assert.h>#include<sys/types.h>/*forfstat*/#include<sys/stat.h>