| 31 |
|
#include <stdarg.h> |
| 32 |
|
#include <errno.h> |
| 33 |
|
#include <netdb.h> |
| 34 |
+ |
#include <netinet/in.h> |
| 35 |
|
|
| 36 |
< |
#include "ukcprog.h" |
| 37 |
< |
#include "statgrab.h" |
| 36 |
> |
#include <ukcprog.h> |
| 37 |
> |
#include <statgrab.h> |
| 38 |
|
|
| 39 |
|
#define LOG_CRIT 0 |
| 40 |
|
#define LOG_ERR 1 |
| 47 |
|
|
| 48 |
|
char *host_ip; |
| 49 |
|
char *host_fqdn; |
| 50 |
+ |
int preset_fqdn; |
| 51 |
+ |
int preset_ip; |
| 52 |
|
|
| 53 |
|
char *server_fqdn; |
| 54 |
|
int server_udp_port; |
| 166 |
|
}else{ |
| 167 |
|
fprintf(ihost_config.log, "\n"); |
| 168 |
|
} |
| 169 |
+ |
fflush(ihost_config.log); |
| 170 |
|
} |
| 171 |
|
} |
| 172 |
|
|
| 226 |
|
|
| 227 |
|
if((get_host_addr(hostname, &haddr))!=0){ |
| 228 |
|
log_msg(LOG_CRIT, "Failed to lookup name for %s", hostname); |
| 229 |
+ |
close(sock); |
| 230 |
|
return NULL; |
| 231 |
|
} |
| 232 |
|
|
| 238 |
|
log_msg(LOG_DEBUG, "Creating a tcp connection"); |
| 239 |
|
if(connect(sock, (struct sockaddr *)&addr, sizeof(addr)) !=0){ |
| 240 |
|
log_msg(LOG_CRIT, "Failed to connect to hostname %s on port %d", hostname, port); |
| 241 |
+ |
close(sock); |
| 242 |
|
return NULL; |
| 243 |
|
} |
| 244 |
|
|
| 408 |
|
* this already be NULL */ |
| 409 |
|
if(ihost_state->file_list!=NULL) free(ihost_state->file_list); |
| 410 |
|
if(ihost_state->last_modified!=NULL) free(ihost_state->last_modified); |
| 405 |
– |
if(ihost_state->host_fqdn!=NULL) free(ihost_state->host_fqdn); |
| 411 |
|
if(ihost_state->server_fqdn!=NULL) free(ihost_state->server_fqdn); |
| 407 |
– |
if(ihost_state->host_ip!=NULL) free(ihost_state->host_ip); |
| 412 |
|
|
| 413 |
+ |
if(ihost_state->preset_fqdn){ |
| 414 |
+ |
if(host_fqdn != NULL) free(host_fqdn); |
| 415 |
+ |
}else{ |
| 416 |
+ |
if(ihost_state->host_fqdn!=NULL) free(ihost_state->host_fqdn); |
| 417 |
+ |
ihost_state->host_fqdn=host_fqdn; |
| 418 |
+ |
} |
| 419 |
+ |
|
| 420 |
+ |
if(ihost_state->preset_ip){ |
| 421 |
+ |
if(host_ip != NULL) free(host_ip); |
| 422 |
+ |
}else{ |
| 423 |
+ |
if(ihost_state->host_ip!=NULL) free(ihost_state->host_ip); |
| 424 |
+ |
ihost_state->host_ip=host_ip; |
| 425 |
+ |
} |
| 426 |
+ |
|
| 427 |
+ |
|
| 428 |
|
ihost_state->file_list=file_list; |
| 429 |
|
ihost_state->last_modified=last_modified; |
| 411 |
– |
ihost_state->host_fqdn=host_fqdn; |
| 412 |
– |
ihost_state->host_ip=host_ip; |
| 430 |
|
ihost_state->server_fqdn=server_fqdn; |
| 431 |
|
ihost_state->server_udp_port=server_udp_port; |
| 432 |
|
ihost_state->udp_update_time=udp_update_time; |
| 716 |
|
fprintf(stderr, "Options\n"); |
| 717 |
|
fprintf(stderr, " -v Verbose mode,-vv would make even more verbose\n"); |
| 718 |
|
fprintf(stderr, " -f Foreground mode, print errors to stderr\n"); |
| 719 |
+ |
fprintf(stderr, " -s Set the machine name to be reported as\n"); |
| 720 |
+ |
fprintf(stderr, " -i Set the IP to be reported as\n"); |
| 721 |
|
fprintf(stderr, " -V Print version number\n"); |
| 722 |
|
fprintf(stderr, " -h Prints this help page\n"); |
| 723 |
|
exit(1); |
| 749 |
|
ihost_state.filtermanager_host=NULL; |
| 750 |
|
ihost_state.host_fqdn=NULL; |
| 751 |
|
ihost_state.host_ip=NULL; |
| 752 |
+ |
ihost_state.preset_fqdn = 0; |
| 753 |
+ |
ihost_state.preset_ip = 0; |
| 754 |
|
ihost_state.server_fqdn=NULL; |
| 755 |
|
ihost_state.file_list=NULL; |
| 756 |
|
ihost_state.last_modified=NULL; |
| 757 |
|
|
| 758 |
< |
while((cmdopt=getopt(argc, argv, "vfhV")) != -1){ |
| 758 |
> |
while((cmdopt=getopt(argc, argv, "vfhVs:i:")) != -1){ |
| 759 |
|
switch(cmdopt){ |
| 760 |
|
case 'v': |
| 761 |
|
ihost_config.verbose++; |
| 773 |
|
case 'V': |
| 774 |
|
fprintf(stderr, "%s version %s\n", argv[0], VERSION); |
| 775 |
|
break; |
| 776 |
+ |
case 's': |
| 777 |
+ |
ihost_state.preset_fqdn = 1; |
| 778 |
+ |
ihost_state.host_fqdn = strdup(optarg); |
| 779 |
+ |
if(ihost_state.host_fqdn == NULL){ |
| 780 |
+ |
fprintf(stderr, "Missing hostname\n"); |
| 781 |
+ |
usage(argv[0]); |
| 782 |
+ |
} |
| 783 |
+ |
break; |
| 784 |
+ |
case 'i': |
| 785 |
+ |
/* Hmm.. Someone could set any string to be the IP, and it will let it */ |
| 786 |
+ |
ihost_state.preset_ip = 1; |
| 787 |
+ |
ihost_state.host_ip = strdup(optarg); |
| 788 |
+ |
if(ihost_state.host_ip == NULL){ |
| 789 |
+ |
fprintf(stderr, "Missing ip\n"); |
| 790 |
+ |
usage(argv[0]); |
| 791 |
+ |
} |
| 792 |
+ |
break; |
| 793 |
|
|
| 794 |
|
default: |
| 795 |
|
usage(argv[0]); |