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

Last change on this file since 2417 was 2417, checked in by schwittmann, 11 years ago

Several ExternalClient improvements:

  • Separated connected and request job events
  • Added basic authentication
  • Lookup DNS again after getting disconnected
  • Fixed some socket exceptions
  • Prevent slow clients from submitting old jobs by using unique job identifiers
File size: 1.6 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 $HOST $PORT [$PASSWORD]\n\n", argv[0]);
19    printf("    HOST       - PC running cryptool\n");
20    printf("    PORT       - Cryptool's listening port\n");
21    printf("    [PASSWORD] - Password used to auth with server\n");
22}
23
24bool lookup(const char* host, sockaddr_in & serv_addr)
25{
26    hostent *server = gethostbyname(host);
27
28    if(!server)
29        return false;
30
31    serv_addr.sin_family = AF_INET;
32    bcopy((char *)server->h_addr, 
33            (char *)&serv_addr.sin_addr.s_addr,
34            server->h_length);
35
36    return true;
37}
38
39int main (int argc, char **argv)
40{
41    if(argc != 3 && argc != 4)
42    {
43        usage(argv);
44        return 1;
45    }
46
47    const char* password = "";
48    if(argc == 4)
49    {
50        password = argv[3];
51    }
52
53    int port = atoi(argv[2]);
54
55    if(port == 0 || port <= 0 || port > 0xFFFF)
56    {
57        printf("Invalid port.\n");
58        return 1;
59    }
60
61    sockaddr_in serv_addr;
62    bzero((char *) &serv_addr, sizeof(serv_addr));
63    serv_addr.sin_port = htons(port);
64
65    while(true)
66    {
67        if(!lookup(argv[1], serv_addr))
68        {
69            printf("failed to lookup %s..\n", argv[1]);
70            continue;
71        }
72        networkThread(serv_addr, port, password);
73        printf("Reconnecting in %u seconds\n", RECONNECT_TIME);
74        sleep(RECONNECT_TIME);
75    }
76
77}
Note: See TracBrowser for help on using the repository browser.