[Olsr-cvs] olsrd-current/lib/httpinfo/src olsrd_httpinfo.c, 1.61, 1.62 olsrd_plugin.c, 1.13, 1.14 olsrd_plugin.h, 1.21, 1.22

Bernd Petrovitsch (spam-protected)
Tue Apr 3 00:22:28 CEST 2007


Update of /cvsroot/olsrd/olsrd-current/lib/httpinfo/src
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv25929/lib/httpinfo/src

Modified Files:
	olsrd_httpinfo.c olsrd_plugin.c olsrd_plugin.h 
Log Message:
* Added an option to activate reverse resolving the hostnames
  Activate it at your own risk!
* Fixup the HTML - at least partly.


Index: olsrd_httpinfo.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/httpinfo/src/olsrd_httpinfo.c,v
retrieving revision 1.61
retrieving revision 1.62
diff -C2 -d -r1.61 -r1.62
*** olsrd_httpinfo.c	4 Feb 2007 22:37:36 -0000	1.61
--- olsrd_httpinfo.c	2 Apr 2007 22:22:25 -0000	1.62
***************
*** 50,53 ****
--- 50,54 ----
  #include <unistd.h>
  #include <errno.h>
+ #include <netdb.h>
  
  #include "olsr.h"
***************
*** 706,710 ****
--- 707,770 ----
  }
  
+ static int
+ build_ip_txt(char *buf, const olsr_u32_t bufsize, const olsr_bool want_link, const char * const ipstr, const char  * const maskstr);
+ static int
+ build_ip_txt(char *buf, const olsr_u32_t bufsize, const olsr_bool want_link, const char * const ipstr, const char  * const maskstr)
+ {
+   int size = 0;
+   if (want_link && maskstr == NULL) { /* Print the link only if there is not netmask */
+     size += sprintf(&buf[size],
+                     "<a href=\"http://%s:%d/all\">",
+                     ipstr,
+                     http_port);
+   }
+   size += sprintf(&buf[size], "%s", ipstr);
+   if (maskstr) {
+     size += sprintf(&buf[size], "/%s", maskstr);
+   }
+   if (want_link && maskstr == NULL) { /* Print the link only if there is not netmask */
+     size += sprintf(&buf[size], "</a>");
+   }
+   return size;
+ }
  
+ static int
+ build_ipaddr_link(char *buf, const olsr_u32_t bufsize, const olsr_bool want_link, union olsr_ip_addr * const ipaddr, const union hna_netmask * const mask);
+ static int
+ build_ipaddr_link(char *buf, const olsr_u32_t bufsize, const olsr_bool want_link, union olsr_ip_addr * const ipaddr, const union hna_netmask * const mask)
+ {
+   int size = 0;
+   char maskbuf[32];
+   char *maskstr;
+   const struct hostent * const hp = resolve_ip_addresses ? gethostbyaddr(ipaddr, olsr_cnf->ipsize, olsr_cnf->ip_version) : NULL;
+   if (mask != NULL) {
+     if (olsr_cnf->ip_version == AF_INET) {
+       if (mask->v4 == ~0U) {
+         maskstr = NULL;
+       } else {
+         struct in_addr in;
+         in.s_addr = mask->v4;
+         snprintf(maskbuf, sizeof(maskbuf), "%s", inet_ntoa(in));
+         maskstr = maskbuf;
+       }
+     } else {
+       snprintf(maskbuf, sizeof(maskbuf), "%d", mask->v6);
+       maskstr = maskbuf;
+     }
+   } else {
+     maskstr =  NULL;
+   }
+   size += sprintf(&buf[size], "<td%s>", resolve_ip_addresses && hp ? "" : " colspan=\"2\"");
+   size += build_ip_txt(&buf[size], bufsize, want_link, olsr_ip_to_string(ipaddr), maskstr);
+   if (hp) {
+     size += sprintf(&buf[size], "</td><td>(");
+     size += build_ip_txt(&buf[size], bufsize, want_link, hp->h_name, NULL);
+     size += sprintf(&buf[size], ")");
+   }
+   size += sprintf(&buf[size], "</td>");
+   return size;
+ }
+ #define build_ipaddr_with_link(buf, bufsize, ipaddr, mask) build_ipaddr_link((buf), (bufsize), OLSR_TRUE, (ipaddr), (mask))
+ #define build_ipaddr_no_link(buf, bufsize, ipaddr, mask)   build_ipaddr_link((buf), (bufsize), OLSR_FALSE, (ipaddr), (mask))
  
  int
***************
*** 716,720 ****
    size += sprintf(&buf[size], "<h2>OLSR routes in kernel</h2>\n");
  
!   size += sprintf(&buf[size], "<table width=\"100%%\" BORDER=0 CELLSPACING=0 CELLPADDING=0 ALIGN=center><tr><th>Destination</th><th>Gateway</th><th>Metric</th>");
    if (olsr_cnf->lq_level > 0)
      size += sprintf(&buf[size], "<th>ETX</th>");
--- 776,781 ----
    size += sprintf(&buf[size], "<h2>OLSR routes in kernel</h2>\n");
  
!   size += sprintf(&buf[size], "<table width=\"100%%\" BORDER=0 CELLSPACING=0 CELLPADDING=0 ALIGN=center><tr><th%s>Destination</th><th>Gateway</th><th>Metric</th>",
!                   resolve_ip_addresses ? " colspan=\"2\"" : "");
    if (olsr_cnf->lq_level > 0)
      size += sprintf(&buf[size], "<th>ETX</th>");
***************
*** 728,744 ****
  	  routes = routes->next)
  	{
! 	  size += sprintf(&buf[size],
!                          "<tr><td><a href=\"http://%s:%d/all\">%s</a></td>"
!                          "<td><a href=\"http://%s:%d/all\">%s</a></td>"
!                          "<td>%d</td>",
!                          olsr_ip_to_string(&routes->rt_dst),
!                          http_port,
!                          olsr_ip_to_string(&routes->rt_dst),
!                          olsr_ip_to_string(&routes->rt_router),
!                          http_port,
!                          olsr_ip_to_string(&routes->rt_router),
!                          routes->rt_metric);
            if (olsr_cnf->lq_level > 0)
! 	    size += sprintf(&buf[size], "<td>%.2f</td>", routes->rt_etx);
  	  size += sprintf(&buf[size],
                           "<td>%s</td>"
--- 789,799 ----
  	  routes = routes->next)
  	{
!           size += sprintf(&buf[size], "<tr>");
! 	  size += build_ipaddr_with_link(&buf[size], bufsize - size, &routes->rt_dst, NULL);
! 	  size += build_ipaddr_with_link(&buf[size], bufsize - size, &routes->rt_router, NULL);
! 
! 	  size += sprintf(&buf[size], "<td align=\"right\">%d</td>", routes->rt_metric);
            if (olsr_cnf->lq_level > 0)
!             size += sprintf(&buf[size], "<td align=\"right\">%.2f</td>", routes->rt_etx);
  	  size += sprintf(&buf[size],
                           "<td>%s</td>"
***************
*** 755,769 ****
  	  routes = routes->next)
  	{
  	  size += sprintf(&buf[size],
!                          "<tr><td>%s</td>"
!                          "<td><a href=\"http://%s:%d/all\">%s</a></td>"
!                          "<td>%d</td>",
!                          olsr_ip_to_string(&routes->rt_dst),
!                          olsr_ip_to_string(&routes->rt_router),
!                          http_port,
!                          olsr_ip_to_string(&routes->rt_router),
                           routes->rt_metric);
            if (olsr_cnf->lq_level > 0)
! 	    size += sprintf(&buf[size], "<td>%.2f</td>", routes->rt_etx);
  	  size += sprintf(&buf[size],
                           "<td>%s</td>"
--- 810,821 ----
  	  routes = routes->next)
  	{
+           size += sprintf(&buf[size], "<tr>");
+ 	  size += build_ipaddr_with_link(&buf[size], bufsize - size, &routes->rt_dst, &routes->rt_mask);
+ 	  size += build_ipaddr_with_link(&buf[size], bufsize - size, &routes->rt_router, NULL);
  	  size += sprintf(&buf[size],
!                          "<td align=\"right\">%d</td>",
                           routes->rt_metric);
            if (olsr_cnf->lq_level > 0)
! 	    size += sprintf(&buf[size], "<td align=\"right\">%.2f</td>", routes->rt_etx);
  	  size += sprintf(&buf[size],
                           "<td>%s</td>"
***************
*** 950,955 ****
  	
  	size += sprintf(&buf[size], "</table>\n");
!       }
!     else if((olsr_cnf->ip_version == AF_INET6) && (olsr_cnf->hna6_entries))
        {
  	struct hna6_entry *hna6;
--- 1002,1007 ----
  	
  	size += sprintf(&buf[size], "</table>\n");
!       } 
!    else if((olsr_cnf->ip_version == AF_INET6) && (olsr_cnf->hna6_entries))
        {
  	struct hna6_entry *hna6;
***************
*** 983,987 ****
  
    size += sprintf(&buf[size], "<h2>Links</h2>\n");
!   size += sprintf(&buf[size], "<table width=\"100%%\" BORDER=0 CELLSPACING=0 CELLPADDING=0 ALIGN=center><tr><th>Local IP</th><th>remote IP</th><th>Hysteresis</th>\n");
    if (olsr_cnf->lq_level > 0)
      size += sprintf(&buf[size], "<th>LinkQuality</th><th>lost</th><th>total</th><th>NLQ</th><th>ETX</th>\n");
--- 1035,1039 ----
  
    size += sprintf(&buf[size], "<h2>Links</h2>\n");
!   size += sprintf(&buf[size], "<table width=\"100%%\" BORDER=0 CELLSPACING=0 CELLPADDING=0 ALIGN=center><tr><th>Local IP</th><th>Remote IP</th><th>Hysteresis</th>\n");
    if (olsr_cnf->lq_level > 0)
      size += sprintf(&buf[size], "<th>LinkQuality</th><th>lost</th><th>total</th><th>NLQ</th><th>ETX</th>\n");
***************
*** 992,1012 ****
      while(link)
        {
  	size += sprintf(&buf[size],
!                        "<tr><td>%s</td>"
!                        "<td><a href=\"http://%s:%d/all\">%s</a></td>"
!                        "<td>%0.2f</td>",
!                        olsr_ip_to_string(&link->local_iface_addr),
!                        olsr_ip_to_string(&link->neighbor_iface_addr),
!                        http_port,
!                        olsr_ip_to_string(&link->neighbor_iface_addr),
                         link->L_link_quality);
          if (olsr_cnf->lq_level > 0)
            {
  	    size += sprintf(&buf[size],
!                            "<td>%0.2f</td>"
                             "<td>%d</td>"
                             "<td>%d</td>"
!                            "<td>%0.2f</td>"
!                            "<td>%0.2f</td></tr>\n",
                             link->loss_link_quality,
                             link->lost_packets, 
--- 1044,1061 ----
      while(link)
        {
+         size += sprintf(&buf[size], "<tr>");
+         size += build_ipaddr_no_link(&buf[size], bufsize, &link->local_iface_addr, NULL);
+         size += build_ipaddr_with_link(&buf[size], bufsize, &link->neighbor_iface_addr, NULL);
  	size += sprintf(&buf[size],
!                        "<td align=\"right\">%0.2f</td>",
                         link->L_link_quality);
          if (olsr_cnf->lq_level > 0)
            {
  	    size += sprintf(&buf[size],
!                            "<td align=\"right\">%0.2f</td>"
                             "<td>%d</td>"
                             "<td>%d</td>"
!                            "<td align=\"right\">%0.2f</td>"
!                            "<td align=\"right\">%0.2f</td></tr>\n",
                             link->loss_link_quality,
                             link->lost_packets, 
***************
*** 1031,1043 ****
  	  neigh = neigh->next)
  	{
  	  size += sprintf(&buf[size], 
- 			  "<tr><td><a href=\"http://%s:%d/all\">%s</a></td>"
  			  "<td>%s</td>"
  			  "<td>%s</td>"
  			  "<td>%s</td>"
  			  "<td>%d</td>", 
- 			  olsr_ip_to_string(&neigh->neighbor_main_addr),
-                           http_port,
- 			  olsr_ip_to_string(&neigh->neighbor_main_addr),
  			  (neigh->status == SYM) ? "YES" : "NO",
  			  neigh->is_mpr ? "YES" : "NO",
--- 1080,1090 ----
  	  neigh = neigh->next)
  	{
+           size += sprintf(&buf[size], "<tr>");
+           size += build_ipaddr_with_link(&buf[size], bufsize, &neigh->neighbor_main_addr, NULL);
  	  size += sprintf(&buf[size], 
  			  "<td>%s</td>"
  			  "<td>%s</td>"
  			  "<td>%s</td>"
  			  "<td>%d</td>", 
  			  (neigh->status == SYM) ? "YES" : "NO",
  			  neigh->is_mpr ? "YES" : "NO",
***************
*** 1054,1058 ****
  	      list_2 = list_2->next)
  	    {
! 	      size += sprintf(&buf[size], "<option>%s</option>\n", olsr_ip_to_string(&list_2->neighbor_2->neighbor_2_addr));
  	      thop_cnt ++;
  	    }
--- 1101,1105 ----
  	      list_2 = list_2->next)
  	    {
!               size += sprintf(&buf[size], "<option>%s</option>", olsr_ip_to_string(&list_2->neighbor_2->neighbor_2_addr));
  	      thop_cnt ++;
  	    }
***************
*** 1078,1082 ****
  
  
!   size += sprintf(&buf[size], "<h2>Topology entries</h2>\n<table width=\"100%%\" BORDER=0 CELLSPACING=0 CELLPADDING=0 ALIGN=center><tr><th>Destination IP</th><th>Last hop IP</th>");
    if (olsr_cnf->lq_level > 0)
      size += sprintf(&buf[size], "<th>LQ</th><th>ILQ</th><th>ETX</th>");
--- 1125,1129 ----
  
  
!   size += sprintf(&buf[size], "<h2>Topology entries</h2>\n<table width=\"100%%\" BORDER=0 CELLSPACING=0 CELLPADDING=0 ALIGN=center><tr><th>Destination IP</th><th>Last Hop IP</th>");
    if (olsr_cnf->lq_level > 0)
      size += sprintf(&buf[size], "<th>LQ</th><th>ILQ</th><th>ETX</th>");
***************
*** 1095,1116 ****
  	  while(dst_entry != &entry->destinations)
  	    {
! 	      size += sprintf(&buf[size],
!                              "<tr><td><a href=\"http://%s:%d/all\">%s</a></td>"
!                              "<td><a href=\"http://%s:%d/all\">%s</a></td>",
!                              olsr_ip_to_string(&dst_entry->T_dest_addr),
!                              http_port,
!                              olsr_ip_to_string(&dst_entry->T_dest_addr),
!                              olsr_ip_to_string(&entry->T_last_addr), 
!                              http_port,
!                              olsr_ip_to_string(&entry->T_last_addr));
                if (olsr_cnf->lq_level > 0)
                  {
  	          size += sprintf(&buf[size],
!                                  "<td>%0.2f</td>"
!                                  "<td>%0.2f</td>"
!                                  "<td>%0.2f</td>\n",
                                   dst_entry->link_quality,
                                   dst_entry->inverse_link_quality,
!                                  (dst_entry->link_quality * dst_entry->inverse_link_quality) ? 1.0 / (dst_entry->link_quality * dst_entry->inverse_link_quality) : 0.0);
                  }
  	      size += sprintf(&buf[size], "</tr>\n");
--- 1142,1158 ----
  	  while(dst_entry != &entry->destinations)
  	    {
!               size += sprintf(&buf[size], "<tr>");
!               size += build_ipaddr_with_link(&buf[size], bufsize, &dst_entry->T_dest_addr, NULL);
!               size += build_ipaddr_with_link(&buf[size], bufsize, &entry->T_last_addr, NULL);
                if (olsr_cnf->lq_level > 0)
                  {
+                   const double d = dst_entry->link_quality * dst_entry->inverse_link_quality;
  	          size += sprintf(&buf[size],
!                                  "<td align=\"right\">%0.2f</td>"
!                                  "<td align=\"right\">%0.2f</td>"
!                                  "<td align=\"right\">%0.2f</td>\n",
                                   dst_entry->link_quality,
                                   dst_entry->inverse_link_quality,
!                                  d ? 1.0 / d : 0.0);
                  }
  	      size += sprintf(&buf[size], "</tr>\n");
***************
*** 1153,1164 ****
  	  while(tmp_net != &tmp_hna->networks)
  	    {
! 	      size += sprintf(&buf[size], "<tr><td>%s</td>", 
! 			      olsr_ip_to_string(&tmp_net->A_network_addr));
  	      size += sprintf(&buf[size], "<td>%s</td>",
  			      olsr_netmask_to_string(&tmp_net->A_netmask));
! 	      size += sprintf(&buf[size], "<td><a href=\"http://%s:%d/all\">%s</a></td></tr>\n",
!                               olsr_ip_to_string(&tmp_hna->A_gateway_addr),
!                               http_port,
!                               olsr_ip_to_string(&tmp_hna->A_gateway_addr));
  	      tmp_net = tmp_net->next;
  	    }
--- 1195,1203 ----
  	  while(tmp_net != &tmp_hna->networks)
  	    {
!               size += sprintf(&buf[size], "<tr>");
!               size += build_ipaddr_no_link(&buf[size], bufsize, &tmp_net->A_network_addr, NULL);
  	      size += sprintf(&buf[size], "<td>%s</td>",
  			      olsr_netmask_to_string(&tmp_net->A_netmask));
!               size += build_ipaddr_with_link(&buf[size], bufsize, &tmp_hna->A_gateway_addr, NULL);
  	      tmp_net = tmp_net->next;
  	    }
***************
*** 1190,1197 ****
        while(entry != &mid_set[index])
  	{
! 	  size += sprintf(&buf[size], "<tr><td><a href=\"http://%s:%d/all\">%s</a></td>\n",
! 	                  olsr_ip_to_string(&entry->main_addr),
!                           http_port,
! 	                  olsr_ip_to_string(&entry->main_addr));
  	  size += sprintf(&buf[size], "<td><select>\n<option>IP ADDRESS</option>\n");
  
--- 1229,1234 ----
        while(entry != &mid_set[index])
  	{
!           size += sprintf(&buf[size], "<tr>");
!           size += build_ipaddr_with_link(&buf[size], bufsize, &entry->main_addr, NULL);
  	  size += sprintf(&buf[size], "<td><select>\n<option>IP ADDRESS</option>\n");
  

Index: olsrd_plugin.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/httpinfo/src/olsrd_plugin.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** olsrd_plugin.h	4 Feb 2007 22:37:36 -0000	1.21
--- olsrd_plugin.h	2 Apr 2007 22:22:26 -0000	1.22
***************
*** 73,76 ****
--- 73,77 ----
  
  extern int http_port;
+ extern int resolve_ip_addresses;
  
  /* Allowed hosts stuff */

Index: olsrd_plugin.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/httpinfo/src/olsrd_plugin.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** olsrd_plugin.c	4 Feb 2007 22:37:36 -0000	1.13
--- olsrd_plugin.c	2 Apr 2007 22:22:26 -0000	1.14
***************
*** 50,56 ****
--- 50,61 ----
  #include <string.h>
  #include <stdlib.h>
+ #include <netinet/in.h>
+ #include <arpa/nameser.h>
+ 
  #include "olsrd_httpinfo.h"
  
+ 
  int http_port = 0;
+ int resolve_ip_addresses = 0;
  
  static void __attribute__ ((constructor)) 
***************
*** 60,64 ****
  my_fini(void);
  
- 
  /*
   * Defines the version of the plugin interface that is used
--- 65,68 ----
***************
*** 82,86 ****
    /* Print plugin info to stdout */
    printf("%s\n", MOD_DESC);
!   
    return;
  }
--- 86,90 ----
    /* Print plugin info to stdout */
    printf("%s\n", MOD_DESC);
! 
    return;
  }
***************
*** 167,171 ****
        
      }
! 
    return 1;
  }
--- 171,184 ----
        
      }
!   if(!strcasecmp(key, "resolve"))
!     {
!         if (!strcasecmp (value, "yes")) {
!             resolve_ip_addresses = 1;
!         } else if (!strcasecmp (value, "no")) {
!             resolve_ip_addresses = 0;
!         } else {
!             return 0;
!         }
!     }
    return 1;
  }





More information about the Olsr-cvs mailing list