From: Martin Schwenke Date: Tue, 15 Aug 2023 00:57:59 +0000 (+1000) Subject: ctdb-common: Replace pcap_open_live() by lower level calls X-Git-Tag: samba-4.17.11~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb905f04b505369e805613e694c2cbb62bd91dee;p=thirdparty%2Fsamba.git ctdb-common: Replace pcap_open_live() by lower level calls A subsequent commit will insert an additional call before pcap_activate(). This sequence of calls is taken from the source for pcap_open_live(), so there should be no change in behaviour. Given the defaults set by pcap_create_common(), it would be possible to omit the calls to pcap_set_promisc() and pcap_set_timeout(). However, those defaults don't seem to be well documented, so continue to explicitly set everything that was set before. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15451 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs (cherry picked from commit ffc2ae616d8fab7528fbdfd8c6b94c5b9a0e3a7c) --- diff --git a/ctdb/common/system_socket.c b/ctdb/common/system_socket.c index 3a7b6eb41de..16463af5a33 100644 --- a/ctdb/common/system_socket.c +++ b/ctdb/common/system_socket.c @@ -980,14 +980,38 @@ int ctdb_sys_open_capture_socket(const char *iface, void **private_data) int pcap_packet_type; const char *t = NULL; int fd; + int ret; - pt = pcap_open_live(iface, 100, 0, 0, errbuf); + pt = pcap_create(iface, errbuf); if (pt == NULL) { DBG_ERR("Failed to open pcap capture device %s (%s)\n", iface, errbuf); return -1; } + /* + * pcap isn't very clear about defaults... + */ + ret = pcap_set_snaplen(pt, 100); + if (ret < 0) { + DBG_ERR("Failed to set snaplen for pcap capture\n"); + goto fail; + } + ret = pcap_set_promisc(pt, 0); + if (ret < 0) { + DBG_ERR("Failed to unset promiscuous mode for pcap capture\n"); + goto fail; + } + ret = pcap_set_timeout(pt, 0); + if (ret < 0) { + DBG_ERR("Failed to set timeout for pcap capture\n"); + goto fail; + } + ret = pcap_activate(pt); + if (ret < 0) { + DBG_ERR("Failed to activate pcap capture\n"); + goto fail; + } pcap_packet_type = pcap_datalink(pt); switch (pcap_packet_type) {