summaryrefslogtreecommitdiff
path: root/psutil/_psutil_posix.c
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2016-10-25 00:15:37 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2016-10-25 00:15:37 +0200
commit0c233ed50778efb61dfb6df2a07b5d8a820cdd84 (patch)
tree5385bccf0c1b3dd27a12f65f92141916e70ddfff /psutil/_psutil_posix.c
parent3a9cfd3931f9d358d3aa414d3f1bcda198435b53 (diff)
downloadpsutil-0c233ed50778efb61dfb6df2a07b5d8a820cdd84.tar.gz
osx/bsd: separate IFFLAGS function
Diffstat (limited to 'psutil/_psutil_posix.c')
-rw-r--r--psutil/_psutil_posix.c26
1 files changed, 5 insertions, 21 deletions
diff --git a/psutil/_psutil_posix.c b/psutil/_psutil_posix.c
index 9087443f..afe4fdac 100644
--- a/psutil/_psutil_posix.c
+++ b/psutil/_psutil_posix.c
@@ -319,8 +319,7 @@ error:
/*
- * net_if_stats() implementation. This is here because it is common
- * to both OSX and FreeBSD and I didn't know where else to put it.
+ * net_if_stats() OSX/BSD implementation.
*/
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__NetBSD__)
@@ -470,7 +469,7 @@ int psutil_get_nic_speed(int ifm_active) {
* http://www.i-scream.org/libstatgrab/
*/
static PyObject *
-psutil_net_if_stats(PyObject *self, PyObject *args) {
+psutil_net_if_duplex_speed(PyObject *self, PyObject *args) {
char *nic_name;
int sock = 0;
int ret;
@@ -479,8 +478,6 @@ psutil_net_if_stats(PyObject *self, PyObject *args) {
struct ifreq ifr;
struct ifmediareq ifmed;
- PyObject *py_is_up = NULL;
-
if (! PyArg_ParseTuple(args, "s", &nic_name))
return NULL;
@@ -489,16 +486,6 @@ psutil_net_if_stats(PyObject *self, PyObject *args) {
goto error;
strncpy(ifr.ifr_name, nic_name, sizeof(ifr.ifr_name));
- // is up?
- ret = ioctl(sock, SIOCGIFFLAGS, &ifr);
- if (ret == -1)
- goto error;
- if ((ifr.ifr_flags & IFF_UP) != 0)
- py_is_up = Py_True;
- else
- py_is_up = Py_False;
- Py_INCREF(py_is_up);
-
// speed / duplex
memset(&ifmed, 0, sizeof(struct ifmediareq));
strlcpy(ifmed.ifm_name, nic_name, sizeof(ifmed.ifm_name));
@@ -518,18 +505,15 @@ psutil_net_if_stats(PyObject *self, PyObject *args) {
}
close(sock);
- Py_DECREF(py_is_up);
-
- return Py_BuildValue("[Oii]", py_is_up, duplex, speed);
+ return Py_BuildValue("[ii]", duplex, speed);
error:
- Py_XDECREF(py_is_up);
if (sock != 0)
close(sock);
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
-#endif // net_if_stats() implementation
+#endif // net_if_stats() OSX/BSD implementation
/*
@@ -548,7 +532,7 @@ PsutilMethods[] = {
{"net_if_flags", psutil_net_if_flags, METH_VARARGS,
"Retrieve NIC flags"},
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__NetBSD__)
- {"net_if_stats", psutil_net_if_stats, METH_VARARGS,
+ {"net_if_duplex_speed", psutil_net_if_duplex_speed, METH_VARARGS,
"Return NIC stats."},
#endif
{NULL, NULL, 0, NULL}