summaryrefslogtreecommitdiff
path: root/psutil/_psutil_posix.c
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2015-08-05 02:54:04 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2015-08-05 02:54:04 +0200
commit725dfb4faa3240fe5730e5abc72dfbb74efe66e9 (patch)
tree1cb94b0d366f5c68e9000a8dc1d9639965b802ce /psutil/_psutil_posix.c
parent11969913e6718cb7c40ed31be3a3c025815f0931 (diff)
downloadpsutil-663-ptp-ifaces.tar.gz
#663: ptp addresses linux implementation663-ptp-ifaces
Diffstat (limited to 'psutil/_psutil_posix.c')
-rw-r--r--psutil/_psutil_posix.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/psutil/_psutil_posix.c b/psutil/_psutil_posix.c
index 183dab0e..5967df0c 100644
--- a/psutil/_psutil_posix.c
+++ b/psutil/_psutil_posix.c
@@ -17,6 +17,7 @@
#ifdef __linux
#include <netdb.h>
#include <linux/if_packet.h>
+#include <linux/if.h>
#endif // end linux
#if defined(__FreeBSD__) || defined(__APPLE__)
@@ -163,6 +164,7 @@ psutil_net_if_addrs(PyObject* self, PyObject* args)
PyObject *py_address = NULL;
PyObject *py_netmask = NULL;
PyObject *py_broadcast = NULL;
+ PyObject *py_ptp = NULL;
if (py_retlist == NULL)
return NULL;
@@ -185,20 +187,41 @@ psutil_net_if_addrs(PyObject* self, PyObject* args)
py_netmask = psutil_convert_ipaddr(ifa->ifa_netmask, family);
if (py_netmask == NULL)
goto error;
+
#ifdef __linux
- py_broadcast = psutil_convert_ipaddr(ifa->ifa_ifu.ifu_broadaddr, family);
+ if (ifa->ifa_flags & IFF_BROADCAST) {
+ py_broadcast = psutil_convert_ipaddr(ifa->ifa_broadaddr, family);
+ Py_INCREF(Py_None);
+ py_ptp = Py_None;
+ }
+ else if (ifa->ifa_flags & IFF_POINTOPOINT) {
+ py_ptp = psutil_convert_ipaddr(ifa->ifa_dstaddr, family);
+ Py_INCREF(Py_None);
+ py_broadcast = Py_None;
+ }
+ else {
+ Py_INCREF(Py_None);
+ Py_INCREF(Py_None);
+ py_broadcast = Py_None;
+ py_ptp = Py_None;
+ }
#else
+ // TODO
py_broadcast = psutil_convert_ipaddr(ifa->ifa_broadaddr, family);
+ Py_INCREF(Py_None);
+ py_ptp = Py_None;
#endif
- if (py_broadcast == NULL)
+
+ if ((py_broadcast == NULL) || (py_ptp == NULL))
goto error;
py_tuple = Py_BuildValue(
- "(siOOO)",
+ "(siOOOO)",
ifa->ifa_name,
family,
py_address,
py_netmask,
- py_broadcast
+ py_broadcast,
+ py_ptp
);
if (! py_tuple)
@@ -209,6 +232,7 @@ psutil_net_if_addrs(PyObject* self, PyObject* args)
Py_DECREF(py_address);
Py_DECREF(py_netmask);
Py_DECREF(py_broadcast);
+ Py_DECREF(py_ptp);
}
freeifaddrs(ifaddr);
@@ -222,6 +246,7 @@ error:
Py_XDECREF(py_address);
Py_XDECREF(py_netmask);
Py_XDECREF(py_broadcast);
+ Py_XDECREF(py_ptp);
return NULL;
}