Diff for /embedaddon/mtr/ui/report.c between versions 1.1.1.2 and 1.1.1.3

version 1.1.1.2, 2021/03/17 00:07:30 version 1.1.1.3, 2023/09/27 11:18:58
Line 43 Line 43
 #include "utils.h"  #include "utils.h"
   
 #define MAXLOADBAL 5  #define MAXLOADBAL 5
#define MAX_FORMAT_STR 81#define MAX_FORMAT_STR 320
   
   
 void report_open(  void report_open(
Line 65  static size_t snprint_addr( Line 65  static size_t snprint_addr(
         struct hostent *host =          struct hostent *host =
             ctl->dns ? addr2host((void *) addr, ctl->af) : NULL;              ctl->dns ? addr2host((void *) addr, ctl->af) : NULL;
         if (!host)          if (!host)
            return snprintf(dst, dst_len, "%s", strlongip(ctl, addr));            return snprintf(dst, dst_len, "%s", strlongip(ctl->af, addr));
         else if (ctl->dns && ctl->show_ips)          else if (ctl->dns && ctl->show_ips)
             return snprintf(dst, dst_len, "%s (%s)", host->h_name,              return snprintf(dst, dst_len, "%s (%s)", host->h_name,
                            strlongip(ctl, addr));                            strlongip(ctl->af, addr));
         else          else
             return snprintf(dst, dst_len, "%s", host->h_name);              return snprintf(dst, dst_len, "%s", host->h_name);
     } else      } else
Line 170  void report_close( Line 170  void report_close(
             if (j < 0)              if (j < 0)
                 continue;                  continue;
   
            /* 1000.0 is a temporay hack for stats usec to ms, impacted net_loss. */            /* 1000.0 is a temporary hack for stats usec to ms, impacted net_loss. */
             if (strchr(data_fields[j].format, 'f')) {              if (strchr(data_fields[j].format, 'f')) {
                 snprintf(buf + len, sizeof(buf), data_fields[j].format,                  snprintf(buf + len, sizeof(buf), data_fields[j].format,
                          data_fields[j].net_xxx(at) / 1000.0);                           data_fields[j].net_xxx(at) / 1000.0);
Line 215  void report_close( Line 215  void report_close(
             if (!found) {              if (!found) {
   
 #ifdef HAVE_IPINFO  #ifdef HAVE_IPINFO
                   if (mpls->labels && z == 1 && ctl->enablempls)
                       print_mpls(mpls);
                 if (is_printii(ctl)) {                  if (is_printii(ctl)) {
                     if (mpls->labels && z == 1 && ctl->enablempls)  
                         print_mpls(mpls);  
                     snprint_addr(ctl, name, sizeof(name), addr2);                      snprint_addr(ctl, name, sizeof(name), addr2);
                     printf("     %s%s\n", fmt_ipinfo(ctl, addr2), name);                      printf("     %s%s\n", fmt_ipinfo(ctl, addr2), name);
                     if (ctl->enablempls)  
                         print_mpls(mplss);  
                 }                  }
                   if (ctl->enablempls)
                       print_mpls(mplss);
 #else  #else
                 int k;                  int k;
                 if (mpls->labels && z == 1 && ctl->enablempls) {                  if (mpls->labels && z == 1 && ctl->enablempls) {
Line 235  void report_close( Line 235  void report_close(
                 }                  }
   
                 if (z == 1) {                  if (z == 1) {
                    printf("    |  `|-- %s\n", strlongip(ctl, addr2));                    printf("    |  `|-- %s\n", strlongip(ctl->af, addr2));
                     for (k = 0; k < mplss->labels && ctl->enablempls; k++) {                      for (k = 0; k < mplss->labels && ctl->enablempls; k++) {
                         printf                          printf
                             ("    |   +-- [MPLS: Lbl %lu TC %u S %u TTL %u]\n",                              ("    |   +-- [MPLS: Lbl %lu TC %u S %u TTL %u]\n",
Line 243  void report_close( Line 243  void report_close(
                              mplss->ttl[k]);                               mplss->ttl[k]);
                     }                      }
                 } else {                  } else {
                    printf("    |   |-- %s\n", strlongip(ctl, addr2));                    printf("    |   |-- %s\n", strlongip(ctl->af, addr2));
                     for (k = 0; k < mplss->labels && ctl->enablempls; k++) {                      for (k = 0; k < mplss->labels && ctl->enablempls; k++) {
                         printf                          printf
                             ("    |   +-- [MPLS: Lbl %lu TC %u S %u TTL %u]\n",                              ("    |   +-- [MPLS: Lbl %lu TC %u S %u TTL %u]\n",
Line 344  void json_close(struct mtr_ctl *ctl) Line 344  void json_close(struct mtr_ctl *ctl)
             goto on_error;              goto on_error;
   
 #ifdef HAVE_IPINFO  #ifdef HAVE_IPINFO
        if(!ctl->ipinfo_no) {        if (!ctl->ipinfo_no) {
             char* fmtinfo = fmt_ipinfo(ctl, addr);              char* fmtinfo = fmt_ipinfo(ctl, addr);
             if (fmtinfo != NULL)              if (fmtinfo != NULL)
                 fmtinfo = trim(fmtinfo, '\0');                  fmtinfo = trim(fmtinfo, '\0');
Line 385  void json_close(struct mtr_ctl *ctl) Line 385  void json_close(struct mtr_ctl *ctl)
     if (ret == -1)      if (ret == -1)
         goto on_error;          goto on_error;
   
    printf("\n"); // bash promt should be on new line    printf("\n"); // bash prompt should be on new line
     json_decref(jreport);      json_decref(jreport);
     return;      return;
 on_error:  on_error:
Line 447  void xml_close( Line 447  void xml_close(
                 title = "Loss";                  title = "Loss";
             }              }
   
            /* 1000.0 is a temporay hack for stats usec to ms, impacted net_loss. */            /* 1000.0 is a temporary hack for stats usec to ms, impacted net_loss. */
             if (strchr(data_fields[j].format, 'f')) {              if (strchr(data_fields[j].format, 'f')) {
                 printf(name,                  printf(name,
                        title, data_fields[j].net_xxx(at) / 1000.0, title);                         title, data_fields[j].net_xxx(at) / 1000.0, title);
Line 470  void csv_close( Line 470  void csv_close(
     struct mtr_ctl *ctl,      struct mtr_ctl *ctl,
     time_t now)      time_t now)
 {  {
    int i, j, at, max;    int i, j, at, max, z, w;
     ip_t *addr;      ip_t *addr;
       ip_t *addr2 = NULL;
     char name[MAX_FORMAT_STR];      char name[MAX_FORMAT_STR];
   
     for (i = 0; i < MAXFLD; i++) {      for (i = 0; i < MAXFLD; i++) {
Line 518  void csv_close( Line 519  void csv_close(
             if (j < 0)              if (j < 0)
                 continue;                  continue;
   
            /* 1000.0 is a temporay hack for stats usec to ms, impacted net_loss. */            /* 1000.0 is a temporary hack for stats usec to ms, impacted net_loss. */
             if (strchr(data_fields[j].format, 'f')) {              if (strchr(data_fields[j].format, 'f')) {
                 printf(",%.2f",                  printf(",%.2f",
                        (double) (data_fields[j].net_xxx(at) / 1000.0));                         (double) (data_fields[j].net_xxx(at) / 1000.0));
Line 527  void csv_close( Line 528  void csv_close(
             }              }
         }          }
         printf("\n");          printf("\n");
           if (ctl->reportwide == 0)
               continue;
           
           for (z = 0; z < MAX_PATH; z++) {
               int found = 0;
               addr2 = net_addrs(at, z);
               snprint_addr(ctl, name, sizeof(name), addr2);
               if ((addrcmp
                       ((void *) &ctl->unspec_addr, (void *) addr2,
                        ctl->af)) == 0) {
                   break;
               } else if ((addrcmp
                       ((void *) addr, (void *) addr2,
                        ctl->af)) == 0) {
                   continue; /* Latest Host is already printed */
               } else {
                   for (w = 0; w < z; w++)
                       /* Ok... checking if there are ips repeated on same hop */
                       if ((addrcmp
                               ((void *) addr2, (void *) net_addrs(at, w),
                                ctl->af)) == 0) {
                           found = 1;
                           break;
                       }
   
                   if (!found) {
   #ifdef HAVE_IPINFO
                       if (!ctl->ipinfo_no) {
                           char *fmtinfo = fmt_ipinfo(ctl, addr2);
                           fmtinfo = trim(fmtinfo, '\0');
                           printf("MTR.%s,%lld,%s,%s,%d,%s,%s", PACKAGE_VERSION,
                               (long long) now, "OK", ctl->Hostname, at + 1, name,
                               fmtinfo);
                       } else
   #endif
                           printf("MTR.%s,%lld,%s,%s,%d,%s", PACKAGE_VERSION,
                              (long long) now, "OK", ctl->Hostname, at + 1, name);
   
                       /* Use values associated with the first ip discovered for this hop */
                       for (i = 0; i < MAXFLD; i++) {
                           j = ctl->fld_index[ctl->fld_active[i]];
                           if (j < 0)
                               continue;
   
                           /* 1000.0 is a temporary hack for stats usec to ms, impacted net_loss. */
                           if (strchr(data_fields[j].format, 'f')) {
                               printf(",%.2f",
                                      (double) (data_fields[j].net_xxx(at) / 1000.0));
                           } else {
                               printf(",%d", data_fields[j].net_xxx(at));
                           }
                       }
                       printf("\n");
                   }
               }    
           }
     }      }
 }  }

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


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