Diff for /embedaddon/mtr/ui/curses.c between versions 1.1 and 1.1.1.3

version 1.1, 2019/10/21 14:25:31 version 1.1.1.3, 2023/09/27 11:18:58
Line 3 Line 3
     Copyright (C) 1997,1998  Matt Kimball      Copyright (C) 1997,1998  Matt Kimball
   
     This program is free software; you can redistribute it and/or modify      This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License version 2 as     it under the terms of the GNU General Public License version 2 as
     published by the Free Software Foundation.      published by the Free Software Foundation.
   
     This program is distributed in the hope that it will be useful,      This program is distributed in the hope that it will be useful,
Line 11 Line 11
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.      GNU General Public License for more details.
   
    You should have received a copy of the GNU General Public License    You should have received a copy of the GNU General Public License along
    along with this program; if not, write to the Free Software    with this program; if not, write to the Free Software Foundation, Inc.,
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */  */
   
 #include "config.h"  #include "config.h"
Line 157  int mtr_curses_keyaction( Line 157  int mtr_curses_keyaction(
   
     switch (c) {      switch (c) {
     case 'q':      case 'q':
       case -1:
     case 3:      case 3:
         return ActionQuit;          return ActionQuit;
     case 12:      case 12:
Line 235  int mtr_curses_keyaction( Line 236  int mtr_curses_keyaction(
   
         if (f <= 0.0)          if (f <= 0.0)
             return ActionNone;              return ActionNone;
        if (getuid() != 0 && f < 1.0)        if (!running_as_root() && (f < 1.0))
             return ActionNone;              return ActionNone;
         ctl->WaitTime = f;          ctl->WaitTime = f;
   
Line 363  int mtr_curses_keyaction( Line 364  int mtr_curses_keyaction(
             ("  b <c>   set ping bit pattern to c(0..255) or random(c<0)\n");              ("  b <c>   set ping bit pattern to c(0..255) or random(c<0)\n");
         printw("  Q <t>   set ping packet's TOS to t\n");          printw("  Q <t>   set ping packet's TOS to t\n");
         printw("  u       switch between ICMP ECHO and UDP datagrams\n");          printw("  u       switch between ICMP ECHO and UDP datagrams\n");
           printw("  t       switch between ICMP ECHO and TCP\n");
 #ifdef HAVE_IPINFO  #ifdef HAVE_IPINFO
         printw("  y       switching IP info\n");          printw("  y       switching IP info\n");
         printw("  z       toggle ASN info on/off\n");          printw("  z       toggle ASN info on/off\n");
Line 388  static void format_field( Line 390  static void format_field(
         format_number(n, 5, dst);          format_number(n, 5, dst);
     } else if (strchr(format, 'f')) {      } else if (strchr(format, 'f')) {
         /* this is for fields where we measure integer microseconds but          /* this is for fields where we measure integer microseconds but
           display floating point miliseconds. Convert to float here. */           display floating point milliseconds. Convert to float here. */
         snprintf(dst, dst_length, format, n / 1000.0);          snprintf(dst, dst_length, format, n / 1000.0);
         /* this was marked as a temporary hack over 10 years ago. -- REW */          /* this was marked as a temporary hack over 10 years ago. -- REW */
     } else {      } else {
Line 404  static void mtr_curses_hosts( Line 406  static void mtr_curses_hosts(
     int at;      int at;
     struct mplslen *mpls, *mplss;      struct mplslen *mpls, *mplss;
     ip_t *addr, *addrs;      ip_t *addr, *addrs;
       int addrcmp_result;
       int err;
     int y;      int y;
     char *name;      char *name;
   
Line 416  static void mtr_curses_hosts( Line 420  static void mtr_curses_hosts(
   
     for (at = net_min(ctl) + ctl->display_offset; at < max; at++) {      for (at = net_min(ctl) + ctl->display_offset; at < max; at++) {
         printw("%2d. ", at + 1);          printw("%2d. ", at + 1);
           err = net_err(at);
         addr = net_addr(at);          addr = net_addr(at);
         mpls = net_mpls(at);          mpls = net_mpls(at);
   
        if (addrcmp((void *) addr, (void *) &ctl->unspec_addr, ctl->af) !=        addrcmp_result = addrcmp(addr, &ctl->unspec_addr, ctl->af);
            0) {
         if (err == 0 && addrcmp_result != 0) {
             name = dns_lookup(ctl, addr);              name = dns_lookup(ctl, addr);
             if (!net_up(at))              if (!net_up(at))
                 attron(A_BOLD);                  attron(A_BOLD);
 #ifdef HAVE_IPINFO  #ifdef HAVE_IPINFO
             if (is_printii(ctl))              if (is_printii(ctl))
                printw(fmt_ipinfo(ctl, addr));                printw("%s", fmt_ipinfo(ctl, addr));
 #endif  #endif
             if (name != NULL) {              if (name != NULL) {
                 if (ctl->show_ips)                  if (ctl->show_ips)
                    printw("%s (%s)", name, strlongip(ctl, addr));                    printw("%s (%s)", name, strlongip(ctl->af, addr));
                 else                  else
                     printw("%s", name);                      printw("%s", name);
             } else {              } else {
                printw("%s", strlongip(ctl, addr));                printw("%s", strlongip(ctl->af, addr));
             }              }
             attroff(A_BOLD);              attroff(A_BOLD);
   
Line 445  static void mtr_curses_hosts( Line 451  static void mtr_curses_hosts(
             hd_len = 0;              hd_len = 0;
             for (i = 0; i < MAXFLD; i++) {              for (i = 0; i < MAXFLD; i++) {
                 /* Ignore options that don't exist */                  /* Ignore options that don't exist */
                /* On the other hand, we now check the input side. Shouldn't happen,                 /* On the other hand, we now check the input side. Shouldn't happen,
                    can't be careful enough. */                     can't be careful enough. */
                 j = ctl->fld_index[ctl->fld_active[i]];                  j = ctl->fld_index[ctl->fld_active[i]];
                 if (j == -1)                  if (j == -1)
Line 459  static void mtr_curses_hosts( Line 465  static void mtr_curses_hosts(
             printw("%s", buf);              printw("%s", buf);
   
             for (k = 0; k < mpls->labels && ctl->enablempls; k++) {              for (k = 0; k < mpls->labels && ctl->enablempls; k++) {
                printw("\n    [MPLS: Lbl %lu Exp %u S %u TTL %u]",                printw("\n    [MPLS: Lbl %lu TC %u S %u TTL %u]",
                       mpls->label[k], mpls->exp[k], mpls->s[k],                       mpls->label[k], mpls->tc[k], mpls->s[k],
                        mpls->ttl[k]);                         mpls->ttl[k]);
             }              }
   
             /* Multi path */              /* Multi path */
            for (i = 0; i < MAXPATH; i++) {            for (i = 0; i < MAX_PATH; i++) {
                 addrs = net_addrs(at, i);                  addrs = net_addrs(at, i);
                 mplss = net_mplss(at, i);                  mplss = net_mplss(at, i);
                if (addrcmp((void *) addrs, (void *) addr, ctl->af) == 0)                if (addrcmp(addrs, addr, ctl->af) == 0)
                     continue;                      continue;
                if (addrcmp                if (addrcmp(addrs, &ctl->unspec_addr,ctl->af) == 0)
                    ((void *) addrs, (void *) &ctl->unspec_addr, 
                     ctl->af) == 0) 
                     break;                      break;
   
                 name = dns_lookup(ctl, addrs);                  name = dns_lookup(ctl, addrs);
Line 481  static void mtr_curses_hosts( Line 485  static void mtr_curses_hosts(
                 printw("\n    ");                  printw("\n    ");
 #ifdef HAVE_IPINFO  #ifdef HAVE_IPINFO
                 if (is_printii(ctl))                  if (is_printii(ctl))
                    printw(fmt_ipinfo(ctl, addrs));                    printw("%s", fmt_ipinfo(ctl, addrs));
 #endif  #endif
                 if (name != NULL) {                  if (name != NULL) {
                     if (ctl->show_ips)                      if (ctl->show_ips)
                        printw("%s (%s)", name, strlongip(ctl, addrs));                        printw("%s (%s)", name, strlongip(ctl->af, addrs));
                     else                      else
                         printw("%s", name);                          printw("%s", name);
                 } else {                  } else {
                    printw("%s", strlongip(ctl, addrs));                    printw("%s", strlongip(ctl->af, addrs));
                 }                  }
                 for (k = 0; k < mplss->labels && ctl->enablempls; k++) {                  for (k = 0; k < mplss->labels && ctl->enablempls; k++) {
                    printw("\n    [MPLS: Lbl %lu Exp %u S %u TTL %u]",                    printw("\n    [MPLS: Lbl %lu TC %u S %u TTL %u]",
                           mplss->label[k], mplss->exp[k], mplss->s[k],                           mplss->label[k], mplss->tc[k], mplss->s[k],
                            mplss->ttl[k]);                             mplss->ttl[k]);
                 }                  }
                 attroff(A_BOLD);                  attroff(A_BOLD);
             }              }
   
         } else {          } else {
            printw("???");            attron(A_BOLD);
             printw("(%s)", host_error_to_string(err));
             attroff(A_BOLD);
         }          }
   
         printw("\n");          printw("\n");
Line 618  static void mtr_curses_graph( Line 623  static void mtr_curses_graph(
     int startstat,      int startstat,
     int cols)      int cols)
 {  {
    int max, at, y;    int max, at, y, err;
     ip_t *addr;      ip_t *addr;
     char *name;      char *name;
     int __unused_int ATTRIBUTE_UNUSED;      int __unused_int ATTRIBUTE_UNUSED;
Line 629  static void mtr_curses_graph( Line 634  static void mtr_curses_graph(
         printw("%2d. ", at + 1);          printw("%2d. ", at + 1);
   
         addr = net_addr(at);          addr = net_addr(at);
           err = net_err(at);
   
         if (!addr) {          if (!addr) {
            printw("???\n");            printw("(%s)", host_error_to_string(err));
             continue;              continue;
         }          }
   
        if (!net_up(at))        if (err == 0
            attron(A_BOLD);            && addrcmp(addr, &ctl->unspec_addr, ctl->af)) {
        if (addrcmp((void *) addr, (void *) &ctl->unspec_addr, ctl->af)) {
             if (!net_up(at)) {
                 attron(A_BOLD);
             }
 
 #ifdef HAVE_IPINFO  #ifdef HAVE_IPINFO
             if (is_printii(ctl))              if (is_printii(ctl))
                printw(fmt_ipinfo(ctl, addr));                printw("%s", fmt_ipinfo(ctl, addr));
 #endif  #endif
             name = dns_lookup(ctl, addr);              name = dns_lookup(ctl, addr);
            printw("%s", name ? name : strlongip(ctl, addr));            printw("%s", name ? name : strlongip(ctl->af, addr));
        } else        } else {
            printw("???");            attron(A_BOLD);
             printw("(%s)", host_error_to_string(err));
         }
 
         attroff(A_BOLD);          attroff(A_BOLD);
   
         getyx(stdscr, y, __unused_int);          getyx(stdscr, y, __unused_int);
Line 684  void mtr_curses_redraw( Line 698  void mtr_curses_redraw(
     pwcenter(buf);      pwcenter(buf);
     attroff(A_BOLD);      attroff(A_BOLD);
   
    mvprintw(1, 0, "%s (%s)", ctl->LocalHostname, net_localaddr());    mvprintw(1, 0, "%s (%s) -> %s (%s)",
         ctl->LocalHostname, net_localaddr(),
         ctl->Hostname, net_remoteaddr());
     t = time(NULL);      t = time(NULL);
    mvprintw(1, maxx - 25, iso_time(&t));    mvprintw(1, maxx - 25, "%s", iso_time(&t));
     printw("\n");      printw("\n");
   
     printw("Keys:  ");      printw("Keys:  ");
Line 746  void mtr_curses_redraw( Line 762  void mtr_curses_redraw(
         startstat = padding - 2;          startstat = padding - 2;
   
         snprintf(msg, sizeof(msg), " Last %3d pings", max_cols);          snprintf(msg, sizeof(msg), " Last %3d pings", max_cols);
        mvprintw(rowstat - 1, startstat, msg);        mvprintw(rowstat - 1, startstat, "%s", msg);
   
         attroff(A_BOLD);          attroff(A_BOLD);
         move(rowstat, 0);          move(rowstat, 0);

Removed from v.1.1  
changed lines
  Added in v.1.1.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>