"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "ip2name.c" between
sarg-2.3.11.tar.gz and sarg-2.4.0.tar.gz

About: SARG ia a Squid Analysis Report Generator.

ip2name.c  (sarg-2.3.11):ip2name.c  (sarg-2.4.0)
/* /*
* SARG Squid Analysis Report Generator http://sarg.sourceforge.net * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
* 1998, 2013 * 1998, 2015
* *
* SARG donations: * SARG donations:
* please look at http://sarg.sourceforge.net/donations.php * please look at http://sarg.sourceforge.net/donations.php
* Support: * Support:
* http://sourceforge.net/projects/sarg/forums/forum/363374 * http://sourceforge.net/projects/sarg/forums/forum/363374
* --------------------------------------------------------------------- * ---------------------------------------------------------------------
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
skipping to change at line 66 skipping to change at line 66
static DichotomicObject KnownIp=NULL; static DichotomicObject KnownIp=NULL;
/*! /*!
Add a new module to the list of the configured modules. Add a new module to the list of the configured modules.
*/ */
static void ip2name_chainmodule(struct Ip2NameProcess *Module) static void ip2name_chainmodule(struct Ip2NameProcess *Module)
{ {
struct Ip2NameProcess *Chain; struct Ip2NameProcess *Chain;
struct Ip2NameProcess *Last; struct Ip2NameProcess *Last;
if (debug) debuga(_("Chaining IP resolving module \"%s\"\n"),Module->Name ); if (debug) debuga(__FILE__,__LINE__,_("Chaining IP resolving module \"%s\ "\n"),Module->Name);
Last=NULL; Last=NULL;
for (Chain=FirstModule ; Chain ; Chain=Chain->Next) { for (Chain=FirstModule ; Chain ; Chain=Chain->Next) {
if (Chain==Module) { if (Chain==Module) {
debuga(_("Ignoring duplicate module \"%s\" to resolve an IP address\n"),Module->Name); debuga(__FILE__,__LINE__,_("Ignoring duplicate module \"% s\" to resolve an IP address\n"),Module->Name);
return; return;
} }
Last=Chain; Last=Chain;
} }
if (Last) if (Last)
Last->Next=Module; Last->Next=Module;
else { else {
FirstModule=Module; FirstModule=Module;
Ip2Name=true; Ip2Name=true;
skipping to change at line 109 skipping to change at line 109
for (length=0 ; (unsigned char)candidate[length]>' ' ; length++); for (length=0 ; (unsigned char)candidate[length]>' ' ; length++);
for (ModuleIdx=0 ; ModuleIdx<sizeof(ModulesList)/sizeof(*ModulesL ist) ; ModuleIdx++) { for (ModuleIdx=0 ; ModuleIdx<sizeof(ModulesList)/sizeof(*ModulesL ist) ; ModuleIdx++) {
if (strncasecmp(candidate,ModulesList[ModuleIdx].Name,len gth)==0 && ModulesList[ModuleIdx].Name[length]=='\0') { if (strncasecmp(candidate,ModulesList[ModuleIdx].Name,len gth)==0 && ModulesList[ModuleIdx].Name[length]=='\0') {
// module found // module found
if (ModulesList[ModuleIdx].Process) if (ModulesList[ModuleIdx].Process)
ip2name_chainmodule(ModulesList[ModuleIdx ].Process); ip2name_chainmodule(ModulesList[ModuleIdx ].Process);
break; break;
} }
} }
if (ModuleIdx>=sizeof(ModulesList)/sizeof(*ModulesList)) { if (ModuleIdx>=sizeof(ModulesList)/sizeof(*ModulesList)) {
debuga(_("Unknown module \"%.*s\" to resolve the IP addre sses\n"),length,candidate); debuga(__FILE__,__LINE__,_("Unknown module \"%.*s\" to re solve the IP addresses\n"),length,candidate);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
list=candidate+length; list=candidate+length;
} }
} }
/*! /*!
Configure a module whose name is given as an argument. The parameters to configu re Configure a module whose name is given as an argument. The parameters to configu re
follow the module name after one or more space or tabs. follow the module name after one or more space or tabs.
skipping to change at line 133 skipping to change at line 133
{ {
int length; int length;
unsigned int ModuleIdx; unsigned int ModuleIdx;
for (length=0 ; module[length] && (unsigned char)module[length]>' ' ; len gth++); for (length=0 ; module[length] && (unsigned char)module[length]>' ' ; len gth++);
for (ModuleIdx=0 ; ModuleIdx<sizeof(ModulesList)/sizeof(*ModulesList) ; M oduleIdx++) { for (ModuleIdx=0 ; ModuleIdx<sizeof(ModulesList)/sizeof(*ModulesList) ; M oduleIdx++) {
if (strncasecmp(module,ModulesList[ModuleIdx].Name,length)==0 && ModulesList[ModuleIdx].Name[length]=='\0') { if (strncasecmp(module,ModulesList[ModuleIdx].Name,length)==0 && ModulesList[ModuleIdx].Name[length]=='\0') {
// module found // module found
if (ModulesList[ModuleIdx].Process) { if (ModulesList[ModuleIdx].Process) {
if (!ModulesList[ModuleIdx].Process->Configure) { if (!ModulesList[ModuleIdx].Process->Configure) {
debuga(_("No option to configure for modu le %s\n"),ModulesList[ModuleIdx].Name); debuga(__FILE__,__LINE__,_("No option to configure for module %s\n"),ModulesList[ModuleIdx].Name);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
while (module[length] && (unsigned char)module[le ngth]<=' ') length++; while (module[length] && (unsigned char)module[le ngth]<=' ') length++;
ModulesList[ModuleIdx].Process->Configure(Modules List[ModuleIdx].Name,module+length); ModulesList[ModuleIdx].Process->Configure(Modules List[ModuleIdx].Name,module+length);
} }
break; break;
} }
} }
} }
skipping to change at line 189 skipping to change at line 189
// find the dns module // find the dns module
for (i=0 ; i<sizeof(ModulesList)/sizeof(*ModulesList) ; i++) { for (i=0 ; i<sizeof(ModulesList)/sizeof(*ModulesList) ; i++) {
if (strcmp("dns",ModulesList[i].Name)==0) { if (strcmp("dns",ModulesList[i].Name)==0) {
// module found // module found
DnsModule=ModulesList[i].Process; DnsModule=ModulesList[i].Process;
break; break;
} }
} }
if (!DnsModule) { if (!DnsModule) {
if (debugz) debuga(_("No known module to resolve an IP address us ing the DNS\n")); debuga(__FILE__,__LINE__,_("No known module to resolve an IP addr ess using the DNS\n"));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
// add the module to the list if it isn't there yet // add the module to the list if it isn't there yet
Last=NULL; Last=NULL;
for (Chain=FirstModule ; Chain && Chain!=DnsModule ; Chain=Chain->Next) { for (Chain=FirstModule ; Chain && Chain!=DnsModule ; Chain=Chain->Next) {
Last=Chain; Last=Chain;
} }
if (debug) debuga(_("Chaining IP resolving module \"%s\"\n"),DnsModule->N ame); if (debug) debuga(__FILE__,__LINE__,_("Chaining IP resolving module \"%s\ "\n"),DnsModule->Name);
if (Last) if (Last)
Last->Next=DnsModule; Last->Next=DnsModule;
else { else {
FirstModule=DnsModule; FirstModule=DnsModule;
Ip2Name=true; Ip2Name=true;
} }
} }
/*! /*!
Convert an IP address into a name. Convert an IP address into a name.
skipping to change at line 226 skipping to change at line 226
void ip2name(char *ip,int ip_len) void ip2name(char *ip,int ip_len)
{ {
struct Ip2NameProcess *Module; struct Ip2NameProcess *Module;
enum ip2name_retcode Status; enum ip2name_retcode Status;
const char *Name; const char *Name;
char OrigIp[80]; char OrigIp[80];
if (!KnownIp) { if (!KnownIp) {
KnownIp=Dichotomic_Create(); KnownIp=Dichotomic_Create();
if (!KnownIp) { if (!KnownIp) {
debuga(_("Not enough memory to store the names correspond ing to the IP address\n")); debuga(__FILE__,__LINE__,_("Not enough memory to store th e names corresponding to the IP address\n"));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
Name=Dichotomic_Search(KnownIp,ip); Name=Dichotomic_Search(KnownIp,ip);
if (Name) { if (Name) {
safe_strcpy(ip,Name,ip_len); safe_strcpy(ip,Name,ip_len);
return; return;
} }
skipping to change at line 261 skipping to change at line 261
void ip2name_cleanup(void) void ip2name_cleanup(void)
{ {
Dichotomic_Destroy(&KnownIp); Dichotomic_Destroy(&KnownIp);
} }
void name2ip(char *name,int name_size) void name2ip(char *name,int name_size)
{ {
#ifdef HAVE_GETADDRINFO #ifdef HAVE_GETADDRINFO
int error; int error;
char *port; char *port;
struct addrinfo *res; struct addrinfo *res=NULL;
char *addr; char *addr;
addr=name; addr=name;
if (name[0]=='[') { //IPv6 address if (name[0]=='[') { //IPv6 address
port=strchr(name,']'); port=strchr(name,']');
if (port) { //confirmed IPv6 address if (port) { //confirmed IPv6 address
*port='\0'; *port='\0';
addr++; addr++;
} }
} else { //IPv4 address } else { //IPv4 address
port=strchr(name,':'); port=strchr(name,':');
if (port) *port='\0'; if (port) *port='\0';
} }
error=getaddrinfo(addr,NULL,NULL,&res); error=getaddrinfo(addr,NULL,NULL,&res);
if (error) { if (error) {
freeaddrinfo(res); if (res) freeaddrinfo(res);
debuga(_("Cannot resolve host name \"%s\": %s\n"),name,gai_strerr debuga(__FILE__,__LINE__,_("Cannot resolve host name \"%s\": %s\n
or(error)); "),name,gai_strerror(error));
exit(EXIT_FAILURE);
}
if (res->ai_family==AF_INET) {
struct sockaddr_in *s4=(struct sockaddr_in *)res->ai_addr;
struct in_addr *sa=&s4->sin_addr;
if (res->ai_addrlen<sizeof(*s4)) {
debuga(_("Short structure returned by getaddrinfo for an
IPv4 address: %d bytes instead of %d\n"),res->ai_addrlen,(int)sizeof(*s4));
exit(EXIT_FAILURE);
}
inet_ntop(res->ai_family,sa,name,name_size);
} else if (res->ai_family==AF_INET6) {
struct sockaddr_in6 *s6=(struct sockaddr_in6 *)res->ai_addr;
struct in6_addr *sa6=&s6->sin6_addr;
if (res->ai_addrlen<sizeof(*s6)) {
debuga(_("Short structure returned by getaddrinfo for an
IPv6 address: %d bytes instead of %d\n"),res->ai_addrlen,(int)sizeof(*s6));
exit(EXIT_FAILURE);
}
inet_ntop(res->ai_family,sa6,name,name_size);
} else { } else {
debuga(_("Invalid address type %d returned when resolving host na if (res->ai_family==AF_INET) {
me \"%s\"\n"),res->ai_family,name); struct sockaddr_in *s4=(struct sockaddr_in *)res->ai_addr
;
struct in_addr *sa=&s4->sin_addr;
if (res->ai_addrlen<sizeof(*s4)) {
debuga(__FILE__,__LINE__,_("Short structure retur
ned by getaddrinfo for an IPv4 address: %d bytes instead of %d\n"),res->ai_addrl
en,(int)sizeof(*s4));
exit(EXIT_FAILURE);
}
inet_ntop(res->ai_family,sa,name,name_size);
} else if (res->ai_family==AF_INET6) {
struct sockaddr_in6 *s6=(struct sockaddr_in6 *)res->ai_ad
dr;
struct in6_addr *sa6=&s6->sin6_addr;
if (res->ai_addrlen<sizeof(*s6)) {
debuga(__FILE__,__LINE__,_("Short structure retur
ned by getaddrinfo for an IPv6 address: %d bytes instead of %d\n"),res->ai_addrl
en,(int)sizeof(*s6));
exit(EXIT_FAILURE);
}
inet_ntop(res->ai_family,sa6,name,name_size);
} else {
debuga(__FILE__,__LINE__,_("Invalid address type %d retur
ned when resolving host name \"%s\"\n"),res->ai_family,name);
}
freeaddrinfo(res);
} }
freeaddrinfo(res);
#else #else
struct in_addr ia; struct in_addr ia;
struct hostent *hp; struct hostent *hp;
char *port; char *port;
char n1[4]; char n1[4];
char n2[4]; char n2[4];
char n3[4]; char n3[4];
char n4[4]; char n4[4];
struct getwordstruct gwarea; struct getwordstruct gwarea;
port=strchr(name,':'); port=strchr(name,':');
if (port) *port='\0'; if (port) *port='\0';
if((hp=gethostbyname(name))==NULL) if ((hp=gethostbyname(name))==NULL)
return; return;
memcpy(&ia.s_addr,hp->h_addr_list[0],sizeof(ia.s_addr)); memcpy(&ia.s_addr,hp->h_addr_list[0],sizeof(ia.s_addr));
ia.s_addr=ntohl(ia.s_addr); ia.s_addr=ntohl(ia.s_addr);
getword_start(&gwarea,inet_ntoa(ia)); getword_start(&gwarea,inet_ntoa(ia));
if (getword(n4,sizeof(n4),&gwarea,'.')<0 || getword(n3,sizeof(n3),&gwarea ,'.')<0 || if (getword(n4,sizeof(n4),&gwarea,'.')<0 || getword(n3,sizeof(n3),&gwarea ,'.')<0 ||
getword(n2,sizeof(n2),&gwarea,'.')<0 || getword(n1,sizeof(n1),&gwarea ,0)<0) { getword(n2,sizeof(n2),&gwarea,'.')<0 || getword(n1,sizeof(n1),&gwarea ,0)<0) {
debuga(_("Invalid record in IP address \"%s\"\n"),gwarea.beginnin g); debuga(__FILE__,__LINE__,_("Invalid IPv4 address \"%s\"\n"),gware a.beginning);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
snprintf(name,name_size,"%s.%s.%s.%s",n1,n2,n3,n4); snprintf(name,name_size,"%s.%s.%s.%s",n1,n2,n3,n4);
#endif #endif
return; return;
} }
 End of changes. 14 change blocks. 
37 lines changed or deleted 41 lines changed or added

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