File: | netifaces.c |
Function: | ifaddrs |
Error: | ob_refcnt of '*dict' is 1 too high |
358 static PyObject *
359 ifaddrs (PyObject *self, PyObject *args)
360 {
361 const char *ifname;
362 PyObject *result;
363 int found = FALSE;
364 #if defined(WIN32)
365 PIP_ADAPTER_INFO pAdapterInfo = NULL;
366 PIP_ADAPTER_INFO pInfo = NULL;
367 ULONG ulBufferLength = 0;
368 DWORD dwRet;
369 PIP_ADDR_STRING str;
370 #endif
371
372 if (!PyArg_ParseTuple (args, "s", &ifname))
when PyArg_ParseTuple() succeeds
taking False path
373 return NULL;
374
375 result = PyDict_New ();
when PyDict_New() succeeds
376
377 if (!result)
taking False path
378 return NULL;
379
380 #if defined(WIN32)
381 /* First, retrieve the adapter information. We do this in a loop, in
382 case someone adds or removes adapters in the meantime. */
383 do {
384 dwRet = GetAdaptersInfo(pAdapterInfo, &ulBufferLength);
385
386 if (dwRet == ERROR_BUFFER_OVERFLOW) {
387 if (pAdapterInfo)
388 free (pAdapterInfo);
389 pAdapterInfo = (PIP_ADAPTER_INFO)malloc (ulBufferLength);
390
391 if (!pAdapterInfo) {
392 Py_DECREF (result);
393 PyErr_SetString (PyExc_MemoryError, "Not enough memory");
394 return NULL;
395 }
396 }
397 } while (dwRet == ERROR_BUFFER_OVERFLOW);
398
399 /* If we failed, then fail in Python too */
400 if (dwRet != ERROR_SUCCESS && dwRet != ERROR_NO_DATA) {
401 Py_DECREF (result);
402 if (pAdapterInfo)
403 free (pAdapterInfo);
404
405 PyErr_SetString (PyExc_OSError,
406 "Unable to obtain adapter information.");
407 return NULL;
408 }
409
410 for (pInfo = pAdapterInfo; pInfo; pInfo = pInfo->Next) {
411 char buffer[256];
412
413 if (strcmp (pInfo->AdapterName, ifname) != 0)
414 continue;
415
416 found = TRUE;
417
418 /* Do the physical address */
419 if (256 >= 3 * pInfo->AddressLength) {
420 PyObject *hwaddr, *dict;
421 char *ptr = buffer;
422 unsigned n;
423
424 *ptr = '\0';
425 for (n = 0; n < pInfo->AddressLength; ++n) {
426 sprintf (ptr, "%02x:", pInfo->Address[n] & 0xff);
427 ptr += 3;
428 }
429 *--ptr = '\0';
430
431 hwaddr = PyString_FromString (buffer);
432 dict = PyDict_New ();
433
434 if (!dict) {
435 Py_XDECREF (hwaddr);
436 Py_DECREF (result);
437 free (pAdapterInfo);
438 return NULL;
439 }
440
441 PyDict_SetItemString (dict, "addr", hwaddr);
442 Py_DECREF (hwaddr);
443
444 if (!add_to_family (result, AF_LINK, dict)) {
445 Py_DECREF (result);
446 free (pAdapterInfo);
447 return NULL;
448 }
449 }
450
451 for (str = &pInfo->IpAddressList; str; str = str->Next) {
452 PyObject *addr = PyString_FromString (str->IpAddress.String);
453 PyObject *mask = PyString_FromString (str->IpMask.String);
454 PyObject *bcast = NULL;
455 PyObject *dict;
456
457 /* If this isn't the loopback interface, work out the broadcast
458 address, for better compatibility with other platforms. */
459 if (pInfo->Type != MIB_IF_TYPE_LOOPBACK) {
460 unsigned long inaddr = inet_addr (str->IpAddress.String);
461 unsigned long inmask = inet_addr (str->IpMask.String);
462 struct in_addr in;
463 char *brstr;
464
465 in.S_un.S_addr = (inaddr | ~inmask) & 0xfffffffful;
466
467 brstr = inet_ntoa (in);
468
469 if (brstr)
470 bcast = PyString_FromString (brstr);
471 }
472
473 dict = PyDict_New ();
474
475 if (!dict) {
476 Py_XDECREF (addr);
477 Py_XDECREF (mask);
478 Py_XDECREF (bcast);
479 Py_DECREF (result);
480 free (pAdapterInfo);
481 return NULL;
482 }
483
484 if (addr)
485 PyDict_SetItemString (dict, "addr", addr);
486 if (mask)
487 PyDict_SetItemString (dict, "netmask", mask);
488 if (bcast)
489 PyDict_SetItemString (dict, "broadcast", bcast);
490
491 Py_XDECREF (addr);
492 Py_XDECREF (mask);
493 Py_XDECREF (bcast);
494
495 if (!add_to_family (result, AF_INET, dict)) {
496 Py_DECREF (result);
497 free (pAdapterInfo);
498 return NULL;
499 }
500 }
501 }
502
503 free (pAdapterInfo);
504 #elif HAVE_GETIFADDRS
505 struct ifaddrs *addrs = NULL;
506 struct ifaddrs *addr = NULL;
507
508 if (getifaddrs (&addrs) < 0) {
when considering range: 0 <= value <= 0x7fffffff
taking False path
509 Py_DECREF (result);
510 PyErr_SetFromErrno (PyExc_OSError);
511 return NULL;
512 }
513
514 for (addr = addrs; addr; addr = addr->ifa_next) {
when treating unknown struct ifaddrs * * from netifaces.c:508 as non-NULL
taking True path
when treating unknown struct ifaddrs * from netifaces.c:514 as NULL
taking False path
515 char buffer[256];
516 PyObject *pyaddr = NULL, *netmask = NULL, *braddr = NULL;
517
518 if (strcmp (addr->ifa_name, ifname) != 0)
when considering value == (int)0 from netifaces.c:518
taking False path
519 continue;
520
521 /* Sometimes there are records without addresses (e.g. in the case of a
522 dial-up connection via ppp, which on Linux can have a link address
523 record with no actual address). We skip these as they aren't useful.
524 Thanks to Christian Kauhaus for reporting this issue. */
525 if (!addr->ifa_addr)
when treating unknown struct sockaddr * from netifaces.c:525 as non-NULL
taking False path
526 continue;
527
528 found = TRUE;
529
530 if (string_from_sockaddr (addr->ifa_addr, buffer, sizeof (buffer)) == 0)
when considering range: -0x80000000 <= value <= -1
taking False path
531 pyaddr = PyString_FromString (buffer);
532
533 if (string_from_sockaddr (addr->ifa_netmask, buffer, sizeof (buffer)) == 0)
when considering range: -0x80000000 <= value <= -1
taking False path
534 netmask = PyString_FromString (buffer);
535
536 if (string_from_sockaddr (addr->ifa_broadaddr, buffer, sizeof (buffer)) == 0)
when considering value == (int)0 from netifaces.c:536
taking True path
537 braddr = PyString_FromString (buffer);
when PyString_FromString() succeeds
538
539 PyObject *dict = PyDict_New();
when PyDict_New() succeeds
PyDictObject allocated at: PyObject *dict = PyDict_New();
ob_refcnt is now refs: 1 + N where N >= 0
540
541 if (!dict) {
taking False path
542 Py_XDECREF (pyaddr);
543 Py_XDECREF (netmask);
544 Py_XDECREF (braddr);
545 Py_DECREF (result);
546 freeifaddrs (addrs);
547 return NULL;
548 }
549
550 if (pyaddr)
taking False path
551 PyDict_SetItemString (dict, "addr", pyaddr);
552 if (netmask)
taking False path
553 PyDict_SetItemString (dict, "netmask", netmask);
554
555 if (braddr) {
taking True path
556 if (addr->ifa_flags & (IFF_POINTOPOINT | IFF_LOOPBACK))
when considering value == (unsigned int)0 from netifaces.c:556
taking False path
557 PyDict_SetItemString (dict, "peer", braddr);
558 else
559 PyDict_SetItemString (dict, "broadcast", braddr);
when PyDict_SetItemString() succeeds
560 }
561
562 Py_XDECREF (pyaddr);
taking True path
563 Py_XDECREF (netmask);
taking True path
564 Py_XDECREF (braddr);
taking False path
taking True path
565
566 if (!add_to_family (result, addr->ifa_addr->sa_family, dict)) {
when treating unknown struct sockaddr * from netifaces.c:566 as non-NULL
when considering range: -0x80000000 <= value <= -1
taking False path
567 Py_DECREF (result);
568 freeifaddrs (addrs);
569 return NULL;
570 }
571 }
572
573 freeifaddrs (addrs);
574 #elif HAVE_SOCKET_IOCTLS
575
576 int sock = socket(AF_INET, SOCK_DGRAM, 0);
577
578 if (sock < 0) {
579 Py_DECREF (result);
580 PyErr_SetFromErrno (PyExc_OSError);
581 return NULL;
582 }
583
584 struct CNAME(ifreq) ifr;
585 PyObject *addr = NULL, *netmask = NULL, *braddr = NULL, *dstaddr = NULL;
586 int is_p2p = FALSE;
587 char buffer[256];
588
589 strncpy (ifr.CNAME(ifr_name), ifname, IFNAMSIZ);
590
591 #if HAVE_SIOCGIFHWADDR
592 if (ioctl (sock, SIOCGIFHWADDR, &ifr) == 0) {
593 found = TRUE;
594
595 if (string_from_sockaddr (ifr->CNAME(ifr_addr), buffer, sizeof (buffer)) == 0) {
596 PyObject *hwaddr = PyString_FromString (buffer);
597 PyObject *dict = PyDict_New ();
598 PyObject *list = PyList_New (1);
599 PyObject *family = PyInt_FromLong (AF_LINK);
600
601 if (!hwaddr || !dict || !list || !family) {
602 Py_XDECREF (hwaddr);
603 Py_XDECREF (dict);
604 Py_XDECREF (list)
605 Py_XDECREF (family);
606 Py_XDECREF (result);
607 close (sock);
608 return NULL;
609 }
610
611 PyDict_SetItemString (dict, "addr", hwaddr);
612 Py_DECREF (hwaddr);
613
614 PyList_SET_ITEM (list, 0, dict);
615
616 PyDict_SetItem (result, family, list);
617 Py_DECREF (family);
618 Py_DECREF (list);
619 }
620 }
621 #endif
622
623 #if HAVE_SIOCGIFADDR
624 #if HAVE_SIOCGLIFNUM
625 if (ioctl (sock, SIOCGLIFADDR, &ifr) == 0) {
626 #else
627 if (ioctl (sock, SIOCGIFADDR, &ifr) == 0) {
628 #endif
629 found = TRUE;
630
631 if (string_from_sockaddr ((struct sockaddr *)&ifr.CNAME(ifr_addr), buffer, sizeof (buffer)) == 0)
632 addr = PyString_FromString (buffer);
633 }
634 #endif
635
636 #if HAVE_SIOCGIFNETMASK
637 #if HAVE_SIOCGLIFNUM
638 if (ioctl (sock, SIOCGLIFNETMASK, &ifr) == 0) {
639 #else
640 if (ioctl (sock, SIOCGIFNETMASK, &ifr) == 0) {
641 #endif
642 found = TRUE;
643
644 if (string_from_sockaddr ((struct sockaddr *)&ifr.CNAME(ifr_addr), buffer, sizeof (buffer)) == 0)
645 netmask = PyString_FromString (buffer);
646 }
647 #endif
648
649 #if HAVE_SIOCGIFFLAGS
650 #if HAVE_SIOCGLIFNUM
651 if (ioctl (sock, SIOCGLIFFLAGS, &ifr) == 0) {
652 #else
653 if (ioctl (sock, SIOCGIFFLAGS, &ifr) == 0) {
654 #endif
655 found = TRUE;
656
657 if (ifr.CNAME(ifr_flags) & IFF_POINTOPOINT)
658 is_p2p = TRUE;
659 }
660 #endif
661
662 #if HAVE_SIOCGIFBRDADDR
663 #if HAVE_SIOCGLIFNUM
664 if (!is_p2p && ioctl (sock, SIOCGLIFBRDADDR, &ifr) == 0) {
665 #else
666 if (!is_p2p && ioctl (sock, SIOCGIFBRDADDR, &ifr) == 0) {
667 #endif
668 found = TRUE;
669
670 if (string_from_sockaddr ((struct sockaddr *)&ifr.CNAME(ifr_addr), buffer, sizeof (buffer)) == 0)
671 braddr = PyString_FromString (buffer);
672 }
673 #endif
674
675 #if HAVE_SIOCGIFDSTADDR
676 #if HAVE_SIOCGLIFNUM
677 if (is_p2p && ioctl (sock, SIOCGLIFBRDADDR, &ifr) == 0) {
678 #else
679 if (is_p2p && ioctl (sock, SIOCGIFBRDADDR, &ifr) == 0) {
680 #endif
681 found = TRUE;
682
683 if (string_from_sockaddr ((struct sockaddr *)&ifr.CNAME(ifr_addr), buffer, sizeof (buffer)) == 0)
684 dstaddr = PyString_FromString (buffer);
685 }
686 #endif
687
688 PyObject *dict = PyDict_New();
689
690 if (!dict) {
691 Py_XDECREF (addr);
692 Py_XDECREF (netmask);
693 Py_XDECREF (braddr);
694 Py_XDECREF (dstaddr);
695 Py_DECREF (result);
696 close (sock);
697 return NULL;
698 }
699
700 if (addr)
701 PyDict_SetItemString (dict, "addr", addr);
702 if (netmask)
703 PyDict_SetItemString (dict, "netmask", netmask);
704 if (braddr)
705 PyDict_SetItemString (dict, "broadcast", braddr);
706 if (dstaddr)
707 PyDict_SetItemString (dict, "peer", dstaddr);
708
709 Py_XDECREF (addr);
710 Py_XDECREF (netmask);
711 Py_XDECREF (braddr);
712 Py_XDECREF (dstaddr);
713
714 if (!PyDict_Size (dict))
715 Py_DECREF (dict);
716 else {
717 PyObject *list = PyList_New(1);
718
719 if (!list) {
720 Py_DECREF (dict);
721 Py_DECREF (result);
722 close (sock);
723 return NULL;
724 }
725
726 PyList_SET_ITEM (list, 0, dict);
727
728 PyObject *family = PyInt_FromLong (AF_INET);
729 if (!family) {
730 Py_DECREF (result);
731 Py_DECREF (list);
732 close (sock);
733 return NULL;
734 }
735
736 PyDict_SetItem (result, family, list);
737 Py_DECREF (family);
738 Py_DECREF (list);
739 }
740
741 close (sock);
742
743 #endif /* HAVE_SOCKET_IOCTLS */
744
745 if (found)
taking True path
746 return result;
747 else {
748 Py_DECREF (result);
749 PyErr_SetString (PyExc_ValueError,
750 "You must specify a valid interface name.");
751 return NULL;
752 }
753 }
ob_refcnt of '*dict' is 1 too high
was expecting final ob_refcnt to be N + 0 (for some unknown N)
but final ob_refcnt is N + 1
found 7 similar trace(s) to this
File: | netifaces.c |
Function: | ifaddrs |
Error: | returning (PyObject*)NULL without setting an exception |
358 static PyObject *
359 ifaddrs (PyObject *self, PyObject *args)
360 {
361 const char *ifname;
362 PyObject *result;
363 int found = FALSE;
364 #if defined(WIN32)
365 PIP_ADAPTER_INFO pAdapterInfo = NULL;
366 PIP_ADAPTER_INFO pInfo = NULL;
367 ULONG ulBufferLength = 0;
368 DWORD dwRet;
369 PIP_ADDR_STRING str;
370 #endif
371
372 if (!PyArg_ParseTuple (args, "s", &ifname))
when PyArg_ParseTuple() succeeds
taking False path
373 return NULL;
374
375 result = PyDict_New ();
when PyDict_New() succeeds
376
377 if (!result)
taking False path
378 return NULL;
379
380 #if defined(WIN32)
381 /* First, retrieve the adapter information. We do this in a loop, in
382 case someone adds or removes adapters in the meantime. */
383 do {
384 dwRet = GetAdaptersInfo(pAdapterInfo, &ulBufferLength);
385
386 if (dwRet == ERROR_BUFFER_OVERFLOW) {
387 if (pAdapterInfo)
388 free (pAdapterInfo);
389 pAdapterInfo = (PIP_ADAPTER_INFO)malloc (ulBufferLength);
390
391 if (!pAdapterInfo) {
392 Py_DECREF (result);
393 PyErr_SetString (PyExc_MemoryError, "Not enough memory");
394 return NULL;
395 }
396 }
397 } while (dwRet == ERROR_BUFFER_OVERFLOW);
398
399 /* If we failed, then fail in Python too */
400 if (dwRet != ERROR_SUCCESS && dwRet != ERROR_NO_DATA) {
401 Py_DECREF (result);
402 if (pAdapterInfo)
403 free (pAdapterInfo);
404
405 PyErr_SetString (PyExc_OSError,
406 "Unable to obtain adapter information.");
407 return NULL;
408 }
409
410 for (pInfo = pAdapterInfo; pInfo; pInfo = pInfo->Next) {
411 char buffer[256];
412
413 if (strcmp (pInfo->AdapterName, ifname) != 0)
414 continue;
415
416 found = TRUE;
417
418 /* Do the physical address */
419 if (256 >= 3 * pInfo->AddressLength) {
420 PyObject *hwaddr, *dict;
421 char *ptr = buffer;
422 unsigned n;
423
424 *ptr = '\0';
425 for (n = 0; n < pInfo->AddressLength; ++n) {
426 sprintf (ptr, "%02x:", pInfo->Address[n] & 0xff);
427 ptr += 3;
428 }
429 *--ptr = '\0';
430
431 hwaddr = PyString_FromString (buffer);
432 dict = PyDict_New ();
433
434 if (!dict) {
435 Py_XDECREF (hwaddr);
436 Py_DECREF (result);
437 free (pAdapterInfo);
438 return NULL;
439 }
440
441 PyDict_SetItemString (dict, "addr", hwaddr);
442 Py_DECREF (hwaddr);
443
444 if (!add_to_family (result, AF_LINK, dict)) {
445 Py_DECREF (result);
446 free (pAdapterInfo);
447 return NULL;
448 }
449 }
450
451 for (str = &pInfo->IpAddressList; str; str = str->Next) {
452 PyObject *addr = PyString_FromString (str->IpAddress.String);
453 PyObject *mask = PyString_FromString (str->IpMask.String);
454 PyObject *bcast = NULL;
455 PyObject *dict;
456
457 /* If this isn't the loopback interface, work out the broadcast
458 address, for better compatibility with other platforms. */
459 if (pInfo->Type != MIB_IF_TYPE_LOOPBACK) {
460 unsigned long inaddr = inet_addr (str->IpAddress.String);
461 unsigned long inmask = inet_addr (str->IpMask.String);
462 struct in_addr in;
463 char *brstr;
464
465 in.S_un.S_addr = (inaddr | ~inmask) & 0xfffffffful;
466
467 brstr = inet_ntoa (in);
468
469 if (brstr)
470 bcast = PyString_FromString (brstr);
471 }
472
473 dict = PyDict_New ();
474
475 if (!dict) {
476 Py_XDECREF (addr);
477 Py_XDECREF (mask);
478 Py_XDECREF (bcast);
479 Py_DECREF (result);
480 free (pAdapterInfo);
481 return NULL;
482 }
483
484 if (addr)
485 PyDict_SetItemString (dict, "addr", addr);
486 if (mask)
487 PyDict_SetItemString (dict, "netmask", mask);
488 if (bcast)
489 PyDict_SetItemString (dict, "broadcast", bcast);
490
491 Py_XDECREF (addr);
492 Py_XDECREF (mask);
493 Py_XDECREF (bcast);
494
495 if (!add_to_family (result, AF_INET, dict)) {
496 Py_DECREF (result);
497 free (pAdapterInfo);
498 return NULL;
499 }
500 }
501 }
502
503 free (pAdapterInfo);
504 #elif HAVE_GETIFADDRS
505 struct ifaddrs *addrs = NULL;
506 struct ifaddrs *addr = NULL;
507
508 if (getifaddrs (&addrs) < 0) {
when considering range: 0 <= value <= 0x7fffffff
taking False path
509 Py_DECREF (result);
510 PyErr_SetFromErrno (PyExc_OSError);
511 return NULL;
512 }
513
514 for (addr = addrs; addr; addr = addr->ifa_next) {
when treating unknown struct ifaddrs * * from netifaces.c:508 as non-NULL
taking True path
515 char buffer[256];
516 PyObject *pyaddr = NULL, *netmask = NULL, *braddr = NULL;
517
518 if (strcmp (addr->ifa_name, ifname) != 0)
when considering value == (int)0 from netifaces.c:518
taking False path
519 continue;
520
521 /* Sometimes there are records without addresses (e.g. in the case of a
522 dial-up connection via ppp, which on Linux can have a link address
523 record with no actual address). We skip these as they aren't useful.
524 Thanks to Christian Kauhaus for reporting this issue. */
525 if (!addr->ifa_addr)
when treating unknown struct sockaddr * from netifaces.c:525 as non-NULL
taking False path
526 continue;
527
528 found = TRUE;
529
530 if (string_from_sockaddr (addr->ifa_addr, buffer, sizeof (buffer)) == 0)
when considering range: -0x80000000 <= value <= -1
taking False path
531 pyaddr = PyString_FromString (buffer);
532
533 if (string_from_sockaddr (addr->ifa_netmask, buffer, sizeof (buffer)) == 0)
when considering range: -0x80000000 <= value <= -1
taking False path
534 netmask = PyString_FromString (buffer);
535
536 if (string_from_sockaddr (addr->ifa_broadaddr, buffer, sizeof (buffer)) == 0)
when considering value == (int)0 from netifaces.c:536
taking True path
537 braddr = PyString_FromString (buffer);
when PyString_FromString() succeeds
538
539 PyObject *dict = PyDict_New();
when PyDict_New() succeeds
540
541 if (!dict) {
taking False path
542 Py_XDECREF (pyaddr);
543 Py_XDECREF (netmask);
544 Py_XDECREF (braddr);
545 Py_DECREF (result);
546 freeifaddrs (addrs);
547 return NULL;
548 }
549
550 if (pyaddr)
taking False path
551 PyDict_SetItemString (dict, "addr", pyaddr);
552 if (netmask)
taking False path
553 PyDict_SetItemString (dict, "netmask", netmask);
554
555 if (braddr) {
taking True path
556 if (addr->ifa_flags & (IFF_POINTOPOINT | IFF_LOOPBACK))
when considering value == (unsigned int)0 from netifaces.c:556
taking False path
557 PyDict_SetItemString (dict, "peer", braddr);
558 else
559 PyDict_SetItemString (dict, "broadcast", braddr);
when PyDict_SetItemString() succeeds
560 }
561
562 Py_XDECREF (pyaddr);
taking True path
563 Py_XDECREF (netmask);
taking True path
564 Py_XDECREF (braddr);
taking False path
taking True path
565
566 if (!add_to_family (result, addr->ifa_addr->sa_family, dict)) {
when treating unknown struct sockaddr * from netifaces.c:566 as non-NULL
when considering value == (int)0 from netifaces.c:566
taking True path
567 Py_DECREF (result);
when taking True path
568 freeifaddrs (addrs);
569 return NULL;
570 }
571 }
572
573 freeifaddrs (addrs);
574 #elif HAVE_SOCKET_IOCTLS
575
576 int sock = socket(AF_INET, SOCK_DGRAM, 0);
577
578 if (sock < 0) {
579 Py_DECREF (result);
580 PyErr_SetFromErrno (PyExc_OSError);
581 return NULL;
582 }
583
584 struct CNAME(ifreq) ifr;
585 PyObject *addr = NULL, *netmask = NULL, *braddr = NULL, *dstaddr = NULL;
586 int is_p2p = FALSE;
587 char buffer[256];
588
589 strncpy (ifr.CNAME(ifr_name), ifname, IFNAMSIZ);
590
591 #if HAVE_SIOCGIFHWADDR
592 if (ioctl (sock, SIOCGIFHWADDR, &ifr) == 0) {
593 found = TRUE;
594
595 if (string_from_sockaddr (ifr->CNAME(ifr_addr), buffer, sizeof (buffer)) == 0) {
596 PyObject *hwaddr = PyString_FromString (buffer);
597 PyObject *dict = PyDict_New ();
598 PyObject *list = PyList_New (1);
599 PyObject *family = PyInt_FromLong (AF_LINK);
600
601 if (!hwaddr || !dict || !list || !family) {
602 Py_XDECREF (hwaddr);
603 Py_XDECREF (dict);
604 Py_XDECREF (list)
605 Py_XDECREF (family);
606 Py_XDECREF (result);
607 close (sock);
608 return NULL;
609 }
610
611 PyDict_SetItemString (dict, "addr", hwaddr);
612 Py_DECREF (hwaddr);
613
614 PyList_SET_ITEM (list, 0, dict);
615
616 PyDict_SetItem (result, family, list);
617 Py_DECREF (family);
618 Py_DECREF (list);
619 }
620 }
621 #endif
622
623 #if HAVE_SIOCGIFADDR
624 #if HAVE_SIOCGLIFNUM
625 if (ioctl (sock, SIOCGLIFADDR, &ifr) == 0) {
626 #else
627 if (ioctl (sock, SIOCGIFADDR, &ifr) == 0) {
628 #endif
629 found = TRUE;
630
631 if (string_from_sockaddr ((struct sockaddr *)&ifr.CNAME(ifr_addr), buffer, sizeof (buffer)) == 0)
632 addr = PyString_FromString (buffer);
633 }
634 #endif
635
636 #if HAVE_SIOCGIFNETMASK
637 #if HAVE_SIOCGLIFNUM
638 if (ioctl (sock, SIOCGLIFNETMASK, &ifr) == 0) {
639 #else
640 if (ioctl (sock, SIOCGIFNETMASK, &ifr) == 0) {
641 #endif
642 found = TRUE;
643
644 if (string_from_sockaddr ((struct sockaddr *)&ifr.CNAME(ifr_addr), buffer, sizeof (buffer)) == 0)
645 netmask = PyString_FromString (buffer);
646 }
647 #endif
648
649 #if HAVE_SIOCGIFFLAGS
650 #if HAVE_SIOCGLIFNUM
651 if (ioctl (sock, SIOCGLIFFLAGS, &ifr) == 0) {
652 #else
653 if (ioctl (sock, SIOCGIFFLAGS, &ifr) == 0) {
654 #endif
655 found = TRUE;
656
657 if (ifr.CNAME(ifr_flags) & IFF_POINTOPOINT)
658 is_p2p = TRUE;
659 }
660 #endif
661
662 #if HAVE_SIOCGIFBRDADDR
663 #if HAVE_SIOCGLIFNUM
664 if (!is_p2p && ioctl (sock, SIOCGLIFBRDADDR, &ifr) == 0) {
665 #else
666 if (!is_p2p && ioctl (sock, SIOCGIFBRDADDR, &ifr) == 0) {
667 #endif
668 found = TRUE;
669
670 if (string_from_sockaddr ((struct sockaddr *)&ifr.CNAME(ifr_addr), buffer, sizeof (buffer)) == 0)
671 braddr = PyString_FromString (buffer);
672 }
673 #endif
674
675 #if HAVE_SIOCGIFDSTADDR
676 #if HAVE_SIOCGLIFNUM
677 if (is_p2p && ioctl (sock, SIOCGLIFBRDADDR, &ifr) == 0) {
678 #else
679 if (is_p2p && ioctl (sock, SIOCGIFBRDADDR, &ifr) == 0) {
680 #endif
681 found = TRUE;
682
683 if (string_from_sockaddr ((struct sockaddr *)&ifr.CNAME(ifr_addr), buffer, sizeof (buffer)) == 0)
684 dstaddr = PyString_FromString (buffer);
685 }
686 #endif
687
688 PyObject *dict = PyDict_New();
689
690 if (!dict) {
691 Py_XDECREF (addr);
692 Py_XDECREF (netmask);
693 Py_XDECREF (braddr);
694 Py_XDECREF (dstaddr);
695 Py_DECREF (result);
696 close (sock);
697 return NULL;
698 }
699
700 if (addr)
701 PyDict_SetItemString (dict, "addr", addr);
702 if (netmask)
703 PyDict_SetItemString (dict, "netmask", netmask);
704 if (braddr)
705 PyDict_SetItemString (dict, "broadcast", braddr);
706 if (dstaddr)
707 PyDict_SetItemString (dict, "peer", dstaddr);
708
709 Py_XDECREF (addr);
710 Py_XDECREF (netmask);
711 Py_XDECREF (braddr);
712 Py_XDECREF (dstaddr);
713
714 if (!PyDict_Size (dict))
715 Py_DECREF (dict);
716 else {
717 PyObject *list = PyList_New(1);
718
719 if (!list) {
720 Py_DECREF (dict);
721 Py_DECREF (result);
722 close (sock);
723 return NULL;
724 }
725
726 PyList_SET_ITEM (list, 0, dict);
727
728 PyObject *family = PyInt_FromLong (AF_INET);
729 if (!family) {
730 Py_DECREF (result);
731 Py_DECREF (list);
732 close (sock);
733 return NULL;
734 }
735
736 PyDict_SetItem (result, family, list);
737 Py_DECREF (family);
738 Py_DECREF (list);
739 }
740
741 close (sock);
742
743 #endif /* HAVE_SOCKET_IOCTLS */
744
745 if (found)
746 return result;
747 else {
748 Py_DECREF (result);
749 PyErr_SetString (PyExc_ValueError,
750 "You must specify a valid interface name.");
751 return NULL;
752 }
753 }
returning (PyObject*)NULL without setting an exception
found 3 similar trace(s) to this