246 */
247 static PyObject *get_interfaces_info(PyObject *self __unused, PyObject *args) {
248 PyObject *devlist = NULL, *ethinf_py = NULL;
249 PyObject *inargs = NULL;
250 char **fetch_devs;
251 int i = 0, fetch_devs_len = 0;
252
253 if (!PyArg_ParseTuple(args, "|O", &inargs)) {
when PyArg_ParseTuple() succeeds
taking False path
254 PyErr_SetString(PyExc_LookupError,
255 "Argument must be either a string, list or a tuple");
256 return NULL;
257 }
258
259 /* Parse input arguments if we got them */
260 if( inargs != NULL ) {
taking True path
261 if( PyString_Check(inargs) ) { /* Input argument is just a string */
when treating unknown struct _typeobject * from python-ethtool/ethtool.c:261 as non-NULL
when considering value == (long int)0 from python-ethtool/ethtool.c:261
taking False path
262 fetch_devs_len = 1;
263 fetch_devs = calloc(1, sizeof(char *));
264 fetch_devs[0] = PyString_AsString(inargs);
265 } else if( PyTuple_Check(inargs) ) { /* Input argument is a tuple list with devices */
when treating unknown struct _typeobject * from python-ethtool/ethtool.c:265 as non-NULL
when considering value == (long int)0 from python-ethtool/ethtool.c:265
taking False path
266 int j = 0;
267
268 fetch_devs_len = PyTuple_Size(inargs);
269 fetch_devs = calloc(fetch_devs_len+1, sizeof(char *));
270 for( i = 0; i < fetch_devs_len; i++ ) {
271 PyObject *elmt = PyTuple_GetItem(inargs, i);
272 if( elmt && PyString_Check(elmt) ) {
273 fetch_devs[j++] = PyString_AsString(elmt);
274 }
275 }
276 fetch_devs_len = j;
277 } else if( PyList_Check(inargs) ) { /* Input argument is a list with devices */
when treating unknown struct _typeobject * from python-ethtool/ethtool.c:277 as non-NULL
when considering range: 1 <= value <= 0x2000000
taking True path
278 int j = 0;
279
280 fetch_devs_len = PyList_Size(inargs);
when PyList_Size() returns ob_size
281 fetch_devs = calloc(fetch_devs_len+1, sizeof(char *));
282 for( i = 0; i < fetch_devs_len; i++ ) {
when considering range: 1 <= fetch_devs_len <= 0x7fffffff
taking True path
when considering fetch_devs_len == (int)1 from python-ethtool/ethtool.c:280
taking False path
283 PyObject *elmt = PyList_GetItem(inargs, i);
284 if( elmt && PyString_Check(elmt) ) {
taking True path
when considering range: 1 <= value <= 0x8000000
taking True path
285 fetch_devs[j++] = PyString_AsString(elmt);
when PyString_AsString() succeeds
when treating unknown char * * from python-ethtool/ethtool.c:285 as non-NULL
286 }
287 }
288 fetch_devs_len = j;
289 } else {
290 PyErr_SetString(PyExc_LookupError,
291 "Argument must be either a string, list or a tuple");
292 return NULL;
293 }
294 }
295
296 devlist = PyList_New(0);
when PyList_New() succeeds
297 for( i = 0; i < fetch_devs_len; i++ ) {
taking True path
298 struct etherinfo_obj_data *objdata = NULL;
299
300 /* Allocate memory for data structures for each device */
301 objdata = calloc(1, sizeof(struct etherinfo_obj_data));
302 if( !objdata ) {
when treating unknown void * from python-ethtool/ethtool.c:301 as non-NULL
taking False path
303 PyErr_SetString(PyExc_OSError, strerror(errno));
304 return NULL;
305 }
306
307 objdata->ethinfo = calloc(1, sizeof(struct etherinfo));
308 if( !objdata->ethinfo ) {
when treating unknown void * from python-ethtool/ethtool.c:307 as non-NULL
taking False path
309 PyErr_SetString(PyExc_OSError, strerror(errno));
310 return NULL;
311 }
312
313 /* Store the device name and a reference to the NETLINK connection for
314 * objects to use when quering for device info
315 */
316 objdata->ethinfo->device = strdup(fetch_devs[i]);
when treating unknown char * * from python-ethtool/ethtool.c:316 as non-NULL
317 objdata->ethinfo->index = -1;
318 objdata->nlc = &nlconnection;
319 objdata->nlc_users = &nlconnection_users;
320
321 /* Instantiate a new etherinfo object with the device information */
322 ethinf_py = PyCObject_FromVoidPtr(objdata, NULL);
when PyCObject_FromVoidPtr() succeeds
323 if( ethinf_py ) {
taking True path
324 /* Prepare the argument list for the object constructor */
325 PyObject *args = PyTuple_New(1);
when PyTuple_New() fails
326 PyTuple_SetItem(args, 0, ethinf_py);
calling PyTuple_SetItem with NULL as argument 1 (args) at python-ethtool/ethtool.c:326
PyTuple_SetItem() invokes Py_TYPE() on the pointer via the PyTuple_Check() macro, thus accessing (NULL)->ob_type
327
328 /* Create the object */
329 PyObject *dev = PyObject_CallObject((PyObject *)ðtool_etherinfoType, args);
330 if( dev ) {
331 PyList_Append(devlist, dev);
332 Py_DECREF(dev);
333 }
334 Py_DECREF(args);
335 }
336 }
337 if( fetch_devs_len > 0 ) {
338 free(fetch_devs);
339 }
340
341 return devlist;
342 }