diff options
author | David Sommerseth <davids@redhat.com> | 2010-04-26 20:38:57 +0200 |
---|---|---|
committer | David Sommerseth <davids@redhat.com> | 2010-04-26 20:38:57 +0200 |
commit | d3fd6b84f461a4d7ffbf3f3eae37381150b69e82 (patch) | |
tree | 4de791e5b791b50fe42056443b6dbfae2c3a29f1 /python-ethtool/ethtool.c | |
parent | bfdcac6b16806416a6c0295fcfad5d820595d88c (diff) | |
download | python-ethtool-d3fd6b84f461a4d7ffbf3f3eae37381150b69e82.tar.gz python-ethtool-d3fd6b84f461a4d7ffbf3f3eae37381150b69e82.tar.xz python-ethtool-d3fd6b84f461a4d7ffbf3f3eae37381150b69e82.zip |
Rewritten ethtool to make use of libnl instead of accessing NETLINK directly
Diffstat (limited to 'python-ethtool/ethtool.c')
-rw-r--r-- | python-ethtool/ethtool.c | 52 |
1 files changed, 14 insertions, 38 deletions
diff --git a/python-ethtool/ethtool.c b/python-ethtool/ethtool.c index 8d67844..d84bc79 100644 --- a/python-ethtool/ethtool.c +++ b/python-ethtool/ethtool.c @@ -233,9 +233,9 @@ static PyObject *get_ipaddress(PyObject *self __unused, PyObject *args) static PyObject *get_interface_info(PyObject *self __unused, PyObject *args) { PyObject *devlist = NULL, *ethinf_py = NULL; PyObject *inargs = NULL; - struct etherinfo *devinfo = NULL, *ptr = NULL; + struct etherinfo *devinfo = NULL; char **fetch_devs; - int fetch_devs_len = 0; + int i = 0, fetch_devs_len = 0; if (!PyArg_ParseTuple(args, "|O", &inargs)) { PyErr_SetString(PyExc_LookupError, @@ -250,7 +250,7 @@ static PyObject *get_interface_info(PyObject *self __unused, PyObject *args) { fetch_devs = calloc(1, sizeof(char *)); fetch_devs[0] = PyString_AsString(inargs); } else if( PyTuple_Check(inargs) ) { /* Input argument is a tuple list with devices */ - int i, j = 0; + int j = 0; fetch_devs_len = PyTuple_Size(inargs); fetch_devs = calloc(fetch_devs_len+1, sizeof(char *)); @@ -262,7 +262,7 @@ static PyObject *get_interface_info(PyObject *self __unused, PyObject *args) { } fetch_devs_len = j; } else if( PyList_Check(inargs) ) { /* Input argument is a list with devices */ - int i, j = 0; + int j = 0; fetch_devs_len = PyList_Size(inargs); fetch_devs = calloc(fetch_devs_len+1, sizeof(char *)); @@ -279,35 +279,15 @@ static PyObject *get_interface_info(PyObject *self __unused, PyObject *args) { return NULL; } } - devinfo = get_etherinfo(); - if( !devinfo ) { - PyErr_SetString(PyExc_OSError, strerror(errno)); - return NULL; - } - /* Slice up the etherinfo struct and populate individual objects with - * the current ethernet information. - */ - devlist = PyList_New(0); - while( devinfo->next != NULL ) { - /* Get copy of pointers, before we start slicing it up */ - ptr = devinfo->next; /* Fetch the pointer to the next element first */ - devinfo->next = NULL; /* Make the current slice do not point anywhere else */ - - /* Skip this device only if we have a list of devices and the current one */ - /* does not match */ - if( fetch_devs_len > 0) { - int i; - for( i = 0; i < fetch_devs_len; i++ ) { - if( fetch_devs[i] && (strcmp(fetch_devs[i], devinfo->device) == 0) ) { - goto found_dev; /* Add this device to the devlist */ - } - } - /* Free the info which we don't need, and continue */ - free_etherinfo(devinfo); - goto next_dev; + + for( i = 0; i < fetch_devs_len; i++ ) { + devinfo = get_etherinfo(fetch_devs[i]); + if( !devinfo ) { + PyErr_SetString(PyExc_OSError, strerror(errno)); + return NULL; } - found_dev: + /* Instantiate a new etherinfo object with the device information */ ethinf_py = PyCObject_FromVoidPtr(devinfo, NULL); if( ethinf_py ) { @@ -319,14 +299,10 @@ static PyObject *get_interface_info(PyObject *self __unused, PyObject *args) { PyObject *dev = PyObject_CallObject((PyObject *)ðtool_etherinfoType, args); PyList_Append(devlist, dev); } - next_dev: - devinfo = ptr; /* Go to the next element */ - } - /* clean up headers which might not be used or considered interesting */ - if( devinfo != NULL ) { - free_etherinfo(devinfo); + if( devinfo != NULL ) { + free_etherinfo(devinfo); + } } - if( fetch_devs_len > 0 ) { free(fetch_devs); } |