diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2019-02-20 04:42:57 -0800 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2019-02-20 04:42:57 -0800 |
commit | fd48e950c5f1aa41ad456ae2fe2ee6f377094481 (patch) | |
tree | 949d42506ffc6a537a63ccdfdaadcb2430b10734 | |
parent | 850e6a8fc3d65e99edf43751dae4886f68f4daab (diff) | |
download | psutil-fd48e950c5f1aa41ad456ae2fe2ee6f377094481.tar.gz |
port GetExtendedTcpTable
-rw-r--r-- | psutil/_psutil_windows.c | 11 | ||||
-rw-r--r-- | psutil/arch/windows/global.c | 2 | ||||
-rw-r--r-- | psutil/arch/windows/global.h | 10 |
3 files changed, 9 insertions, 14 deletions
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c index 0b2c9cd0..f99b88cc 100644 --- a/psutil/_psutil_windows.c +++ b/psutil/_psutil_windows.c @@ -1614,7 +1614,6 @@ psutil_net_connections(PyObject *self, PyObject *args) { static long null_address[4] = { 0, 0, 0, 0 }; unsigned long pid; int pid_return; - _GetExtendedTcpTable getExtendedTcpTable; _GetExtendedUdpTable getExtendedUdpTable; PVOID table = NULL; DWORD tableSize; @@ -1639,10 +1638,6 @@ psutil_net_connections(PyObject *self, PyObject *args) { PyObject *_SOCK_DGRAM = PyLong_FromLong((long)SOCK_DGRAM); // Import some functions. - getExtendedTcpTable = psutil_GetProcAddressFromLib( - "iphlpapi.dll", "GetExtendedTcpTable"); - if (getExtendedTcpTable == NULL) - goto error; getExtendedUdpTable = psutil_GetProcAddressFromLib( "iphlpapi.dll", "GetExtendedUdpTable"); if (getExtendedUdpTable == NULL) @@ -1669,7 +1664,7 @@ psutil_net_connections(PyObject *self, PyObject *args) { } } - if ((getExtendedTcpTable == NULL) || (getExtendedUdpTable == NULL)) { + if (getExtendedUdpTable == NULL) { PyErr_SetString(PyExc_NotImplementedError, "feature not supported on this Windows version"); _psutil_conn_decref_objs(); @@ -1693,7 +1688,7 @@ psutil_net_connections(PyObject *self, PyObject *args) { py_addr_tuple_remote = NULL; tableSize = 0; - error = __GetExtendedTcpTable(getExtendedTcpTable, + error = __GetExtendedTcpTable(psutil_GetExtendedTcpTable, AF_INET, &table, &tableSize); if (error == ERROR_NOT_ENOUGH_MEMORY) { PyErr_NoMemory(); @@ -1790,7 +1785,7 @@ psutil_net_connections(PyObject *self, PyObject *args) { py_addr_tuple_remote = NULL; tableSize = 0; - error = __GetExtendedTcpTable(getExtendedTcpTable, + error = __GetExtendedTcpTable(psutil_GetExtendedTcpTable, AF_INET6, &table, &tableSize); if (error == ERROR_NOT_ENOUGH_MEMORY) { PyErr_NoMemory(); diff --git a/psutil/arch/windows/global.c b/psutil/arch/windows/global.c index d7e92737..d34aade7 100644 --- a/psutil/arch/windows/global.c +++ b/psutil/arch/windows/global.c @@ -82,13 +82,13 @@ psutil_load_globals() { "ntdll.dll", "RtlIpv6AddressToStringA"); if (! psutil_rtlIpv6AddressToStringA) return 1; -/* psutil_GetExtendedTcpTable = ps_GetProcAddressFromLib( "iphlpapi.dll", "GetExtendedTcpTable"); if (! psutil_GetExtendedTcpTable) return 1; +/* psutil_GetExtendedUdpTable = ps_GetProcAddressFromLib( "iphlpapi.dll", "GetExtendedUdpTable"); if (! psutil_GetExtendedUdpTable) diff --git a/psutil/arch/windows/global.h b/psutil/arch/windows/global.h index 6e4fa143..341e3a27 100644 --- a/psutil/arch/windows/global.h +++ b/psutil/arch/windows/global.h @@ -10,6 +10,8 @@ typedef DWORD (_stdcall * NTQSI_PROC) (int, PVOID, ULONG, PULONG); typedef PSTR (NTAPI * _RtlIpv4AddressToStringA)(struct in_addr *, PSTR); typedef PSTR (NTAPI * _RtlIpv6AddressToStringA)(struct in6_addr *, PSTR); +typedef DWORD (WINAPI * _GetExtendedTcpTable)(PVOID, PDWORD, BOOL, ULONG, + TCP_TABLE_CLASS, ULONG); // probably unnecessary? /* @@ -19,8 +21,6 @@ typedef PSTR (NTAPI * _RtlIpv6AddressToStringA)(struct in6_addr *, PSTR); typedef DWORD (CALLBACK *_GetActiveProcessorCount)(WORD); typedef ULONGLONG (CALLBACK *_GetTickCount64)(void); -typedef DWORD (WINAPI * _GetExtendedTcpTable)(PVOID, PDWORD, BOOL, ULONG, - TCP_TABLE_CLASS, ULONG); typedef DWORD (WINAPI * _GetExtendedUdpTable)(PVOID, PDWORD, BOOL, ULONG, UDP_TABLE_CLASS, ULONG); @@ -31,9 +31,6 @@ _GetActiveProcessorCount \ _GetTickCount64 \ psutil_GetTickCount64; -_GetExtendedTcpTable \ - psutil_GetExtendedTcpTable; - _GetExtendedUdpTable \ psutil_GetExtendedUdpTable; */ @@ -56,5 +53,8 @@ _RtlIpv4AddressToStringA \ _RtlIpv6AddressToStringA \ psutil_rtlIpv6AddressToStringA; +_GetExtendedTcpTable \ + psutil_GetExtendedTcpTable; + int psutil_load_globals(); |