diff options
author | Jeff Tang <mrjefftang@users.noreply.github.com> | 2015-04-13 16:18:38 -0400 |
---|---|---|
committer | Jeff Tang <mrjefftang@users.noreply.github.com> | 2015-06-04 10:53:01 -0400 |
commit | 7f062361ec6b545ac11bff1ef405c42dcffe36f0 (patch) | |
tree | f4e1f6daaaf7e1155ef8a7eb4ae1947fa73cbde6 | |
parent | 931432d83e203e757d0c6668c02386d7f762ea66 (diff) | |
download | psutil-7f062361ec6b545ac11bff1ef405c42dcffe36f0.tar.gz |
Implement inet_ntop to support Windows XP
-rw-r--r-- | CREDITS | 2 | ||||
-rw-r--r-- | HISTORY.rst | 1 | ||||
-rw-r--r-- | psutil/_psutil_windows.c | 1 | ||||
-rw-r--r-- | psutil/arch/windows/inet_ntop.c | 24 | ||||
-rw-r--r-- | psutil/arch/windows/inet_ntop.h | 10 | ||||
-rw-r--r-- | setup.py | 1 |
6 files changed, 38 insertions, 1 deletions
@@ -255,7 +255,7 @@ I: 492 N: Jeff Tang W: https://github.com/mrjefftang -I: 340, 529 +I: 340, 529, 616 N: Yaolong Huang E: airekans@gmail.com diff --git a/HISTORY.rst b/HISTORY.rst index faeb0c9e..8c026524 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -22,6 +22,7 @@ Bug tracker at https://github.com/giampaolo/psutil/issues when running as a limited user. - #602: pre-commit GIT hook. - #629: enhanced support for py.test and nose test discovery and tests run. +- #616: [Windows] Add inet_ntop function for Windows XP. **Bug fixes** diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c index 670be24c..f789e03d 100644 --- a/psutil/_psutil_windows.c +++ b/psutil/_psutil_windows.c @@ -31,6 +31,7 @@ #include "arch/windows/process_info.h" #include "arch/windows/process_handles.h" #include "arch/windows/ntextapi.h" +#include "arch/windows/inet_ntop.h" #ifdef __MINGW32__ #include "arch/windows/glpi.h" diff --git a/psutil/arch/windows/inet_ntop.c b/psutil/arch/windows/inet_ntop.c new file mode 100644 index 00000000..39b05dfb --- /dev/null +++ b/psutil/arch/windows/inet_ntop.c @@ -0,0 +1,24 @@ +#include "inet_ntop.h" + +// From: https://memset.wordpress.com/2010/10/09/inet_ntop-for-win32/ +PCSTR +WSAAPI +inet_ntop( + __in INT Family, + __in PVOID pAddr, + __out_ecount(StringBufSize) PSTR pStringBuf, + __in size_t StringBufSize + ) +{ + struct sockaddr_in srcaddr; + + memset(&srcaddr, 0, sizeof(struct sockaddr_in)); + memcpy(&(srcaddr.sin_addr), pAddr, sizeof(srcaddr.sin_addr)); + + srcaddr.sin_family = Family; + if (WSAAddressToString((struct sockaddr*) &srcaddr, sizeof(struct sockaddr_in), 0, pStringBuf, (LPDWORD) &StringBufSize) != 0) { + DWORD rv = WSAGetLastError(); + return NULL; + } + return pStringBuf; +}
\ No newline at end of file diff --git a/psutil/arch/windows/inet_ntop.h b/psutil/arch/windows/inet_ntop.h new file mode 100644 index 00000000..e9b83585 --- /dev/null +++ b/psutil/arch/windows/inet_ntop.h @@ -0,0 +1,10 @@ +#include <ws2tcpip.h> + +PCSTR +WSAAPI +inet_ntop( + __in INT Family, + __in PVOID pAddr, + __out_ecount(StringBufSize) PSTR pStringBuf, + __in size_t StringBufSize + );
\ No newline at end of file @@ -70,6 +70,7 @@ if sys.platform.startswith("win32"): 'psutil/arch/windows/process_info.c', 'psutil/arch/windows/process_handles.c', 'psutil/arch/windows/security.c', + 'psutil/arch/windows/inet_ntop.c', ], define_macros=[ VERSION_MACRO, |