Improve BSD bridge detection portability
This commit is contained in:
parent
40dd2b1a6c
commit
a71b48be1b
1 changed files with 14 additions and 37 deletions
51
ethsock.c
51
ethsock.c
|
@ -41,16 +41,10 @@
|
||||||
#else
|
#else
|
||||||
#define NMRPFLASH_AF_PACKET AF_LINK
|
#define NMRPFLASH_AF_PACKET AF_LINK
|
||||||
#include <net/if_types.h>
|
#include <net/if_types.h>
|
||||||
|
#include <net/if_media.h>
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NMRPFLASH_BSD
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <netinet/if_ether.h>
|
|
||||||
#include <net/if_bridgevar.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct ethsock
|
struct ethsock
|
||||||
{
|
{
|
||||||
const char *intf;
|
const char *intf;
|
||||||
|
@ -162,36 +156,9 @@ static bool set_stp_enabled(const char *intf, bool enabled)
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
static bool is_bridge(const char *intf)
|
|
||||||
{
|
|
||||||
#ifdef NMRPFLASH_BSD
|
|
||||||
struct ifdrv ifd;
|
|
||||||
struct ifbropreq ifbop;
|
|
||||||
int err, fd = socket(AF_INET, SOCK_DGRAM, 0);
|
|
||||||
if (fd < 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
strncpy(ifd.ifd_name, intf, sizeof(ifd.ifd_name));
|
|
||||||
ifd.ifd_cmd = BRDGPARAM;
|
|
||||||
ifd.ifd_data = &ifbop;
|
|
||||||
ifd.ifd_len = sizeof(ifbop);
|
|
||||||
|
|
||||||
err = ioctl(fd, SIOCGDRVSPEC, &ifd);
|
|
||||||
if (err && verbosity) {
|
|
||||||
xperror("ioctl(SIOCGDRVSPEC)");
|
|
||||||
}
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
return !err;
|
|
||||||
#else
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool get_intf_info(const char *intf, uint8_t *hwaddr, void *dummy)
|
static bool get_intf_info(const char *intf, uint8_t *hwaddr, bool *bridge)
|
||||||
{
|
{
|
||||||
struct ifaddrs *ifas, *ifa;
|
struct ifaddrs *ifas, *ifa;
|
||||||
bool found;
|
bool found;
|
||||||
|
@ -203,9 +170,18 @@ static bool get_intf_info(const char *intf, uint8_t *hwaddr, void *dummy)
|
||||||
|
|
||||||
found = false;
|
found = false;
|
||||||
|
|
||||||
|
if (bridge) {
|
||||||
|
*bridge = false;
|
||||||
|
}
|
||||||
|
|
||||||
for (ifa = ifas; ifa; ifa = ifa->ifa_next) {
|
for (ifa = ifas; ifa; ifa = ifa->ifa_next) {
|
||||||
if (!strcmp(ifa->ifa_name, intf)) {
|
if (!strcmp(ifa->ifa_name, intf)) {
|
||||||
if (sockaddr_get_hwaddr(ifa->ifa_addr, hwaddr)) {
|
if (sockaddr_get_hwaddr(ifa->ifa_addr, hwaddr)) {
|
||||||
|
#ifdef NMRPFLASH_BSD
|
||||||
|
if (bridge) {
|
||||||
|
*bridge = ((struct if_data*) ifa->ifa_data)->ifi_type == IFT_BRIDGE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -371,6 +347,7 @@ struct ethsock *ethsock_create(const char *intf, uint16_t protocol)
|
||||||
char buf[PCAP_ERRBUF_SIZE];
|
char buf[PCAP_ERRBUF_SIZE];
|
||||||
struct bpf_program fp;
|
struct bpf_program fp;
|
||||||
struct ethsock *sock;
|
struct ethsock *sock;
|
||||||
|
bool is_bridge;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
#ifdef NMRPFLASH_WINDOWS
|
#ifdef NMRPFLASH_WINDOWS
|
||||||
|
@ -406,7 +383,7 @@ struct ethsock *ethsock_create(const char *intf, uint16_t protocol)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NMRPFLASH_WINDOWS
|
#ifndef NMRPFLASH_WINDOWS
|
||||||
err = !get_intf_info(intf, sock->hwaddr, NULL);
|
err = !get_intf_info(intf, sock->hwaddr, &is_bridge);
|
||||||
#else
|
#else
|
||||||
err = !get_intf_info(intf, sock->hwaddr, &sock->index);
|
err = !get_intf_info(intf, sock->hwaddr, &sock->index);
|
||||||
#endif
|
#endif
|
||||||
|
@ -460,7 +437,7 @@ struct ethsock *ethsock_create(const char *intf, uint16_t protocol)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (is_bridge(intf)) {
|
if (is_bridge) {
|
||||||
fprintf(stderr, "Warning: bridge interfaces are not fully "
|
fprintf(stderr, "Warning: bridge interfaces are not fully "
|
||||||
"supported on this platform.\n");
|
"supported on this platform.\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue