1818#include <tchar.h>
1919#include <tlhelp32.h>
2020#include <winsock2.h>
21+ #if (_WIN32_WINNT >= 0x0600 )
2122#include <ws2tcpip.h>
23+ #endif
2224#include <iphlpapi.h>
2325#include <wtsapi32.h>
2426#include <Winsvc.h>
@@ -84,6 +86,24 @@ typedef struct _DISK_PERFORMANCE_WIN_2008 {
8486} DISK_PERFORMANCE_WIN_2008 ;
8587
8688// --- network connections mingw32 support
89+ #ifndef _IPRTRMIB_H
90+ typedef struct _MIB_TCP6ROW_OWNER_PID {
91+ UCHAR ucLocalAddr [16 ];
92+ DWORD dwLocalScopeId ;
93+ DWORD dwLocalPort ;
94+ UCHAR ucRemoteAddr [16 ];
95+ DWORD dwRemoteScopeId ;
96+ DWORD dwRemotePort ;
97+ DWORD dwState ;
98+ DWORD dwOwningPid ;
99+ } MIB_TCP6ROW_OWNER_PID , * PMIB_TCP6ROW_OWNER_PID ;
100+
101+ typedef struct _MIB_TCP6TABLE_OWNER_PID {
102+ DWORD dwNumEntries ;
103+ MIB_TCP6ROW_OWNER_PID table [ANY_SIZE ];
104+ } MIB_TCP6TABLE_OWNER_PID , * PMIB_TCP6TABLE_OWNER_PID ;
105+ #endif
106+
87107#ifndef __IPHLPAPI_H__
88108typedef struct in6_addr {
89109 union {
@@ -110,6 +130,20 @@ typedef struct _MIB_UDPTABLE_OWNER_PID {
110130} MIB_UDPTABLE_OWNER_PID , * PMIB_UDPTABLE_OWNER_PID ;
111131#endif
112132
133+ #if (_WIN32_WINNT < 0x0600 )
134+ typedef struct _MIB_UDP6ROW_OWNER_PID {
135+ UCHAR ucLocalAddr [16 ];
136+ DWORD dwLocalScopeId ;
137+ DWORD dwLocalPort ;
138+ DWORD dwOwningPid ;
139+ } MIB_UDP6ROW_OWNER_PID , * PMIB_UDP6ROW_OWNER_PID ;
140+
141+ typedef struct _MIB_UDP6TABLE_OWNER_PID {
142+ DWORD dwNumEntries ;
143+ MIB_UDP6ROW_OWNER_PID table [ANY_SIZE ];
144+ } MIB_UDP6TABLE_OWNER_PID , * PMIB_UDP6TABLE_OWNER_PID ;
145+ #endif
146+
113147PIP_ADAPTER_ADDRESSES
114148psutil_get_nic_addresses () {
115149 // allocate a 15 KB buffer to start with
@@ -1606,7 +1640,6 @@ psutil_net_connections(PyObject *self, PyObject *args) {
16061640 }
16071641
16081642 // TCP IPv6
1609-
16101643 if ((PySequence_Contains (py_af_filter , _AF_INET6 ) == 1 ) &&
16111644 (PySequence_Contains (py_type_filter , _SOCK_STREAM ) == 1 ))
16121645 {
@@ -2138,7 +2171,12 @@ psutil_disk_usage(PyObject *self, PyObject *args) {
21382171static PyObject *
21392172psutil_net_io_counters (PyObject * self , PyObject * args ) {
21402173 DWORD dwRetVal = 0 ;
2174+ #if (_WIN32_WINNT >= 0x0600 )
21412175 MIB_IF_ROW2 * pIfRow = NULL ;
2176+ #endif
2177+ #if (_WIN32_WINNT < 0x0600 )
2178+ MIB_IFROW * pIfRow = NULL ;
2179+ #endif
21422180 PIP_ADAPTER_ADDRESSES pAddresses = NULL ;
21432181 PIP_ADAPTER_ADDRESSES pCurrAddresses = NULL ;
21442182 PyObject * py_retdict = PyDict_New ();
@@ -2155,21 +2193,35 @@ psutil_net_io_counters(PyObject *self, PyObject *args) {
21552193 while (pCurrAddresses ) {
21562194 py_nic_name = NULL ;
21572195 py_nic_info = NULL ;
2196+ #if (_WIN32_WINNT >= 0x0600 )
21582197 pIfRow = (MIB_IF_ROW2 * ) malloc (sizeof (MIB_IF_ROW2 ));
2198+ #endif
2199+ #if (_WIN32_WINNT < 0x0600 )
2200+ pIfRow = (MIB_IFROW * ) malloc (sizeof (MIB_IFROW ));
2201+ #endif
21592202
21602203 if (pIfRow == NULL ) {
21612204 PyErr_NoMemory ();
21622205 goto error ;
21632206 }
2207+ #if (_WIN32_WINNT >= 0x0600 )
21642208 SecureZeroMemory ((PVOID )pIfRow , sizeof (MIB_IF_ROW2 ));
2209+ #endif
21652210
2211+ #if (_WIN32_WINNT >= 0x0600 )
21662212 pIfRow -> InterfaceIndex = pCurrAddresses -> IfIndex ;
21672213 dwRetVal = GetIfEntry2 (pIfRow );
2214+ #endif
2215+ #if (_WIN32_WINNT < 0x0600 )
2216+ pIfRow -> dwIndex = pCurrAddresses -> IfIndex ;
2217+ dwRetVal = GetIfEntry (pIfRow );
2218+ #endif
21682219 if (dwRetVal != NO_ERROR ) {
2169- PyErr_SetString (PyExc_RuntimeError , "GetIfEntry() failed." );
2220+ PyErr_SetString (PyExc_RuntimeError , "GetIfEntry() or GetIfEntry2() failed." );
21702221 goto error ;
21712222 }
21722223
2224+ #if (_WIN32_WINNT >= 0x0600 )
21732225 py_nic_info = Py_BuildValue ("(KKKKKKKK)" ,
21742226 pIfRow -> OutOctets ,
21752227 pIfRow -> InOctets ,
@@ -2179,6 +2231,19 @@ psutil_net_io_counters(PyObject *self, PyObject *args) {
21792231 pIfRow -> OutErrors ,
21802232 pIfRow -> InDiscards ,
21812233 pIfRow -> OutDiscards );
2234+ #endif
2235+ #if (_WIN32_WINNT < 0x0600 )
2236+ py_nic_info = Py_BuildValue ("(kkkkkkkk)" ,
2237+ pIfRow -> dwOutOctets ,
2238+ pIfRow -> dwInOctets ,
2239+ pIfRow -> dwOutUcastPkts ,
2240+ pIfRow -> dwInUcastPkts ,
2241+ pIfRow -> dwInErrors ,
2242+ pIfRow -> dwOutErrors ,
2243+ pIfRow -> dwInDiscards ,
2244+ pIfRow -> dwOutDiscards );
2245+ #endif
2246+
21822247 if (!py_nic_info )
21832248 goto error ;
21842249
0 commit comments