Skip to content

Commit

Permalink
Implement inet_ntop to support Windows XP
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjefftang committed Jun 4, 2015
1 parent 931432d commit 7f06236
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected]
Expand Down
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down
1 change: 1 addition & 0 deletions psutil/_psutil_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
24 changes: 24 additions & 0 deletions psutil/arch/windows/inet_ntop.c
Original file line number Diff line number Diff line change
@@ -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;
}
10 changes: 10 additions & 0 deletions psutil/arch/windows/inet_ntop.h
Original file line number Diff line number Diff line change
@@ -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
);
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def get_winver():
'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,
Expand Down

0 comments on commit 7f06236

Please sign in to comment.