31 |
|
#include <netinet/in.h> |
32 |
|
#include <arpa/inet.h> |
33 |
|
|
34 |
+ |
#define versionNo 0.8 |
35 |
|
#define RECONFIGURE_RETURN_CODE 2 |
36 |
|
#define UDP_MAX_PACKET_SIZE 8192 |
37 |
|
|
411 |
|
return 0; |
412 |
|
} |
413 |
|
|
414 |
+ |
void usage(char *progname){ |
415 |
+ |
fprintf(stderr, "Usage %s [options] server port\n", progname); |
416 |
+ |
fprintf(stderr, "Options\n"); |
417 |
+ |
fprintf(stderr, " -v Verbose, the more v flags the more verbose, eg -vv\n"); |
418 |
+ |
fprintf(stderr, " -d Daemon mode, self backgrounding\n"); |
419 |
+ |
fprintf(stderr, " -s Send errors to syslog\n"); |
420 |
+ |
fprintf(stderr, " -V Print version number\n"); |
421 |
+ |
fprintf(stderr, " -h Prints this help page\n"); |
422 |
+ |
exit(1); |
423 |
+ |
} |
424 |
+ |
|
425 |
|
int main(int argc, char **argv){ |
426 |
|
ihost_state_t ihost_state; |
427 |
|
int heartbeat_exit; |
430 |
|
int sleep_delay=0; |
431 |
|
char *xml_stats; |
432 |
|
|
433 |
+ |
int cmdopt; |
434 |
+ |
extern int optind; |
435 |
+ |
int verbose=0, daemon=0, syslog=0 ; |
436 |
+ |
|
437 |
|
/* NULL'ify so i can tell if i need to free it or not */ |
438 |
|
ihost_state.fm_host=NULL; |
439 |
|
ihost_state.my_fqdn=NULL; |
443 |
|
ihost_state.key=NULL; |
444 |
|
|
445 |
|
errf_set_progname(argv[0]); |
446 |
< |
if(argc!=3){ |
447 |
< |
errf_usage("<host> <port>"); |
448 |
< |
exit(1); |
446 |
> |
|
447 |
> |
while((cmdopt=getopt(argc, argv, "vdshV")) != -1){ |
448 |
> |
switch(cmdopt){ |
449 |
> |
case 'v': |
450 |
> |
verbose++; |
451 |
> |
break; |
452 |
> |
|
453 |
> |
case 'd': |
454 |
> |
daemon=1; |
455 |
> |
break; |
456 |
> |
|
457 |
> |
case 's': |
458 |
> |
syslog=1; |
459 |
> |
break; |
460 |
> |
|
461 |
> |
case 'h': |
462 |
> |
usage(argv[0]); |
463 |
> |
break; |
464 |
> |
case 'V': |
465 |
> |
errf("%s version %f",argv[0], versionNo); |
466 |
> |
break; |
467 |
> |
default: |
468 |
> |
usage(argv[0]); |
469 |
> |
exit(1); |
470 |
> |
} |
471 |
|
} |
472 |
|
|
473 |
< |
ihost_state.fm_host=argv[1]; |
474 |
< |
ihost_state.fm_port=atoi(argv[2]); |
473 |
> |
if(argc!=optind+2){ |
474 |
> |
usage(argv[0]); |
475 |
> |
exit(1); |
476 |
> |
} |
477 |
> |
ihost_state.fm_host=argv[optind]; |
478 |
> |
ihost_state.fm_port=atoi(argv[optind+1]); |
479 |
> |
if(ihost_state.fm_port==0){ |
480 |
> |
errf("Invalid port number"); |
481 |
> |
usage(argv[0]); |
482 |
> |
} |
483 |
> |
printf("%s\n%d\n",ihost_state.fm_host, ihost_state.fm_port); |
484 |
|
|
485 |
|
if(ihost_configure(&ihost_state)!=0){ |
486 |
|
errf("configure failed"); |