diff --git a/src/zabbix_sender/zabbix_sender.c b/src/zabbix_sender/zabbix_sender.c index c482f692958..57480fa8916 100644 --- a/src/zabbix_sender/zabbix_sender.c +++ b/src/zabbix_sender/zabbix_sender.c @@ -862,6 +862,18 @@ static void zbx_load_config(const char *config_file_in) zbx_free(cfg_hostname); } + else + { + char buffer[MAX_STRING_LEN]; + + buffer[MAX_STRING_LEN - 1] = '\0'; + + /* check for successful call to the gethostname and check that data fits in the buffer */ + if (0 == gethostname(buffer, MAX_STRING_LEN - 1) && MAX_STRING_LEN - 2 > strlen(buffer)) + { + ZABBIX_HOSTNAME = zbx_strdup(NULL, buffer); + } + } zbx_fill_from_config_file(&config_source_ip, cfg_source_ip);