add promiscuous mode

master
Harald Welte 10 months ago
parent 580f923b48
commit 0cb90ab61d
  1. 23
      tr-bridge.c

@ -73,6 +73,23 @@ static int devname2ifindex(const char *ifname)
return ifr.ifr_ifindex;
}
static int enable_promisc(int sk, int ifindex)
{
struct packet_mreq mreq = {0};
int rc;
mreq.mr_ifindex = ifindex;
mreq.mr_type = PACKET_MR_PROMISC;
rc = setsockopt(sk, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mreq, sizeof(mreq));
if (rc < 0) {
fprintf(stderr, "Unable to set promiscuous mode: %s\n", strerror(errno));
return rc;
}
return 0;
}
static int open_packet_socket(int ifindex)
{
struct sockaddr_ll addr;
@ -101,6 +118,12 @@ static int open_packet_socket(int ifindex)
return rc;
}
rc = enable_promisc(fd, ifindex);
if (rc < 0) {
close(fd);
return rc;
}
return fd;
}

Loading…
Cancel
Save