170 |
|
} |
171 |
|
} |
172 |
|
|
173 |
– |
/* Takes many pointers, checks if they are NULL or not, and then free's them */ |
174 |
– |
/* Deprciated - and i only wrote it today! :) |
175 |
– |
void m_free(int num_pointers, ...){ |
176 |
– |
int x=0; |
177 |
– |
va_list ap; |
178 |
– |
void *p; |
179 |
– |
|
180 |
– |
va_start(ap, num_pointers); |
181 |
– |
for(;x<num_pointers;x++){ |
182 |
– |
p=va_arg(ap, void*); |
183 |
– |
if(p!=NULL){ |
184 |
– |
free(p); |
185 |
– |
} |
186 |
– |
} |
187 |
– |
va_end(ap); |
188 |
– |
} |
189 |
– |
*/ |
190 |
– |
|
173 |
|
int create_udp_sockinfo(udp_sockinfo_t *udp_sockinfo, char *hostname, int port){ |
174 |
|
|
175 |
|
struct in_addr haddr; |
369 |
|
goto error; |
370 |
|
} |
371 |
|
|
390 |
– |
printf("string : %s\n", response_ptr); |
372 |
|
server_udp_port=atoi(response_ptr); |
373 |
|
|
374 |
|
if (server_udp_port==0){ |
693 |
|
|
694 |
|
|
695 |
|
void usage(char *progname){ |
696 |
< |
fprintf(stderr, "Usage %s [options] server port\n", progname); |
697 |
< |
fprintf(stderr, "Options\n"); |
698 |
< |
fprintf(stderr, " -v Verbose mode,-vv would make even more verbose\n"); |
699 |
< |
fprintf(stderr, " -f Foreground mode, print errors to stderr\n"); |
700 |
< |
fprintf(stderr, " -s Set the machine name to be reported as\n"); |
701 |
< |
fprintf(stderr, " -i Set the IP to be reported as\n"); |
702 |
< |
fprintf(stderr, " -V Print version number\n"); |
703 |
< |
fprintf(stderr, " -h Prints this help page\n"); |
696 |
> |
fprintf(stderr, "Usage %s [-v[v]] [-f] [-n name] [-i ip] [-s server] [-p port] [-V] [-h]\n\n", progname); |
697 |
> |
fprintf(stderr, " -v Verbose mode, -vv would make even more verbose\n"); |
698 |
> |
fprintf(stderr, " -f Foreground mode, print errors to stderr\n"); |
699 |
> |
fprintf(stderr, " -n Set the machine name to be reported as\n"); |
700 |
> |
fprintf(stderr, " -i Set the IP to be reported as\n"); |
701 |
> |
fprintf(stderr, " -s Specifies the i-scream server to connect to\n"); |
702 |
> |
fprintf(stderr, " default: %s\n", DEF_SERVER_NAME); |
703 |
> |
fprintf(stderr, " -p Specifies the i-scream server port\n"); |
704 |
> |
fprintf(stderr, " default: %d\n", DEF_SERVER_PORT); |
705 |
> |
fprintf(stderr, " -V Print version number\n"); |
706 |
> |
fprintf(stderr, " -h Prints this help page\n"); |
707 |
> |
fprintf(stderr, "\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT); |
708 |
|
exit(1); |
709 |
|
} |
710 |
|
|
731 |
|
ihost_config.log=stderr; |
732 |
|
|
733 |
|
/* Blank ihost_state to default settings */ |
734 |
< |
ihost_state.filtermanager_host=NULL; |
734 |
> |
ihost_state.filtermanager_host=DEF_SERVER_NAME; |
735 |
> |
ihost_state.filtermanager_port=DEF_SERVER_PORT; |
736 |
|
ihost_state.host_fqdn=NULL; |
737 |
|
ihost_state.host_ip=NULL; |
738 |
|
ihost_state.preset_fqdn = 0; |
741 |
|
ihost_state.file_list=NULL; |
742 |
|
ihost_state.last_modified=NULL; |
743 |
|
|
744 |
< |
while((cmdopt=getopt(argc, argv, "vfhVs:i:")) != -1){ |
744 |
> |
while((cmdopt=getopt(argc, argv, "vfVn:i:s:p:h")) != -1){ |
745 |
|
switch(cmdopt){ |
746 |
|
case 'v': |
747 |
|
ihost_config.verbose++; |
752 |
|
ihost_config.daemon=0; |
753 |
|
break; |
754 |
|
|
769 |
– |
case 'h': |
770 |
– |
usage(argv[0]); |
771 |
– |
break; |
772 |
– |
|
755 |
|
case 'V': |
756 |
|
fprintf(stderr, "%s version %s\n", argv[0], VERSION); |
757 |
|
break; |
758 |
< |
case 's': |
758 |
> |
case 'n': |
759 |
|
ihost_state.preset_fqdn = 1; |
760 |
|
ihost_state.host_fqdn = strdup(optarg); |
761 |
|
if(ihost_state.host_fqdn == NULL){ |
773 |
|
} |
774 |
|
break; |
775 |
|
|
776 |
+ |
case 's': |
777 |
+ |
ihost_state.filtermanager_host=strdup(optarg); |
778 |
+ |
break; |
779 |
+ |
|
780 |
+ |
case 'p': |
781 |
+ |
ihost_state.filtermanager_port=atoi(optarg); |
782 |
+ |
break; |
783 |
+ |
|
784 |
+ |
case 'h': |
785 |
|
default: |
786 |
|
usage(argv[0]); |
787 |
|
exit(1); |
788 |
|
} |
789 |
|
} |
790 |
|
|
800 |
– |
if(argc!=optind+2){ |
801 |
– |
usage(argv[0]); |
802 |
– |
exit(1); |
803 |
– |
} |
804 |
– |
|
805 |
– |
ihost_state.filtermanager_host=strdup(argv[optind]); |
806 |
– |
ihost_state.filtermanager_port=atoi(argv[optind+1]); |
807 |
– |
|
791 |
|
if(gethostbyname(ihost_state.filtermanager_host)==NULL){ |
792 |
|
log_msg(LOG_CRIT, "Failed to lookup hostname. Please check settings"); |
793 |
|
exit(1); |
824 |
|
|
825 |
|
} |
826 |
|
|
827 |
< |
log_msg(LOG_INFO, "Starting ihost"); |
827 |
> |
log_msg(LOG_INFO, "Starting ihost..."); |
828 |
> |
|
829 |
> |
log_msg(LOG_DEBUG, "Running statgrab_init()"); |
830 |
> |
if(!statgrab_init()){ |
831 |
> |
log_msg(LOG_CRIT, "statgrab_init failed (%m)"); |
832 |
> |
exit(1); |
833 |
> |
} |
834 |
|
|
835 |
|
log_msg(LOG_DEBUG,"Writing PID FILE"); |
836 |
|
|
858 |
|
sleep(10); |
859 |
|
} |
860 |
|
|
872 |
– |
printf("%s\n%d\n", ihost_state.server_fqdn, ihost_state.server_udp_port); |
861 |
|
while((create_udp_sockinfo(&udp_sockinfo, ihost_state.server_fqdn, ihost_state.server_udp_port))!=0){ |
862 |
|
log_msg(LOG_ERR, "Failed to create udp socket"); |
863 |
|
sleep(10); |