23 #include <netcomm/fawkes/client.h>
24 #include <netcomm/fawkes/client_handler.h>
25 #include <netcomm/fawkes/component_ids.h>
26 #include <logging/network.h>
27 #include <logging/console.h>
28 #include <utils/system/signal.h>
29 #include <utils/system/argparser.h>
35 using namespace fawkes;
39 class NetLogConsolePrinter
44 NetLogConsolePrinter(
const char *hostport)
49 char *hp = strdup(hostport);
50 const char *hostname = strtok(hp,
":");
51 const char *portstr = strtok(NULL,
"");
55 if ( (port < 0) || ( port > 0xFFFF ) ) {
56 printf(
"Invalid port given, must be in range [1:65535]. Using default 1910 instead\n");
63 client->register_handler(
this, FAWKES_CID_NETWORKLOGGER);
69 ~NetLogConsolePrinter()
75 void handle_signal(
int signal)
78 client->wake(FAWKES_CID_NETWORKLOGGER);
82 unsigned int id)
throw()
84 if ( (m->cid() == FAWKES_CID_NETWORKLOGGER) &&
87 struct timeval t = content->
get_time();
94 virtual void deregistered(
unsigned int id)
throw()
100 virtual void connection_died(
unsigned int id)
throw()
102 printf(
"Connection to host died. Aborting.\n");
107 virtual void connection_established(
unsigned int id)
throw()
115 client->wait(FAWKES_CID_NETWORKLOGGER);
117 client->disconnect();
130 print_usage(
const char *program_name)
132 printf(
"Usage: %s [hostname[:port]]\n", program_name);
136 main(
int argc,
char **argv)
140 if ( argp.has_arg(
"h") ) {
141 print_usage(argv[0]);
145 const char *hostport = (argp.num_items() > 0) ? argp.items()[0] :
"localhost:1910";
146 NetLogConsolePrinter printer(hostport);