fixes for the lcpdroc client iface screen on *BSD (M.Dolze):

1. If an interface priviously been UP goes DOWN, the time when the
   interface changed would always show the current time.
2. If an active interface is removed from the system, the server would
   still show the old screens and the user will not get any notice.
3. The "first run" detection would not work if more than one interface
   is monitored. Now the "last_online" time is used, because this is an
   "per interface" value initialized to 0 at startup.
4. The TRUE/FALSE macros are used for the return values as in the other
   functions.
This commit is contained in:
marschap
2007-09-20 09:06:51 +00:00
parent 9886acfb49
commit c7358581de
4 changed files with 30 additions and 30 deletions
+1
View File
@@ -23,6 +23,7 @@ v.0.5dev (ongoing development)
+ new driver shuttleVFD for USB-based Shuttle VFDs (Thien Vu)
* enable building lcdproc client on FreeBSD AMD64 platform (M. Dolze)
* Autoconf fixes for Net/FreeBSD (M. Dolze)
* fixes for the lcpdroc client iface screen on *BSD (M.Dolze)
v.0.5.2
* fix switching on/off the Load screen in lcdproc client using the menu
+10 -11
View File
@@ -479,7 +479,6 @@ static int swapmode(int *rettotal, int *retfree)
/* Get network statistics */
int machine_get_iface_stats (IfaceInfo *interface)
{
static int first_time = 1; /* is it first time we call this function? */
int rows;
int name[6] = {CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_SYSTEM, IFMIB_IFCOUNT};
size_t len;
@@ -487,7 +486,6 @@ int machine_get_iface_stats (IfaceInfo *interface)
len = sizeof(rows);
/* get number of interfaces */
//if (sysctlbyname("net.link.generic.system.ifcount", &rows, &len, NULL, 0) == 0) {
if (sysctl(name, 5, &rows, &len, 0, 0) == 0) {
interface->status = down; /* set status down by default */
@@ -506,31 +504,32 @@ int machine_get_iface_stats (IfaceInfo *interface)
}
/* check if its interface name matches */
if (strcmp(ifmd.ifmd_name, interface->name) == 0) {
interface->last_online = time(NULL); /* save actual time */
if ((ifmd.ifmd_flags & IFF_UP) == IFF_UP)
interface->status = up; /* is up */
interface->rc_byte = ifmd.ifmd_data.ifi_ibytes;
interface->tr_byte = ifmd.ifmd_data.ifi_obytes;
interface->rc_pkt = ifmd.ifmd_data.ifi_ipackets;
interface->tr_pkt = ifmd.ifmd_data.ifi_opackets;
if (first_time) {
if (interface->last_online == 0) {
interface->rc_byte_old = interface->rc_byte;
interface->tr_byte_old = interface->tr_byte;
interface->rc_pkt_old = interface->rc_pkt;
interface->tr_pkt_old = interface->tr_pkt;
first_time = 0; /* now it isn't first time */
}
return 1;
if ((ifmd.ifmd_flags & IFF_UP) == IFF_UP) {
interface->status = up; /* is up */
interface->last_online = time(NULL); /* save actual time */
}
return (TRUE);
}
}
/* if we are here there is no interface with the given name */
return 0;
return (TRUE);
} else {
perror("read sysctl IFMIB_IFCOUNT");
return 0;
return (FALSE);
}
} /* get_iface_stats() */
+10 -10
View File
@@ -439,7 +439,6 @@ static int swapmode(int *retavail, int *retfree)
*/
int machine_get_iface_stats (IfaceInfo *interface)
{
static int first_time = 1; /* is it first time we call this function? */
int rows;
int name[6] = {CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_IFDATA, 0, IFDATA_GENERAL};
size_t len;
@@ -461,31 +460,32 @@ int machine_get_iface_stats (IfaceInfo *interface)
}
/* check if its interface name matches */
if (strcmp(ifmd.ifmd_name, interface->name) == 0) {
interface->last_online = time(NULL); /* save actual time */
if ((ifmd.ifmd_flags & IFF_UP) == IFF_UP)
interface->status = up; /* is up */
interface->rc_byte = ifmd.ifmd_data.ifi_ibytes;
interface->tr_byte = ifmd.ifmd_data.ifi_obytes;
interface->rc_pkt = ifmd.ifmd_data.ifi_ipackets;
interface->tr_pkt = ifmd.ifmd_data.ifi_opackets;
if (first_time) {
if (interface->last_online == 0) {
interface->rc_byte_old = interface->rc_byte;
interface->tr_byte_old = interface->tr_byte;
interface->rc_pkt_old = interface->rc_pkt;
interface->tr_pkt_old = interface->tr_pkt;
first_time = 0; /* now it isn't first time */
}
return 1;
if ((ifmd.ifmd_flags & IFF_UP) == IFF_UP) {
interface->status = up; /* is up */
interface->last_online = time(NULL); /* save actual time */
}
return (TRUE);
}
}
/* if we are here there is no interface with the given name */
return 0;
return (TRUE);
} else {
perror("read sysctlbyname");
return 0;
return (FALSE);
}
} /* get_iface_stats() */
+9 -9
View File
@@ -380,7 +380,6 @@ int machine_get_uptime(double *up, double *idle)
/* Get network statistics */
int machine_get_iface_stats (IfaceInfo *interface)
{
static int first_time = 1; /* is it first time we call this function? */
struct ifaddrs *ifa, *ifa_ptr;
struct if_data *ifd;
@@ -397,30 +396,31 @@ int machine_get_iface_stats (IfaceInfo *interface)
(ifa_ptr->ifa_addr->sa_family == AF_LINK)) {
ifd = (struct if_data *)ifa_ptr->ifa_data;
interface->last_online = time(NULL); /* save actual time */
if ((ifa_ptr->ifa_flags & IFF_UP) == IFF_UP)
interface->status = up; /* is up */
interface->rc_byte = ifd->ifi_ibytes;
interface->tr_byte = ifd->ifi_obytes;
interface->rc_pkt = ifd->ifi_ipackets;
interface->tr_pkt = ifd->ifi_opackets;
if (first_time) {
if (interface->last_online == 0) {
interface->rc_byte_old = interface->rc_byte;
interface->tr_byte_old = interface->tr_byte;
interface->rc_pkt_old = interface->rc_pkt;
interface->tr_pkt_old = interface->tr_pkt;
first_time = 0; /* now it isn't first time */
}
return 1;
if ((ifa_ptr->ifa_flags & IFF_UP) == IFF_UP) {
interface->status = up; /* is up */
interface->last_online = time(NULL); /* save actual time */
}
return (TRUE);
}
}
freeifaddrs(ifa);
/* if we are here there is no interface with the given name */
return 0;
return (TRUE);
}
#endif /* __NetBSD__ */