}
#ifdef NMRPFLASH_LINUX
-static int open_stp_state(const char *intf)
+static int bridge_stp_state(const char *intf)
{
char name[256];
snprintf(name, sizeof(name), "/sys/class/net/%s/bridge/stp_state", intf);
return open(name, O_RDWR, 0644);
}
-static bool is_stp_enabled(const char *intf)
+static bool bridge_stp_enabled(const char *intf)
{
char c;
- int fd = open_stp_state(intf);
+ int fd = bridge_stp_state(intf);
if (fd == -1) {
return false;
}
return c == '1';
}
-static bool set_stp_enabled(const char *intf, bool enabled)
+static bool bridge_stp(const char *intf, bool enabled)
{
bool ret;
const char *s = enabled ? "1\n" : "0\n";
- int fd = open_stp_state(intf);
+ int fd = bridge_stp_state(intf);
if (fd == -1) {
return false;
}
}
#endif
-static bool get_intf_info(const char *intf, uint8_t *hwaddr, bool *bridge)
+static bool intf_get_info(const char *intf, uint8_t *hwaddr, bool *bridge)
{
struct ifaddrs *ifas, *ifa;
bool found;
}
}
-static bool get_intf_info(const char *intf, uint8_t *hwaddr, DWORD *index)
+static bool intf_get_info(const char *intf, uint8_t *hwaddr, DWORD *index)
{
PIP_ADAPTER_INFO adapters, adapter;
DWORD ret;
}
#ifndef NMRPFLASH_WINDOWS
- err = !get_intf_info(intf, sock->hwaddr, &is_bridge);
+ err = !intf_get_info(intf, sock->hwaddr, &is_bridge);
#else
- err = !get_intf_info(intf, sock->hwaddr, &sock->index);
+ err = !intf_get_info(intf, sock->hwaddr, &sock->index);
#endif
if (err) {
fprintf(stderr, "Failed to get interface info.\n");
#ifdef NMRPFLASH_LINUX
// nmrpflash does not work on bridge interfaces with STP enabled
- if ((sock->stp = is_stp_enabled(intf))) {
- if (!set_stp_enabled(intf, false)) {
+ if ((sock->stp = bridge_stp_enabled(intf))) {
+ if (!bridge_stp(intf, false)) {
fprintf(stderr, "Warning: failed to disable STP on %s.\n", intf);
}
}
#ifdef NMRPFLASH_LINUX
if (sock->stp) {
- set_stp_enabled(sock->intf, true);
+ bridge_stp(sock->intf, true);
}
#endif
if (sock->pcap) {
}
#endif
- return get_intf_info(dev->name, hwaddr, NULL);
+ return intf_get_info(dev->name, hwaddr, NULL);
}
int ethsock_list_all(void)
}
#ifndef NMRPFLASH_WINDOWS
-static bool set_interface_up(int fd, const char *intf, bool up)
+static bool intf_up(int fd, const char *intf, bool up)
{
struct ifreq ifr;
strncpy(ifr.ifr_name, intf, IFNAMSIZ);
return true;
}
-
#endif
int ethsock_ip_add(struct ethsock *sock, uint32_t ipaddr, uint32_t ipmask, struct ethsock_ip_undo **undo)
int ret = -1;
int fd = socket(AF_INET, SOCK_DGRAM, 0);
- if (!fd) {
+ if (fd < 0) {
sock_perror("socket");
goto out;
}
(*undo)->ip[1] = ipmask;
}
- if (!set_interface_up(fd, ifr.ifr_name, add)) {
+ if (!intf_up(fd, ifr.ifr_name, add)) {
goto out;
}
#else // NMRPFLASH_OSX (or any other BSD)
if (add) {
(*undo)->ip[0] = ipaddr;
(*undo)->ip[1] = ipmask;
- set_interface_up(fd, ifra.ifra_name, true);
+ intf_up(fd, ifra.ifra_name, true);
}
#endif