浏览代码

Merge pull request #1286 from jakesmith/ipv4-fix.0

Fix issue handling ipv4 .0 addresses

Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 13 年之前
父节点
当前提交
8867bc4b41
共有 2 个文件被更改,包括 3 次插入30 次删除
  1. 3 28
      system/jlib/jsocket.cpp
  2. 0 2
      system/jlib/jsocket.hpp

+ 3 - 28
system/jlib/jsocket.cpp

@@ -2667,7 +2667,7 @@ bool IpAddress::isLoopBack() const
 {
     if (::isIp4(netaddr)&&((netaddr[3] & 0x000000ff)==0x000007f))
         return true;
-    return (netaddr[3]==0)&&(netaddr[2]==0)&&(netaddr[1]==0)&&(netaddr[0]==1);
+    return (netaddr[3]==0x1000000)&&(netaddr[2]==0)&&(netaddr[1]==0)&&(netaddr[0]==0);
 }
 
 bool IpAddress::isLocal() const 
@@ -2678,30 +2678,6 @@ bool IpAddress::isLocal() const
     return isInterfaceIp(ip, NULL);
 }
 
-
-bool IpAddress::isLinkLocal() const
-{
-    return (netaddr[0]&&0x3ff==0x3fa)&&(netaddr[2]==0);
-}
-
-
-bool IpAddress::isSiteLocal() const // depreciated
-{
-    if (::isIp4(netaddr)) {
-        switch (netaddr[3]&0xff) {
-        case 10:
-            return true;
-        case 192:
-            return ((netaddr[3]&0xff00)==0xc000);
-        case 172:
-            return ((netaddr[3]&0x0f00)==0x0100);
-        }
-        return false;
-    }
-    return (netaddr[0]&&0x3ff==0x3fb)&&(netaddr[2]==0);
-}
-
-
 bool IpAddress::ipequals(const IpAddress & other) const
 {
     // reverse compare for speed
@@ -2713,7 +2689,6 @@ int  IpAddress::ipcompare(const IpAddress & other) const
     return memcmp(&netaddr, &other.netaddr, sizeof(netaddr));
 }
 
-
 unsigned IpAddress::iphash(unsigned prev) const
 {
     return hashc((const byte *)&netaddr,sizeof(netaddr),prev);
@@ -2963,7 +2938,7 @@ void IpAddress::ipdeserialize(MemoryBuffer & in)
     if (pfx!=IPV6_SERIALIZE_PREFIX) {
         netaddr[0] = 0;
         netaddr[1] = 0;
-        netaddr[2] = (pfx>0x1000000)?0xffff0000:0;  // catch null and loopback
+        netaddr[2] = (pfx == 0 || pfx == 0x1000000) ? 0 : 0xffff0000; // catch null and loopback
         netaddr[3] = pfx;
     }
     else 
@@ -3072,7 +3047,7 @@ void IpAddress::setNetAddress(size32_t sz,const void *src)
     }
     else if (!IP4only&&(sz==sizeof(netaddr))) { // IPv6
         memcpy(&netaddr,src,sz);
-        if ((netaddr[2]==0)&&(netaddr[3]>0x1000000)&&(netaddr[0]==0)&&(netaddr[1]==0))
+        if ((netaddr[2]==0)&&(netaddr[3]!=0)&&(netaddr[3]!=0x1000000)&&(netaddr[0]==0)&&(netaddr[1]==0))
             netaddr[2]=0xffff0000;  // use this form only
     }
     else

+ 0 - 2
system/jlib/jsocket.hpp

@@ -90,8 +90,6 @@ public:
     bool isHost() const;                                // is primary host NIC ip
     bool isLoopBack() const;                            // is loopback (localhost: 127.0.0.1 or ::1)
     bool isLocal() const;                               // matches local interface 
-    bool isLinkLocal() const;
-    bool isSiteLocal() const; // depreciated
     bool isIp4() const;
     StringBuffer &getIpText(StringBuffer & out) const;
     void ipserialize(MemoryBuffer & out) const;