[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH] network utilities



On 10/28/2009 10:35 AM, Daniel Veillard wrote:
On Thu, Oct 22, 2009 at 04:42:20PM -0400, Laine Stump wrote:
+/*
+ * Helpers to extract the IP arrays from the virSocketAddrPtr
+ * That part is the less portable of the module
+ */
+typedef unsigned char virIPv4Addr[4];
+typedef virIPv4Addr *virIPv4AddrPtr;
+typedef unsigned short virIPv6Addr[8];


Are you defining this an an array of short for efficiency? It's much
easier to deal with if you just look at it as a byte array - you don't
need to worry about network vs. host ordering when doing comparisons and
bit shifts/masks (IPv6 addresses, like IPv4 addresses, are *always* in
network order, even when being passed around in applications - see
section 3.2 of
http://tools.ietf.org/html/rfc3493.)
   No. Those routines and structs are purely internal, and I choose to
adopt a structure which match the way addresses are serialized in
writing. So if you see 192.168.0.1 and look at the parsed array
(in code or in gdb) you see the same thing. This is mostly to make the
code understandable. For Ipv6 since in writing people use blocks of
values 0000-FFFF is was making sense for me to match that and use an
array of short. htonx and ntohx are just here to make code and debug
easier to understand.

Okay, now I see that 1) you only have the conversion in one direction, so obviously it's not going to be used in any API, and 2) all the netmask functions are operating from the virSocketAddr rather than the viIPvxAddr. My concern was caused by thinking it would be used in more general ways.

Personally I've just gotten used to using /x, and reading the number backwards ;-) (and if it's IPv6, I've only ever got a couple addresses I'm dealing with, and I make sure they're different enough to be easily recognizeable. That will of course change sometime in the next 20 years or so, when IPv6 is actually in common use on production networks :-P) (seriously, I should be using it on my home network. Heck, Red Hat should be routing it through the VPN so we can all globally drink the koolaid!)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]