diff options
| author | yangwei <[email protected]> | 2019-04-11 12:25:27 +0800 |
|---|---|---|
| committer | yangwei <[email protected]> | 2019-04-11 12:25:27 +0800 |
| commit | 39493badab924847044e3cd823872a79fc287aab (patch) | |
| tree | 03ad0cb256381e87ee9745e80c76e17a6be78811 | |
| parent | 2adf5c81f181e18fb996ecd973724ea8687c9c5d (diff) | |
采集日志新增捕包机IP
| -rw-r--r-- | src/ntc_http_collect.c | 35 | ||||
| -rw-r--r-- | src/ntc_http_collect.h | 4 |
2 files changed, 38 insertions, 1 deletions
diff --git a/src/ntc_http_collect.c b/src/ntc_http_collect.c index 2ac741b..7639cd2 100644 --- a/src/ntc_http_collect.c +++ b/src/ntc_http_collect.c @@ -66,6 +66,30 @@ rd_kafka_t *g_multi_kafka_producer; rd_kafka_t *g_ntc_http_collect_kafka_handle = NULL; rd_kafka_topic_t *g_ntc_http_collect_kafka_topic = NULL; +static unsigned int get_ip_by_eth_name(const char *ifname) +{ + int sockfd; + struct ifreq ifr; + unsigned int ip; + + sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (-1 == sockfd) { + goto error; + } + + strcpy(ifr.ifr_name,ifname); + if (ioctl(sockfd, SIOCGIFADDR, &ifr) < 0) { + goto error; + } + + ip = ((struct sockaddr_in*)&(ifr.ifr_addr))->sin_addr.s_addr; + close(sockfd); + return ip; + +error: + close(sockfd); + return INADDR_NONE; +} typedef struct store_hash_data_t { @@ -195,6 +219,7 @@ static void feedback_url_to_kafka(streaminfo *a_tcp, int http_seq, store_hash_da cJSON_AddStringToObject(feedback_node, "k", store_key); cJSON_AddStringToObject(feedback_node, "v", value); + cJSON_AddStringToObject(feedback_node, "cap_ip", g_item.local_ip_str); //char *feedback = cJSON_Print(feedback_node); @@ -314,6 +339,16 @@ static void NTC_HTTP_COLLECT_load_profile() memcpy(g_item.filter_file_path, FILTER_PATH, strlen(FILTER_PATH)); memcpy(g_item.profile_path, PROFILE_PATH, strlen(PROFILE_PATH)); + char nic_name[64]; + MESA_load_profile_string_def(PROFILE_PATH,"SYSTEM", "NIC_NAME",nic_name,sizeof(nic_name),"eth0"); + g_item.local_ip_nr=get_ip_by_eth_name(nic_name); + if(g_item.local_ip_nr==INADDR_NONE) + { + printf("get_ip_by_eth_name in %s return NULL, exit!\n", nic_name); + exit(0); + } + + inet_ntop(AF_INET,&(g_item.local_ip_nr),g_item.local_ip_str,sizeof(g_item.local_ip_str)); MESA_load_profile_string_def(g_item.profile_path, PLUGIN_NAME, "log_path", g_item.log_path, sizeof(g_item.log_path), "./avlog/http_url_discovery_log"); MESA_load_profile_uint_def(g_item.profile_path, PLUGIN_NAME, "log_level", &g_item.log_level, 30); diff --git a/src/ntc_http_collect.h b/src/ntc_http_collect.h index 8755e5e..cbee5ad 100644 --- a/src/ntc_http_collect.h +++ b/src/ntc_http_collect.h @@ -13,7 +13,9 @@ typedef struct _g_http_url_discovery_item unsigned int hash_size; unsigned int expire_time; - char topic_buf[64]; + char topic_buf[64]; + char local_ip_str[128]; + unsigned int local_ip_nr; unsigned int enable_lostlen; unsigned int enable_double; |
