X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Ftop.c;h=fe6f384eb2698a016903e101f6c92b49d7864c8c;hb=18646deca120f0ccc3bfad643dba83547ecc2f20;hp=2824261c2a2a94e5de48d3ce67ef8a623d9b93ac;hpb=f134bd0c9c2213fbbb3967f3d784759cb65e2c76;p=tinc diff --git a/src/top.c b/src/top.c index 2824261c..fe6f384e 100644 --- a/src/top.c +++ b/src/top.c @@ -21,6 +21,7 @@ #ifdef HAVE_CURSES +#undef KEY_EVENT /* There are conflicting declarations for KEY_EVENT in Windows wincon.h and curses.h. */ #include #include "control_common.h" @@ -89,7 +90,7 @@ static bool update(int fd) { ns->known = false; while(recvline(fd, line, sizeof line)) { - int n = sscanf(line, "%d %d %s %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64, &code, &req, name, &in_packets, &in_bytes, &out_packets, &out_bytes); + int n = sscanf(line, "%d %d %4095s %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64, &code, &req, name, &in_packets, &in_bytes, &out_packets, &out_bytes); if(n == 2) return true; @@ -157,40 +158,47 @@ static int cmpu64(uint64_t a, uint64_t b) { static int sortfunc(const void *a, const void *b) { const nodestats_t *na = *(const nodestats_t **)a; const nodestats_t *nb = *(const nodestats_t **)b; + int result; + switch(sortmode) { case 1: if(cumulative) - return -cmpu64(na->in_packets, nb->in_packets) ?: na->i - nb->i; + result = -cmpu64(na->in_packets, nb->in_packets); else - return -cmpfloat(na->in_packets_rate, nb->in_packets_rate) ?: na->i - nb->i; + result = -cmpfloat(na->in_packets_rate, nb->in_packets_rate); case 2: if(cumulative) - return -cmpu64(na->in_bytes, nb->in_bytes) ?: na->i - nb->i; + result = -cmpu64(na->in_bytes, nb->in_bytes); else - return -cmpfloat(na->in_bytes_rate, nb->in_bytes_rate) ?: na->i - nb->i; + result = -cmpfloat(na->in_bytes_rate, nb->in_bytes_rate); case 3: if(cumulative) - return -cmpu64(na->out_packets, nb->out_packets) ?: na->i - nb->i; + result = -cmpu64(na->out_packets, nb->out_packets); else - return -cmpfloat(na->out_packets_rate, nb->out_packets_rate) ?: na->i - nb->i; + result = -cmpfloat(na->out_packets_rate, nb->out_packets_rate); case 4: if(cumulative) - return -cmpu64(na->out_bytes, nb->out_bytes) ?: na->i - nb->i; + result = -cmpu64(na->out_bytes, nb->out_bytes); else - return -cmpfloat(na->out_bytes_rate, nb->out_bytes_rate) ?: na->i - nb->i; + result = -cmpfloat(na->out_bytes_rate, nb->out_bytes_rate); case 5: if(cumulative) - return -cmpu64(na->in_packets + na->out_packets, nb->in_packets + nb->out_packets) ?: na->i - nb->i; + result = -cmpu64(na->in_packets + na->out_packets, nb->in_packets + nb->out_packets); else - return -cmpfloat(na->in_packets_rate + na->out_packets_rate, nb->in_packets_rate + nb->out_packets_rate) ?: na->i - nb->i; + result = -cmpfloat(na->in_packets_rate + na->out_packets_rate, nb->in_packets_rate + nb->out_packets_rate); case 6: if(cumulative) - return -cmpu64(na->in_bytes + na->out_bytes, nb->in_bytes + nb->out_bytes) ?: na->i - nb->i; + result = -cmpu64(na->in_bytes + na->out_bytes, nb->in_bytes + nb->out_bytes); else - return -cmpfloat(na->in_bytes_rate + na->out_bytes_rate, nb->in_bytes_rate + nb->out_bytes_rate) ?: na->i - nb->i; + result = -cmpfloat(na->in_bytes_rate + na->out_bytes_rate, nb->in_bytes_rate + nb->out_bytes_rate); default: - return strcmp(na->name, nb->name) ?: na->i - nb->i; + result = strcmp(na->name, nb->name); } + + if(result) + return result; + else + return na->i - nb->i; } static void redraw(void) {