From 04d26c376c7e8e3ff7f314942fd245d5fff150a0 Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Fri, 12 Sep 2014 07:58:44 +0200 Subject: [PATCH] vpcd-config: added scripts for windows builds --- virtualsmartcard/src/vpcd-config/local-ip.c | 17 ++++- .../src/vpcd-config/vpcd-config.c | 46 +++++++++--- .../win32/vpcd-config/vpcd-config.sln | 20 +++++ .../win32/vpcd-config/vpcd-config.vcxproj | 74 +++++++++++++++++++ 4 files changed, 146 insertions(+), 11 deletions(-) create mode 100644 virtualsmartcard/win32/vpcd-config/vpcd-config.sln create mode 100644 virtualsmartcard/win32/vpcd-config/vpcd-config.vcxproj diff --git a/virtualsmartcard/src/vpcd-config/local-ip.c b/virtualsmartcard/src/vpcd-config/local-ip.c index 57d7d76..6541490 100644 --- a/virtualsmartcard/src/vpcd-config/local-ip.c +++ b/virtualsmartcard/src/vpcd-config/local-ip.c @@ -8,10 +8,17 @@ #include //printf #include //memset #include //errno +#include +#ifdef _WIN32 +#include +#include +#define close(s) closesocket(s) +#else #include //socket #include //sockaddr_in #include //getsockname #include //close +#endif #define ERROR_STRING "Unable to guess local IP address" @@ -23,7 +30,12 @@ const char *local_ip (void) socklen_t namelen = sizeof(name); struct sockaddr_in serv; static char buffer[20]; - int sock = socket ( AF_INET, SOCK_DGRAM, 0); + int sock = -1; +#ifdef _WIN32 + WSADATA wsaData; + WSAStartup(MAKEWORD(2, 2), &wsaData); +#endif + sock = socket ( AF_INET, SOCK_DGRAM, 0); if(sock < 0) { perror(ERROR_STRING); return NULL; @@ -42,6 +54,9 @@ const char *local_ip (void) ip = buffer; err: +#ifdef _WIN32 + WSACleanup(); +#endif if (!ip) printf("%s: %s\n" , ERROR_STRING, strerror(errno)); if (sock > 0) diff --git a/virtualsmartcard/src/vpcd-config/vpcd-config.c b/virtualsmartcard/src/vpcd-config/vpcd-config.c index 1fcc952..c6f352c 100644 --- a/virtualsmartcard/src/vpcd-config/vpcd-config.c +++ b/virtualsmartcard/src/vpcd-config/vpcd-config.c @@ -19,17 +19,23 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif - +#include #include "vpcd.h" extern const char *local_ip (void); +#ifdef _WIN32 +#define VICC_MAX_SLOTS 1 +#include +#include +#else /* pcscd allows at most 16 readers. We will use 10. * See PCSCLITE_MAX_READERS_CONTEXTS in pcsclite.h */ #include #define VICC_MAX_SLOTS \ - (PCSCLITE_MAX_READERS_CONTEXTS > 6 ? \ - PCSCLITE_MAX_READERS_CONTEXTS-6 : 1) + (PCSCLITE_MAX_READERS_CONTEXTS > 6 ? \ + PCSCLITE_MAX_READERS_CONTEXTS-6 : 1) +#endif #define ERROR_STRING "Unable to guess local IP address" @@ -46,14 +52,33 @@ void print_qrcode(const char *uri) #else +#define QR_SERVICE_URL "https://api.qrserver.com/v1/create-qr-code/?data=" + +#ifdef _WIN32 + +#define IE_PATH "\"C:\\Program Files\\Internet Explorer\\IExplore.exe\" " void print_qrcode(const char *uri) { - printf("https://api.qrserver.com/v1/create-qr-code/?data=%s\n", uri); + char command[200]; + memset(command, 0, sizeof command); + strcpy(command, IE_PATH); + strcat(command, QR_SERVICE_URL); + strcat(command, uri); + system(command); } + +#else + +void print_qrcode(const char *uri) +{ + printf("%s%s\n", QR_SERVICE_URL, uri); +} + +#endif + #endif - int main ( int argc , char *argv[] ) { char slot; @@ -65,16 +90,17 @@ int main ( int argc , char *argv[] ) if (!ip) goto err; - for (slot = 1; slot < VICC_MAX_SLOTS; slot++) { - port = VPCDPORT+slot-1; + for (slot = 0; slot < VICC_MAX_SLOTS; slot++) { + port = VPCDPORT+slot; printf("VPCD hostname: %s\n", ip); printf("VPCD port: %d\n", port); - printf("On your NFC phone with the Remote Smart Card Reader app scan this code:\n", port); + printf("On your NFC phone with the Remote Smart Card Reader app scan this code:\n"); sprintf(uri, "vpcd://%s:%d", ip, port); print_qrcode(uri); - puts(""); + if (slot < VICC_MAX_SLOTS-1) + puts(""); } - + fail = 0; err: diff --git a/virtualsmartcard/win32/vpcd-config/vpcd-config.sln b/virtualsmartcard/win32/vpcd-config/vpcd-config.sln new file mode 100644 index 0000000..edb056c --- /dev/null +++ b/virtualsmartcard/win32/vpcd-config/vpcd-config.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vpcd-config", "vpcd-config.vcxproj", "{F5ECFFD7-BE92-4A5F-94B0-FF91F7680B0F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F5ECFFD7-BE92-4A5F-94B0-FF91F7680B0F}.Debug|Win32.ActiveCfg = Debug|Win32 + {F5ECFFD7-BE92-4A5F-94B0-FF91F7680B0F}.Debug|Win32.Build.0 = Debug|Win32 + {F5ECFFD7-BE92-4A5F-94B0-FF91F7680B0F}.Release|Win32.ActiveCfg = Release|Win32 + {F5ECFFD7-BE92-4A5F-94B0-FF91F7680B0F}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/virtualsmartcard/win32/vpcd-config/vpcd-config.vcxproj b/virtualsmartcard/win32/vpcd-config/vpcd-config.vcxproj new file mode 100644 index 0000000..304a6a1 --- /dev/null +++ b/virtualsmartcard/win32/vpcd-config/vpcd-config.vcxproj @@ -0,0 +1,74 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {F5ECFFD7-BE92-4A5F-94B0-FF91F7680B0F} + vpcdconfig + + + + Application + true + MultiByte + + + Application + false + true + MultiByte + + + + + + + + + + + + + + + Level3 + Disabled + ..\..\src\vpcd;%(AdditionalIncludeDirectories) + + + true + Ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + Level3 + MaxSpeed + true + true + + + true + true + true + + + + + + + + + + + + +