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:
1 parent
9886acfb49
commit
c7358581de
4 files changed
+30
-30
No files matched your search
@@ -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() */
|
||||
|
||||
|
||||
Reference in new issue
Block a user