From 8ffb06e432e3432efe95796730ef9f879c1d1957 Mon Sep 17 00:00:00 2001 From: David Cantrell Date: Wed, 6 Sep 2006 18:20:08 +0000 Subject: * isys/isys.py: Remove inet_aton() and inet_ntoa(). Replaced calls to these functions with inet_pton() and inet_ntop(). * isys/isys.py: Added inet_convertNetmaskToPrefix() utility function to convert dotted-quad IPv4 netmasks to CIDR prefix values. * iw/network_gui.py (createIPRepr): Renamed to createIPV4Repr() and have it write out ip/prefix rather than ip/netmask. * iw/network_gui.py (createIPV4Repr): Added to handle IPv6 write outs to the tree store. * iw/network_gui.py (NetworkWindow.editDevice): Add IPv6 info to the tree store. * iw/network_gui.py (NetworkWindow.setupDevices): Initialize tree store with IPv4 and IPv6 information. --- ChangeLog | 20 ++++++++++++++++++++ isys/isys.py | 35 ++++++++++++++++++++--------------- iw/network_gui.py | 23 ++++++++++++++++++----- 3 files changed, 58 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index f9a07c17d..62b3d88cb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2006-09-06 David Cantrell + + * isys/isys.py: Remove inet_aton() and inet_ntoa(). Replaced calls + to these functions with inet_pton() and inet_ntop(). + + * isys/isys.py: Added inet_convertNetmaskToPrefix() utility function + to convert dotted-quad IPv4 netmasks to CIDR prefix values. + + * iw/network_gui.py (createIPRepr): Renamed to createIPV4Repr() and + have it write out ip/prefix rather than ip/netmask. + + * iw/network_gui.py (createIPV4Repr): Added to handle IPv6 write + outs to the tree store. + + * iw/network_gui.py (NetworkWindow.editDevice): Add IPv6 info to + the tree store. + + * iw/network_gui.py (NetworkWindow.setupDevices): Initialize tree + store with IPv4 and IPv6 information. + 2006-09-06 Chris Lumens * yuminstal.py (YumBackend.doRepoSetup): Iterate over enabled repos, diff --git a/isys/isys.py b/isys/isys.py index efedeef1d..da51abd4d 100644 --- a/isys/isys.py +++ b/isys/isys.py @@ -413,31 +413,36 @@ def mknod(pathname, mode, dev): DeprecationWarning, stacklevel=2) return os.mknod(pathname, mode, dev) -# XXX: Use socket.getnameinfo for ipv6 compatibility -def inet_ntoa (addr): - return socket.inet_ntoa(struct.pack('i', addr)) - -def inet_aton (addr): - try: - return struct.unpack('I', socket.inet_aton(addr))[0] - except: - raise ValueError - def inet_calcNetBroad (ip, nm): if isinstance (ip, type ("")): - ipaddr = inet_aton (ip) + (ipaddr,) = struct.unpack('I', socket.inet_pton(socket.AF_INET, ip)) else: ipaddr = ip if isinstance (nm, type ("")): - nmaddr = inet_aton (nm) + (nmaddr,) = struct.unpack('I', socket.inet_pton(socket.AF_INET, nm)) else: nmaddr = nm netaddr = ipaddr & nmaddr - bcaddr = netaddr | (~nmaddr); - - return (inet_ntoa (netaddr), inet_ntoa (bcaddr)) + bcaddr = netaddr | (~nmaddr) + nw = socket.inet_ntop(socket.AF_INET, struct.pack('i', netaddr)) + bc = socket.inet_ntop(socket.AF_INET, struct.pack('i', bcaddr)) + + return (nw, bc) + +# Converts IPv4 netmasks in dotted-quad notation to the CIDR prefix +def inet_convertNetmaskToPrefix (netmask): + (nm,) = struct.unpack('I', socket.inet_pton(socket.AF_INET, netmask)) + prefix = 0 + + while prefix < 33: + if (nm >> prefix) == 0: + return prefix + + prefix += 1 + + return prefix def getopt(*args): warnings.warn("isys.getopt is deprecated. Use optparse instead.", diff --git a/iw/network_gui.py b/iw/network_gui.py index 6c94661f0..bbf4aec96 100644 --- a/iw/network_gui.py +++ b/iw/network_gui.py @@ -485,7 +485,8 @@ class NetworkWindow(InstallWindow): self.devices[dev].set(('bootproto', bootproto)) self.devices[dev].set(('ONBOOT', onboot)) model.set_value(iter, 0, onboot == 'yes') - model.set_value(iter, 2, self.createIPRepr(self.devices[dev])) + model.set_value(iter, 2, self.createIPV4Repr(self.devices[dev])) + model.set_value(iter, 3, self.createIPV6Repr(self.devices[dev])) editWin.destroy() @@ -494,12 +495,22 @@ class NetworkWindow(InstallWindow): return - def createIPRepr(self, device): + def createIPV4Repr(self, device): bootproto = device.get("bootproto") if bootproto == "dhcp": ip = "DHCP" else: - ip = "%s/%s" % (device.get("ipaddr"), device.get("netmask")) + prefix = isys.inet_convertNetmaskToPrefix(device.get("netmask")) + ip = "%s/%s" % (device.get("ipaddr"), prefix,) + + return ip + + def createIPV6Repr(self, device): + bootproto = device.get("bootproto") + if bootproto == "dhcp": + ip = "DHCP" + else: + ip = "%s" % (device.get("ipv6addr"),) return ip @@ -549,6 +560,7 @@ class NetworkWindow(InstallWindow): devnames.sort() store = gtk.TreeStore(gobject.TYPE_BOOLEAN, + gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING) @@ -566,7 +578,8 @@ class NetworkWindow(InstallWindow): bootproto = 'dhcp' self.devices[device].set(("bootproto", bootproto)) - ip = self.createIPRepr(self.devices[device]) + ipv4 = self.createIPV4Repr(self.devices[device]) + ipv6 = self.createIPV6Repr(self.devices[device]) # only if we want descriptions in the master device list # currently too wide, but might be able to do it with a tooltip on @@ -580,7 +593,7 @@ class NetworkWindow(InstallWindow): # self.ethdevices.append_row((device, ip, descr), active) # # use this for now - self.ethdevices.append_row((device, ip), active) + self.ethdevices.append_row((device, ipv4, ipv6), active) num += 1 -- cgit