1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-26 01:49:31 +03:00

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 <mschwenke@ddn.com>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
(cherry picked from commit ffc2ae616d)
This commit is contained in:
Martin Schwenke
2023-08-15 10:57:59 +10:00
committed by Jule Anger
parent 74d43dd395
commit bb905f04b5

View File

@ -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) {