Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement inet_ntop to support Windows XP #616

Merged
merged 1 commit into from
Jun 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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