diff --git a/src/libs/zbxsysinfo/linux/net.c b/src/libs/zbxsysinfo/linux/net.c index 75b31e9f2cf..95637e4a5b7 100644 --- a/src/libs/zbxsysinfo/linux/net.c +++ b/src/libs/zbxsysinfo/linux/net.c @@ -1255,6 +1255,66 @@ static void get_wifi_info(const char *interface, struct zbx_json *j) close(sockfd); } +// TODO: create final version, this is just proof of concept +// TODO: do propper: +// checks +// error handling +// type conversion +// etc +static void get_if_type(const char *ifname, struct zbx_json *j) +{ + FILE *f; + char *path, buf[MAX_STRING_LEN]; + unsigned int value = 0; + + if (NULL == (path = zbx_dsprintf(NULL, "/sys/class/net/%s/type", ifname))) + { + // TODO: should never happen? + goto out; + } + + // TODO: do propper error handling and type conversion + if (NULL != (f = fopen(path, "r"))) + { + if (NULL != fgets(buf, sizeof(buf), f)) + { + value = (unsigned int )atoi(buf); + } + zbx_fclose(f); + } + + zbx_free(path); + + if (772 == value) + { + zbx_json_addstring(j, "type", "loopback", ZBX_JSON_TYPE_STRING); + goto out; + + } + + // check if "device" symlink exists for this device + + if (NULL == (path = zbx_dsprintf(NULL, "/sys/class/net/%s/device", ifname))) + { + // TODO: should never happen? + goto out; + + } + + if (NULL != (f = fopen(path, "r"))) + { + zbx_json_addstring(j, "type", "physical", ZBX_JSON_TYPE_STRING); + } + else + { + zbx_json_addstring(j, "type", "virtual", ZBX_JSON_TYPE_STRING); + } + zbx_fclose(f); +out: + zbx_free(path); +} + + static void get_link_settings(const char *interface, struct zbx_json *j) { int sock; @@ -1446,7 +1506,8 @@ int net_if_get(AGENT_REQUEST *request, AGENT_RESULT *result) zbx_json_adduint64(&jval, "compressed", ns.ocompressed); zbx_json_close(&jval); - fill_net_if_get_params(if_name, "type", NULL, 1, &jval); + //fill_net_if_get_params(if_name, "type", NULL, 1, &jval); + get_if_type(if_name, &jval); fill_net_if_get_params(if_name, "address", "mac", 0, &jval); fill_net_if_get_params(if_name, "ifalias", NULL, 0, &jval); fill_net_if_get_params(if_name, "carrier", NULL, 1, &jval);