source: trunk/CrypPlugins/KeySearcher/ExternalClient/Main.cpp @ 2205

Last change on this file since 2205 was 2205, checked in by Sven Rech, 11 years ago

Added external client for other plattforms which can be used to support the keysearcher (client doesn't work yet)

File size: 1.5 KB
Line 
1#include <ctype.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <unistd.h>
5#include <sys/types.h>
6#include <sys/socket.h>
7#include <netdb.h>
8#include <string.h>
9#include <netinet/in.h>
10#include <arpa/inet.h>
11
12#include "Network.h"
13
14#define RECONNECT_TIME  5
15
16void usage(char **argv)
17{
18    printf("Usage: %s $THREAD_NUM $HOST $PORT\n\n", argv[0]);
19    printf("    THREAD_NUM - Number of concurrent threads\n");
20    printf("    HOST       - PC running cryptool\n");
21    printf("    PORT       - Cryptool's listening port\n");
22}
23
24int threadNum;
25
26
27int main (int argc, char **argv)
28{
29    if(argc != 4)
30    {
31        usage(argv);
32        return 1;
33    }
34
35    threadNum = atoi(argv[1]);
36    if(threadNum== 0)
37    {
38        printf("Invalid number of threads\n");
39        return 1;
40    }
41
42    hostent *server = gethostbyname(argv[2]);
43    if(!server)
44    {
45        printf("Invalid host\n");
46        return 1;
47    }
48
49    int port = atoi(argv[3]);
50
51    if(port == 0 || port <= 0 || port > 0xFFFF)
52    {
53        printf("Invalid port.\n");
54        return 1;
55    }
56
57    sockaddr_in serv_addr;
58    bzero((char *) &serv_addr, sizeof(serv_addr));
59    serv_addr.sin_family = AF_INET;
60    bcopy((char *)server->h_addr, 
61            (char *)&serv_addr.sin_addr.s_addr,
62            server->h_length);
63    serv_addr.sin_port = htons(port);
64    while(true)
65    {
66        networkThread(serv_addr, port);
67        printf("Reconnecting in %u seconds\n", RECONNECT_TIME);
68        sleep(RECONNECT_TIME);
69    }
70
71}
Note: See TracBrowser for help on using the repository browser.