#include <stdio.h>
#include <string.h>
-#if defined(STDC_HEADERS)
#include <stdlib.h>
-#endif
-#if defined(HAVE_UNISTD_H)
#include <unistd.h>
-#endif
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/if.h>
#if defined(__FreeBSD__)
#if defined __FreeBSD_USE_KVM
-#if __FreeBSD_version >= 300001
#include <net/if_var.h>
-#endif
#include <kvm.h>
#include <nlist.h>
#include <sys/fcntl.h>
-#else
+#else /* !defined __FreeBSD_USE_KVM */
#include <sys/sysctl.h>
#include <net/route.h>
#include <net/if_dl.h>
-#endif
-#endif
+#endif /* defined __FreeBSD_USE_KVM */
+#endif /* defined __FreeBSD__ */
#include "socket.h"
-#include "i18n.h"
+#include "gettext.h"
#include "tunable.h"
typedef struct {
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
#define MONITOR_SLOP 5
#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);
char iname[16];
struct ifnet ifnet;
unsigned long ifnet_addr = ifnet_savedaddr;
-#if __FreeBSD_version >= 300001
struct ifnethead ifnethead;
struct ifaddrhead ifaddrhead;
-#endif
struct ifaddr ifaddr;
unsigned long ifaddr_addr;
struct sockaddr sa;
- unsigned long sa_addr;
uint i;
if (if_egid)
}
}
-#if __FreeBSD_version >= 300001
kvm_read(kvmfd, ifnet_savedaddr, (char *) &ifnethead, sizeof ifnethead);
ifnet_addr = (u_long) ifnethead.tqh_first;
-#else
- ifnet_addr = ifnet_savedaddr;
-#endif
while (ifnet_addr)
{
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))
{
ifinfo->rx_packets = ifnet.if_ipackets;
ifinfo->tx_packets = ifnet.if_opackets;
-#if __FreeBSD_version >= 300001
ifaddr_addr = (u_long) ifnet.if_addrhead.tqh_first;
-#else
- ifaddr_addr = (u_long) ifnet.if_addrlist;
-#endif
while(ifaddr_addr)
{
if (sa.sa_family != AF_INET)
{
-#if __FreeBSD_version >= 300001
ifaddr_addr = (u_long) ifaddr.ifa_link.tqe_next;
-#else
- ifaddr_addr = (u_long) ifaddr.ifa_next;
-#endif
continue;
}
return 0;
}
-#if __FreeBSD_version >= 300001
ifnet_addr = (u_long) ifnet.if_link.tqe_next;
-#else
- ifnet_addr = (unsigned long) ifnet.if_next;
-#endif
}
if (if_egid)
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 /* __FREEBSD_USE_SYSCTL_GET_IFFINFO */
-#else
-
-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