From: Frederic Marchal Date: Thu, 6 Jun 2013 12:22:39 +0000 (+0200) Subject: Fix the aliasing of an IPv4 address X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b4af579ec675f8bc0d505a04f5922f111a61b3b0;p=thirdparty%2Fsarg.git Fix the aliasing of an IPv4 address The comparison was not working properly and the line of code was a little bit obfuscated. --- diff --git a/alias.c b/alias.c index 22a1b2e..c3d31ad 100644 --- a/alias.c +++ b/alias.c @@ -711,12 +711,14 @@ Replace the IPv4 address by its alias if it is in our list. static bool Alias_MatchIpv4(struct AliasItemStruct *alias,unsigned char *ipv4) { int len; + int n,m; len=alias->Ipv4.NBits; - if ((len<8 || memcmp(ipv4,alias->Ipv4.Ip,len/8)==0) && ((len%8)==0 || (ipv4[len/8] ^ alias->Ipv4.Ip[len/8]) & (0xFFU<<(8-len%8)))==0) { - return(true); - } - return(false); + n=len/8; + m=len%8; + if (n>0 && memcmp(ipv4,alias->Ipv4.Ip,n)!=0) return(false); + if (m!=0 && (ipv4[n] ^ alias->Ipv4.Ip[n]) & (0xFFU<<(8-m))!=0) return(false); + return(true); } /*!