commit - 2569c5975ff446cdbf528a05abed3e3ee296ef1c
commit + 9f394d72aa5b45a32842a3a1c5cddcc6d88f0c53
blob - 735cfe0d446799766b75ab6ebef37a4c30facada
blob + 91f57b6d8cef13d1e482000d62f9e7a576e5f42a
--- modules/network.c
+++ modules/network.c
char network_string[7];
-static char ethernet_device[IF_NAMESIZE];
-static char wifi_device[IF_NAMESIZE];
+static int ethernet_device;
+static int wifi_device;
bool
init_network_socket(int *fd)
read_network_socket(int fd)
{
char buf[1024];
- char ifname[IF_NAMESIZE];
struct rt_msghdr *rtm;
struct if_msghdr *ifm;
ssize_t n;
if (rtm->rtm_type != RTM_IFINFO) return;
ifm = (struct if_msghdr *)buf;
- if (if_indextoname(ifm->ifm_index, ifname) == NULL)
- {
- (void)fprintf(stderr, "No name assosiated with index %u\n", ifm->ifm_index);
-
- return;
- }
if (!LINK_STATE_IS_UP(ifm->ifm_data.ifi_link_state))
{
network_string[0] = '\0';
return;
}
- if (strcmp(ifname, ethernet_device) == 0) (void)snprintf(network_string, 7, "%s ", ETHERNET);
- else if (strcmp(ifname, wifi_device) == 0) (void)snprintf(network_string, 7, "%s ", WIFI);
+ if (ifm->ifm_index == ethernet_device) (void)snprintf(network_string, 7, "%s ", ETHERNET);
+ else if (ifm->ifm_index == wifi_device) (void)snprintf(network_string, 7, "%s ", WIFI);
}
void
get_initial_network_state(void)
{
int mib[6];
- char ifname[IF_NAMESIZE];
char *buf;
char *next;
char *end;
if (rtm->rtm_type != RTM_IFINFO) continue;
ifm = (struct if_msghdr *)next;
- if (if_indextoname(ifm->ifm_index, ifname) == NULL)
- {
- (void)fprintf(stderr, "No name assosiated with index %u\n", ifm->ifm_index);
-
- continue;
- }
if (!LINK_STATE_IS_UP(ifm->ifm_data.ifi_link_state))
{
network_string[0] = '\0';
continue;
}
- if (strcmp(ifname, wifi_device) == 0) (void)snprintf(network_string, 7, "%s ", WIFI);
- if (strcmp(ifname, ethernet_device) == 0) (void)snprintf(network_string, 7, "%s ", ETHERNET);
+ if (ifm->ifm_index == wifi_device) (void)snprintf(network_string, 7, "%s ", WIFI);
+ if (ifm->ifm_index == ethernet_device) (void)snprintf(network_string, 7, "%s ", ETHERNET);
}
free(buf);
void set_ethernet_device(char *dev)
{
- (void)strlcpy(ethernet_device, dev, IF_NAMESIZE);
+ ethernet_device = if_nametoindex(dev);
}
void set_wifi_device(char *dev)
{
- (void)strlcpy(wifi_device, dev, IF_NAMESIZE);
+ wifi_device = if_nametoindex(dev);
}