'initialize IP object by converting IP address string
to binary to integer'

def __init(self, ipstr, cidr=CIDR_UNSPEC):

    self._family = socket.AF_UNSPEC
    self._addr = 0
    self._plen = 0
    self._maskplen = None
    self._raw = ipstr
    if (cidr != IPAddr.CIDR_RAW):
        if ((cidr is not None) and (cidr < IPAddr.CIDR_RAW)):
            family = [(IPAddr.CIDR_RAW - cidr)]
        else:
            family = [socket.AF_INET, socket.AF_INET6]
        for family in family:
            try:
                binary = socket.inet_pton(family, ipstr)
                self._family = family
                break
            except socket.error:
                continue
        if (self._family == socket.AF_INET):
            (self._addr,) = struct.unpack('!L', binary)
            self._plen = 32
            if ((cidr is not None) and (cidr >= 0)):
                mask = (~ (4294967295L >> cidr))
                self._addr &= mask
                self._plen = cidr
        elif (self._family == socket.AF_INET6):
            (hi, lo) = struct.unpack('!QQ', binary)
            self._addr = ((hi << 64) | lo)
            self._plen = 128
            if ((cidr is not None) and (cidr >= 0)):
                mask = (~ (340282366920938463463374607431768211455L >> cidr))
                self._addr &= mask
                self._plen = cidr
            elif self.isInNet(IPAddr.IP6_4COMPAT):
                self._addr = (lo & 4294967295L)
                self._family = socket.AF_INET
                self._plen = 32
    else:
        self._family = IPAddr.CIDR_RAW
