summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola' <g.rodola@gmail.com>2015-08-26 10:55:47 +0200
committerGiampaolo Rodola' <g.rodola@gmail.com>2015-08-26 10:55:47 +0200
commitd8416fbe84b039564920fc896c3fb163b205091d (patch)
tree01b03031835113c52124bd8d607d191bf38ec7b3
parent0487bcf74aba7832e08eb04ca1df8d4135c49efa (diff)
parent1c3a695ddb1237b3af51d96d59862c06af48daca (diff)
downloadpsutil-d8416fbe84b039564920fc896c3fb163b205091d.tar.gz
Merge pull request #670 from sk6249/master
Fix bug: incorrect network interface returned by net_io_counters(True…
-rw-r--r--psutil/_psutil_windows.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index eba974b7..d3faf50e 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -138,7 +138,6 @@ typedef struct _MIB_UDP6TABLE_OWNER_PID {
MIB_UDP6ROW_OWNER_PID table[ANY_SIZE];
} MIB_UDP6TABLE_OWNER_PID, *PMIB_UDP6TABLE_OWNER_PID;
-
PIP_ADAPTER_ADDRESSES
psutil_get_nic_addresses() {
// allocate a 15 KB buffer to start with
@@ -2159,7 +2158,6 @@ return_:
*/
static PyObject *
psutil_net_io_counters(PyObject *self, PyObject *args) {
- char ifname[MAX_PATH];
DWORD dwRetVal = 0;
MIB_IFROW *pIfRow = NULL;
PIP_ADAPTER_ADDRESSES pAddresses = NULL;
@@ -2205,9 +2203,8 @@ psutil_net_io_counters(PyObject *self, PyObject *args) {
if (!py_nic_info)
goto error;
- sprintf_s(ifname, MAX_PATH, "%wS", pCurrAddresses->FriendlyName);
- py_nic_name = PyUnicode_Decode(
- ifname, _tcslen(ifname), Py_FileSystemDefaultEncoding, "replace");
+ py_nic_name = PyUnicode_FromWideChar(pCurrAddresses->FriendlyName,
+ wcslen(pCurrAddresses->FriendlyName));
if (py_nic_name == NULL)
goto error;
@@ -2844,7 +2841,6 @@ psutil_net_if_addrs(PyObject *self, PyObject *args) {
PCTSTR intRet;
char *ptr;
char buff[100];
- char ifname[MAX_PATH];
DWORD bufflen = 100;
PIP_ADAPTER_ADDRESSES pAddresses = NULL;
PIP_ADAPTER_ADDRESSES pCurrAddresses = NULL;
@@ -2854,6 +2850,7 @@ psutil_net_if_addrs(PyObject *self, PyObject *args) {
PyObject *py_tuple = NULL;
PyObject *py_address = NULL;
PyObject *py_mac_address = NULL;
+ PyObject *py_nic_name = NULL;
if (py_retlist == NULL)
return NULL;
@@ -2865,7 +2862,12 @@ psutil_net_if_addrs(PyObject *self, PyObject *args) {
while (pCurrAddresses) {
pUnicast = pCurrAddresses->FirstUnicastAddress;
- sprintf_s(ifname, MAX_PATH, "%wS", pCurrAddresses->FriendlyName);
+
+ py_nic_name = NULL;
+ py_nic_name = PyUnicode_FromWideChar(pCurrAddresses->FriendlyName,
+ wcslen(pCurrAddresses->FriendlyName));
+ if (py_nic_name == NULL)
+ goto error;
// MAC address
if (pCurrAddresses->PhysicalAddressLength != 0) {
@@ -2896,8 +2898,8 @@ psutil_net_if_addrs(PyObject *self, PyObject *args) {
Py_INCREF(Py_None);
Py_INCREF(Py_None);
py_tuple = Py_BuildValue(
- "(siOOOO)",
- ifname,
+ "(OiOOOO)",
+ py_nic_name,
-1, // this will be converted later to AF_LINK
py_mac_address,
Py_None, // netmask (not supported)
@@ -2950,8 +2952,8 @@ psutil_net_if_addrs(PyObject *self, PyObject *args) {
Py_INCREF(Py_None);
Py_INCREF(Py_None);
py_tuple = Py_BuildValue(
- "(siOOOO)",
- ifname,
+ "(OiOOOO)",
+ py_nic_name,
family,
py_address,
Py_None, // netmask (not supported)
@@ -2969,7 +2971,7 @@ psutil_net_if_addrs(PyObject *self, PyObject *args) {
pUnicast = pUnicast->Next;
}
}
-
+ Py_DECREF(py_nic_name);
pCurrAddresses = pCurrAddresses->Next;
}
@@ -2982,6 +2984,7 @@ error:
Py_DECREF(py_retlist);
Py_XDECREF(py_tuple);
Py_XDECREF(py_address);
+ Py_XDECREF(py_nic_name);
return NULL;
}