[libvirt] [PATCHv2 01/13] New virSocketAddr utility functions

Eric Blake eblake at redhat.com
Wed Dec 22 22:58:05 UTC 2010


On 12/22/2010 11:58 AM, Laine Stump wrote:
> virSocketPrefixToNetmask: Given a 'prefix', which is the number of 1
> bits in a netmask, fill in a virSocketAddr object with a netmask as an
> IP address (IPv6 or IPv4).
> 
> virSocketAddrMask: Mask off the host bits in one virSocketAddr
> according to the netmask in another virSocketAddr.
> 
> virSocketAddrMaskByPrefix, Mask off the host bits in a virSocketAddr
> according to a prefix (number of 1 bits in netmask).
> 
> VIR_SOCKET_FAMILY: return the family of a virSocketAddr

ACK after you fix one bug:

> +    } else if (family == AF_INET6) {
> +        int ii = 0;
> +
> +        if (prefix > 128)
> +            goto error;
> +
> +        while (prefix >= 8) {
> +            /* do as much as possible an entire byte at a time */
> +            netmask->data.inet6.sin6_addr.s6_addr[ii++] = 0xff;
> +            prefix -= 8;
> +        }
> +        if (prefix > 0) {
> +            /* final partial byte */
> +            netmask->data.inet6.sin6_addr.s6_addr[ii++]
> +                = ~((1 << (8 - prefix)) -1);
> +        }

> +        ii++;

Delete this line.  You already incremented it if prefix was nonzero in
the lines above, and don't want to increment it if prefix is a multiple
of 8, so that you don't skip a byte.

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20101222/5371996c/attachment-0001.sig>


More information about the libvir-list mailing list