vpcd-config: added scripts for windows builds

This commit is contained in:
Frank Morgner
2014-09-12 07:58:44 +02:00
parent 75137a3e59
commit 04d26c376c
4 changed files with 146 additions and 11 deletions

View File

@@ -8,10 +8,17 @@
#include<stdio.h> //printf
#include<string.h> //memset
#include<errno.h> //errno
#include<string.h>
#ifdef _WIN32
#include<winsock2.h>
#include<WS2tcpip.h>
#define close(s) closesocket(s)
#else
#include<sys/socket.h> //socket
#include<netinet/in.h> //sockaddr_in
#include<arpa/inet.h> //getsockname
#include<unistd.h> //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)

View File

@@ -19,17 +19,23 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include "vpcd.h"
extern const char *local_ip (void);
#ifdef _WIN32
#define VICC_MAX_SLOTS 1
#include <process.h>
#include <string.h>
#else
/* pcscd allows at most 16 readers. We will use 10.
* See PCSCLITE_MAX_READERS_CONTEXTS in pcsclite.h */
#include <pcsclite.h>
#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: