struct in_addr interface_mask;
} *interface_pair;
-static char *netdevfmt;
-
/*
* Count of packets to see on an interface before monitor considers it up.
* Needed because when pppd shuts down the link, the packet counts go up
#ifdef linux
#define have_interface_init
+static const char *netdevfmt;
+
void interface_init(void)
/* figure out which /proc/net/dev format to use */
{
result = FALSE;
else
{
- char *sp = strchr(ifname, '/');
-
+ char *tmp = xstrdup(ifname);
+ char *sp = strchr(tmp, '/');
+ /* hide slash and trailing info from ifname */
if (sp)
*sp = '\0';
- result = _get_ifinfoGT_(socket_fd, stats_file, ifname, ifinfo);
- if (sp)
- *sp = '/';
+ result = _get_ifinfoGT_(socket_fd, stats_file, tmp, ifinfo);
+ free(tmp);
}
if (socket_fd >= 0)
SockClose(socket_fd);
{
kvm_read(kvmfd, ifnet_addr, &ifnet, sizeof(ifnet));
kvm_read(kvmfd, (unsigned long) ifnet.if_name, tname, sizeof tname);
- snprintf(tname, sizeof tname, "%s%d", tname, ifnet.if_unit);
+ snprintf(tname + strlen(tname), sizeof(tname) - strlen(tname), "%d", ifnet.if_unit);
if (!strcmp(tname, iname))
{
char iname[16];
int mib[6];
- memset(ifinfo, 0, sizeof(ifinfo));
+ memset(ifinfo, 0, sizeof(*ifinfo));
/* trim interface name */
GT_("get_ifinfo: sysctl (iflist estimate) failed"));
exit(1);
}
- if ((buf = malloc(needed)) == NULL)
+ if ((buf = (char *)malloc(needed)) == NULL)
{
report(stderr,
GT_("get_ifinfo: malloc failed"));
}
sin = (struct sockaddr_in *)info.rti_info[RTAX_NETMASK];
- if (!sin)
+ if (sin)
{
ifinfo->netmask = sin->sin_addr;
}
* of non point-to-point link
*/
sin = (struct sockaddr_in *)info.rti_info[RTAX_BRD];
- if (!sin)
+ if (sin)
{
ifinfo->dstaddr = sin->sin_addr;
}
#endif
-#ifndef have_interface_init
-void interface_init(void) {};
-#endif
-
-
#ifndef HAVE_INET_ATON
/*
* Note: This is not a true replacement for inet_aton(), as it won't
/* parse 'interface' specification */
{
char *cp1, *cp2;
+ char mask1[] = "255.255.255.255";
hp->interface = xstrdup(buf);
/* find and isolate just the netmask */
if (!(cp2 = strchr(cp1, '/')))
- cp2 = "255.255.255.255";
+ cp2 = mask1;
else
*cp2++ = '\000';
return(TRUE);
}
#endif /* CAN_MONITOR */
+
+#ifndef have_interface_init
+void interface_init(void) {}
+#endif