diff options
Diffstat (limited to 'src/libs/zbxsysinfo/hpux/net.c')
-rw-r--r-- | src/libs/zbxsysinfo/hpux/net.c | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/src/libs/zbxsysinfo/hpux/net.c b/src/libs/zbxsysinfo/hpux/net.c index 6d6d05ab71b..1eb3b974390 100644 --- a/src/libs/zbxsysinfo/hpux/net.c +++ b/src/libs/zbxsysinfo/hpux/net.c @@ -49,7 +49,7 @@ static struct strbuf ctlbuf = #define ZBX_IF_SEP ',' -void add_if_name(char **if_list, size_t *if_list_alloc, size_t *if_list_offset, const char *name) +static void add_if_name(char **if_list, size_t *if_list_alloc, size_t *if_list_offset, const char *name) { if (FAIL == str_in_list(*if_list, name, ZBX_IF_SEP)) { @@ -60,7 +60,7 @@ void add_if_name(char **if_list, size_t *if_list_alloc, size_t *if_list_offset, } } -int get_if_names(char **if_list, size_t *if_list_alloc, size_t *if_list_offset) +static int get_if_names(char **if_list, size_t *if_list_alloc, size_t *if_list_offset) { int s, ifreq_size, numifs, i, family = AF_INET; struct sockaddr *from; @@ -148,6 +148,7 @@ end: #endif return SUCCEED; } + #endif /* HPUX_VERSION < 1131 */ int NET_IF_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result) @@ -162,16 +163,20 @@ int NET_IF_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result) struct zbx_json j; char *if_name; - zbx_json_init(&j, ZBX_JSON_STAT_BUF_LEN); - - zbx_json_addarray(&j, ZBX_PROTO_TAG_DATA); - #if HPUX_VERSION < 1131 if_list = zbx_malloc(if_list, if_list_alloc); *if_list = '\0'; if (FAIL == get_if_names(&if_list, &if_list_alloc, &if_list_offset)) + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot obtain network interface information.")); + zbx_free(if_list); return SYSINFO_RET_FAIL; + } + + zbx_json_init(&j, ZBX_JSON_STAT_BUF_LEN); + + zbx_json_addarray(&j, ZBX_PROTO_TAG_DATA); if_name = if_list; @@ -188,7 +193,6 @@ int NET_IF_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result) zbx_json_addstring(&j, "{#IFNAME}", if_name, ZBX_JSON_TYPE_STRING); zbx_json_close(&j); #if HPUX_VERSION < 1131 - if (NULL != if_name_end) { *if_name_end = ZBX_IF_SEP; @@ -294,6 +298,7 @@ static int dlpi_get_stats(int fd, Ext_mib_t *mib) stat_msg = *(dl_get_statistics_ack_t *)buf_ctl; memcpy(mib, (Ext_mib_t *)(buf_ctl + stat_msg.dl_stat_offset), sizeof(Ext_mib_t)); + return SUCCEED; } @@ -360,9 +365,11 @@ static int get_ppa(int fd, const char *if_name, int *ppa) break; } } + zbx_free(buf); zbx_free(ppa_data_buf); } + return ret; } @@ -398,13 +405,19 @@ int NET_IF_IN(AGENT_REQUEST *request, AGENT_RESULT *result) Ext_mib_t mib; if (2 < request->nparam) + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters.")); return SYSINFO_RET_FAIL; + } if_name = get_rparam(request, 0); mode = get_rparam(request, 1); if (FAIL == get_net_stat(&mib, if_name)) + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot obtain network interface information.")); return SYSINFO_RET_FAIL; + } if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "bytes")) SET_UI64_RESULT(result, mib.mib_if.ifInOctets); @@ -415,7 +428,10 @@ int NET_IF_IN(AGENT_REQUEST *request, AGENT_RESULT *result) else if (0 == strcmp(mode, "dropped")) SET_UI64_RESULT(result, mib.mib_if.ifInDiscards); else + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter.")); return SYSINFO_RET_FAIL; + } return SYSINFO_RET_OK; } @@ -426,13 +442,19 @@ int NET_IF_OUT(AGENT_REQUEST *request, AGENT_RESULT *result) Ext_mib_t mib; if (2 < request->nparam) + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters.")); return SYSINFO_RET_FAIL; + } if_name = get_rparam(request, 0); mode = get_rparam(request, 1); if (FAIL == get_net_stat(&mib, if_name)) + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot obtain network interface information.")); return SYSINFO_RET_FAIL; + } if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "bytes")) SET_UI64_RESULT(result, mib.mib_if.ifOutOctets); @@ -443,7 +465,10 @@ int NET_IF_OUT(AGENT_REQUEST *request, AGENT_RESULT *result) else if (0 == strcmp(mode, "dropped")) SET_UI64_RESULT(result, mib.mib_if.ifOutDiscards); else + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter.")); return SYSINFO_RET_FAIL; + } return SYSINFO_RET_OK; } @@ -454,13 +479,19 @@ int NET_IF_TOTAL(AGENT_REQUEST *request, AGENT_RESULT *result) Ext_mib_t mib; if (2 < request->nparam) + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters.")); return SYSINFO_RET_FAIL; + } if_name = get_rparam(request, 0); mode = get_rparam(request, 1); if (FAIL == get_net_stat(&mib, if_name)) + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot obtain network interface information.")); return SYSINFO_RET_FAIL; + } if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "bytes")) { @@ -480,7 +511,10 @@ int NET_IF_TOTAL(AGENT_REQUEST *request, AGENT_RESULT *result) SET_UI64_RESULT(result, mib.mib_if.ifInDiscards + mib.mib_if.ifOutDiscards); } else + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter.")); return SYSINFO_RET_FAIL; + } return SYSINFO_RET_OK; } |