From 9d7628af64cb80a07c58040f56b6ba3bd60ff915 Mon Sep 17 00:00:00 2001 From: "hyunuk.tak" Date: Wed, 23 Jun 2021 07:41:29 +0900 Subject: [PATCH] Replace pcap_lookupdev with pcap_findalldevs 'pcap_lookupdev' is deprecated: use 'pcap_findalldevs' and use the first device Change-Id: I5451f10f9f6db9f5a1106e02fba60b90569519af Signed-off-by: hyunuk.tak --- plugin/pcap/stcplugin-pcap.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/plugin/pcap/stcplugin-pcap.c b/plugin/pcap/stcplugin-pcap.c index be7f2f0..6542959 100644 --- a/plugin/pcap/stcplugin-pcap.c +++ b/plugin/pcap/stcplugin-pcap.c @@ -1505,23 +1505,23 @@ int stc_plugin_pcap_deinitialize(void) int stc_plugin_pcap_lookup_dev(void) { - char *dev = NULL; + pcap_if_t *alldevs = NULL; char errbuf[PCAP_ERRBUF_SIZE]; - dev = pcap_lookupdev(errbuf); - if (dev == NULL) { - STC_LOGE("Failed to look up dev [%s]", errbuf); + if (pcap_findalldevs(&alldevs, errbuf) < 0 || + alldevs == NULL) { + STC_LOGE("Failed to find all devs [%s]", errbuf); return STC_ERROR_FAIL; } - STC_LOGD("Dev [%s]", dev); + STC_LOGD("Dev [%s]", alldevs->name); return STC_ERROR_NONE; } int stc_plugin_pcap_lookup_net(void) { - char *dev = NULL; + pcap_if_t *alldevs = NULL; char net[BUFF_SIZE_IP]; char mask[BUFF_SIZE_IP]; char errbuf[PCAP_ERRBUF_SIZE]; @@ -1529,15 +1529,15 @@ int stc_plugin_pcap_lookup_net(void) bpf_u_int32 netp; bpf_u_int32 maskp; - dev = pcap_lookupdev(errbuf); - if (dev == NULL) { - STC_LOGE("Failed to look up dev [%s]", errbuf); + if (pcap_findalldevs(&alldevs, errbuf) < 0 || + alldevs == NULL) { + STC_LOGE("Failed to find all devs [%s]", errbuf); return STC_ERROR_FAIL; } - STC_LOGD("Dev [%s]", dev); + STC_LOGD("Dev [%s]", alldevs->name); - ret = pcap_lookupnet(dev, &netp, &maskp, errbuf); + ret = pcap_lookupnet(alldevs->name, &netp, &maskp, errbuf); if (ret == -1) { STC_LOGE("Failed to look up net [%s]", errbuf); return STC_ERROR_FAIL; -- 2.7.4