summaryrefslogtreecommitdiffstats
path: root/python-ethtool/etherinfo_struct.h
diff options
context:
space:
mode:
authorDavid Sommerseth <davids@redhat.com>2010-07-30 19:30:30 +0200
committerDavid Sommerseth <davids@redhat.com>2010-07-30 19:30:30 +0200
commite9aa46ab32a45bd7fc0ad32573d1db84f5049554 (patch)
treea736740bf5c38a84cf0f7868d97bfc02fdf5aaed /python-ethtool/etherinfo_struct.h
parent1d4b0d894dd833cd9ac9e62cbdc400f24a11e32b (diff)
downloadpython-ethtool-e9aa46ab32a45bd7fc0ad32573d1db84f5049554.tar.gz
python-ethtool-e9aa46ab32a45bd7fc0ad32573d1db84f5049554.tar.xz
python-ethtool-e9aa46ab32a45bd7fc0ad32573d1db84f5049554.zip
Improved IPv6 support
As the IPv6 protocol allows a single device to have more than one IPv6 address, the previous implementation did not provide all IPv6 information. It would reject all except the last parsed IPv6 address. NOTE: This implementation will break the previous API. This change removes the ethtool.etherinfo.ipv6_address and ethtool.etherinfo.ipv6_netmask members. A new member is added, ethtool.etherinfo.ipv6_addresses (in plural). This contains a tupple list containing of ethtool.etherinfo_ipv6addr objects, one object for each configured IPv6 address on the device. These objects have the following members available: .address - The IPv6 address .netmask - The IPv6 netmask (in bit notation) .scope - A string with the IPv6 address scope Example code: import ethtool devs = ethtool.get_interfaces_info('eth0') for ip6 in devs[0].ipv6_addresses: print "[%s] %s/%i" % (ip6.scope, ip6.address, ip6.netmask) Signed-off-by: David Sommerseth <davids@redhat.com>
Diffstat (limited to 'python-ethtool/etherinfo_struct.h')
-rw-r--r--python-ethtool/etherinfo_struct.h25
1 files changed, 23 insertions, 2 deletions
diff --git a/python-ethtool/etherinfo_struct.h b/python-ethtool/etherinfo_struct.h
index b09b49c..8f9e2e5 100644
--- a/python-ethtool/etherinfo_struct.h
+++ b/python-ethtool/etherinfo_struct.h
@@ -18,8 +18,14 @@ struct etherinfo {
char *ipv4_address;
int ipv4_netmask;
char *ipv4_broadcast;
- char *ipv6_address;
- int ipv6_netmask;
+ struct ipv6address *ipv6_addresses;
+};
+
+struct ipv6address {
+ char *address;
+ int netmask;
+ int scope;
+ struct ipv6address *next;
};
/*
@@ -45,4 +51,19 @@ typedef struct {
struct etherinfo_obj_data *data;
} etherinfo_py;
+
+typedef struct {
+ PyObject_HEAD
+ struct ipv6address *addrdata;
+} etherinfo_ipv6_py;
+
+/**
+ * NULL safe PyString_FromString() wrapper. If input string is NULL, None will be returned
+ *
+ * @param str Input C string (char *)
+ *
+ * @return Returns a PyObject with either the input string wrapped up, or a Python None value.
+ */
+#define RETURN_STRING(str) (str ? PyString_FromString(str) : Py_None)
+
#endif