From ecd09023d7a5c4c2c0680b097a10c0f9ce132657 Mon Sep 17 00:00:00 2001 From: osmiy Date: Mon, 16 Apr 2007 14:24:17 +0000 Subject: fixed winXX comms protocol git-svn-id: svn://svn.zabbix.com/trunk@4026 97f52cf1-0a1b-0410-bd0e-c28be96e8082 --- src/zabbix_get/zabbix_get.c | 78 ++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 30 deletions(-) (limited to 'src/zabbix_get') diff --git a/src/zabbix_get/zabbix_get.c b/src/zabbix_get/zabbix_get.c index 3c39b184..439684be 100644 --- a/src/zabbix_get/zabbix_get.c +++ b/src/zabbix_get/zabbix_get.c @@ -19,11 +19,16 @@ #include "common.h" +#include "threads.h" #include "comms.h" +#include "cfg.h" +#include "log.h" +#include "zbxgetopt.h" char *progname = NULL; char title_message[] = "ZABBIX get - Communicate with ZABBIX agent"; -char usage_message[] = "[-hV] -s [-p] -k"; +char usage_message[] = "[-hV] -s [-p] -k"; + #ifndef HAVE_GETOPT_LONG char *help_message[] = { "Options:", @@ -50,7 +55,10 @@ char *help_message[] = { }; #endif -struct option longopts[] = +/* COMMAND LINE OPTIONS */ + +/* long options */ +struct zbx_option longopts[] = { {"port", 1, 0, 'p'}, {"host", 1, 0, 's'}, @@ -60,6 +68,14 @@ struct option longopts[] = {0,0,0,0} }; +/* short options */ + +static char shortopts[] = "k:p:s:hV"; + +/* end of COMMAND LINE OPTIONS*/ + + +#if !defined(_WINDOWS) /****************************************************************************** * * @@ -91,6 +107,8 @@ void signal_handler( int sig ) exit( FAIL ); } +#endif /* not WINDOWS */ + /****************************************************************************** * * * Function: get_value * @@ -112,7 +130,7 @@ void signal_handler( int sig ) ******************************************************************************/ static int get_value( const char *host, - const int port, + unsigned short port, const char *key, char *value, int value_max_len @@ -158,40 +176,40 @@ static int get_value( ******************************************************************************/ int main(int argc, char **argv) { - int port = 10050; + unsigned short port = 10050; int ret = SUCCEED; char value[MAX_STRING_LEN]; char *host = NULL; char *key = NULL; - int ch; + char ch; - progname = argv[0]; + progname = get_programm_name(argv[0]); /* Parse the command-line. */ - while ((ch = getopt_long(argc, argv, "k:p:s:hv", longopts, NULL)) != EOF) - switch ((char) ch) { - case 'k': - key = strdup(optarg); - break; - case 'p': - port = atoi(optarg); - break; - case 's': - host = strdup(optarg); - break; - case 'h': - help(); - exit(-1); - break; - case 'V': - version(); - exit(-1); - break; - default: - usage(); - exit(-1); - break; - } + while ((ch = zbx_getopt_long(argc, argv, shortopts, longopts, NULL)) != EOF) + switch ((char) ch) { + case 'k': + key = strdup(zbx_optarg); + break; + case 'p': + port = (unsigned short)atoi(zbx_optarg); + break; + case 's': + host = strdup(zbx_optarg); + break; + case 'h': + help(); + exit(-1); + break; + case 'V': + version(); + exit(-1); + break; + default: + usage(); + exit(-1); + break; + } if( (host==NULL) || (key==NULL)) { -- cgit