Skip to content

Commit

Permalink
workaround for windows compiler without inet_ntop
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Morgner committed Aug 21, 2015
1 parent f66c783 commit 13307b9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
9 changes: 9 additions & 0 deletions virtualsmartcard/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ AC_TYPE_SIZE_T
AC_TYPE_UINT16_T
AC_CHECK_DECLS([SO_NOSIGPIPE], [], [], [#include <sys/socket.h>])
AC_CHECK_DECLS([MSG_NOSIGNAL], [], [], [#include <sys/socket.h>])
if test "${WIN32}" = "yes"
then
saved_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS -D_WIN32_WINNT=0x0600"
AC_CHECK_DECLS([inet_ntop], [], [], [#include <ws2tcpip.h>])
CPPFLAGS="$saved_CPPFLAGS"
else
AC_CHECK_DECLS([inet_ntop], [], [], [#include <arpa/inet.h>])
fi

# Checks for library functions.
AC_FUNC_MALLOC
Expand Down
2 changes: 1 addition & 1 deletion virtualsmartcard/src/vpcd-config/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
EXTRA_DIST = qransi.c
EXTRA_DIST = qransi.c inet_ntop.c

bin_PROGRAMS = vpcd-config

Expand Down
15 changes: 15 additions & 0 deletions virtualsmartcard/src/vpcd-config/inet_ntop.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* Taken from https://memset.wordpress.com/2010/10/09/inet_ntop-for-win32/ */

const char* inet_ntop(int af, const void* src, char* dst, int cnt){

struct sockaddr_in srcaddr;

memset(&srcaddr, 0, sizeof(struct sockaddr_in));
memcpy(&(srcaddr.sin_addr), src, sizeof(srcaddr.sin_addr));

srcaddr.sin_family = af;
if (WSAAddressToString((struct sockaddr*) &srcaddr, sizeof(struct sockaddr_in), 0, dst, (LPDWORD) &cnt) != 0) {
return NULL;
}
return dst;
}
6 changes: 6 additions & 0 deletions virtualsmartcard/src/vpcd-config/local-ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
* Use getsockname and a udp connection
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include<stdio.h> //printf
#include<string.h> //memset
#include<errno.h> //errno
#include<string.h>
#ifdef _WIN32
#include<winsock2.h>
#include<ws2tcpip.h>
#if defined(HAVE_DECL_INET_NTOP) && ! HAVE_DECL_INET_NTOP
#include"inet_ntop.c"
#endif
#define close(s) closesocket(s)
#else
#include<sys/socket.h> //socket
Expand Down

0 comments on commit 13307b9

Please sign in to comment.