Bug#453859: [net-tools-cvscommit at lists.berlios.de: [net-tools-cvscommit] net-tools netstat.c, 1.56, 1.57 statistics.c, 1.20, 1.21]

Bernd Eckenfels be-mail2008 at lina.inka.de
Fri Oct 3 01:57:35 UTC 2008


This bug is now also in upstream CVS (http://net-tools.berlios.de/)

Greetings
Bernd

----- Forwarded message from CVS Commits for net-tools project <net-tools-cvscommit at lists.berlios.de> -----

Envelope-to: net-tools at lina.inka.de
Delivery-date: Fri, 03 Oct 2008 02:05:33 +0200
To: net-tools-cvscommit at lists.berlios.de
From: CVS Commits for net-tools project <net-tools-cvscommit at lists.berlios.de>
Subject: [net-tools-cvscommit] net-tools netstat.c, 1.56, 1.57 statistics.c,
	1.20, 1.21
X-BeenThere: net-tools-cvscommit at lists.berlios.de
X-Mailman-Version: 2.1.9
Reply-To: net-tools at lina.inka.de, net-tools-cvscommit at lists.berlios.de
List-Id: CVS Commits for net-tools project
	<net-tools-cvscommit.lists.berlios.de>
List-Unsubscribe: <https://lists.berlios.de/mailman/listinfo/net-tools-cvscommit>,
	<mailto:net-tools-cvscommit-request at lists.berlios.de?subject=unsubscribe>
List-Archive: <https://lists.berlios.de/pipermail/net-tools-cvscommit>
List-Post: <mailto:net-tools-cvscommit at lists.berlios.de>
List-Help: <mailto:net-tools-cvscommit-request at lists.berlios.de?subject=help>
List-Subscribe: <https://lists.berlios.de/mailman/listinfo/net-tools-cvscommit>,
	<mailto:net-tools-cvscommit-request at lists.berlios.de?subject=subscribe>
X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on 
	calista.eckenfels.net
X-Spam-Level: 
X-Spam-Status: No, score=-2.6 required=4.7 tests=AWL,BAYES_00 autolearn=ham 
	version=3.0.3

Update of /cvsroot/net-tools/net-tools
In directory sheep:/tmp/cvs-serv21692

Modified Files:
	netstat.c statistics.c 
Log Message:
Enable netstat -s for IPv6 (Debian Bug #453859 from Varun Chandramohan)


Index: netstat.c
===================================================================
RCS file: /cvsroot/net-tools/net-tools/netstat.c,v
retrieving revision 1.56
retrieving revision 1.57
diff -C2 -d -r1.56 -r1.57
*** netstat.c	2 Oct 2008 22:05:54 -0000	1.56
--- netstat.c	3 Oct 2008 00:05:20 -0000	1.57
***************
*** 106,109 ****
--- 106,111 ----
  void parsesnmp(int, int, int);
  void inittab(void);
+ void parsesnmp6(int, int, int);
+ void inittab6(void);
  
  typedef enum {
***************
*** 1724,1730 ****
  
      if (flag_sta) {
!         inittab();
! 	parsesnmp(flag_raw, flag_tcp, flag_udp);
! 	exit(0);
      }
      
--- 1726,1751 ----
  
      if (flag_sta) {
!         char *tmp1, *tmp2;
!         char buf[256];
!         if (!afname[0]) {
!             inittab();
!             parsesnmp(flag_raw, flag_tcp, flag_udp);
!         } else {
!             safe_strncpy(buf, afname, sizeof(buf));
!             tmp1 = buf;
!             if ((tmp2 = index(tmp1, ',')))
!                  printf("Multiple interface\n");
!             else if(!strncmp(buf,"inet6",5)) {
! #if HAVE_AFINET6
!                  inittab6();
!                  parsesnmp6(flag_raw, flag_tcp, flag_udp);
! #else
!                  printf("Address type not supported for stats\n");
! #endif
!             }
!             else
!                  printf("Address type not supported for stats\n");
!         }
!         exit(1);
      }
      

Index: statistics.c
===================================================================
RCS file: /cvsroot/net-tools/net-tools/statistics.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** statistics.c	1 Dec 2007 18:44:56 -0000	1.20
--- statistics.c	3 Oct 2008 00:05:20 -0000	1.21
***************
*** 85,88 ****
--- 85,114 ----
  };
  
+ struct entry Ip6tab[] =
+ {
+     {"Ip6InReceives", N_("%u total packets received"), number},
+     {"Ip6InHdrErrors", N_("%u with invalid headers"), opt_number},
+     {"Ip6InTooBigErrors", N_("%u with packets too big"), opt_number},
+     {"Ip6InNoRoutes", N_("%u incoming packets with no route"), opt_number},
+     {"Ip6InAddrErrors", N_("%u with invalid addresses"), opt_number},
+     {"Ip6InUnknownProtos", N_("%u with unknown protocol"), opt_number},
+     {"Ip6InTruncatedPkts", N_("%u with truncated packets"), opt_number},
+     {"Ip6InDiscards", N_("%u incoming packets discarded"), number},
+     {"Ip6InDelivers", N_("%u incoming packets delivered"), number},
+     {"Ip6OutForwDatagrams", N_("%u forwarded"), number},
+     {"Ip6OutRequests", N_("%u requests sent out"), number},     /*? */
+     {"Ip6OutDiscards", N_("%u outgoing packets dropped"), opt_number},
+     {"Ip6OutNoRoutes", N_("%u dropped because of missing route"), opt_number},
+     {"Ip6ReasmTimeout", N_("%u fragments dropped after timeout"), opt_number},
+     {"Ip6ReasmReqds", N_("%u reassemblies required"), opt_number}, /* ? */
+     {"Ip6ReasmOKs", N_("%u packets reassembled ok"), opt_number},
+     {"Ip6ReasmFails", N_("%u packet reassembles failed"), opt_number},
+     {"Ip6FragOKs", N_("%u fragments received ok"), opt_number},
+     {"Ip6FragFails", N_("%u fragments failed"), opt_number},
+     {"Ip6FragCreates", N_("%u fragments created"), opt_number},
+     {"Ip6InMcastPkts", N_("%u incoming multicast packets"), opt_number},
+     {"Ip6OutMcastPkts", N_("%u outgoing multicast packets"), opt_number}
+ };
+ 
  struct entry Icmptab[] =
  {
***************
*** 115,118 ****
--- 141,179 ----
  };
  
+ struct entry Icmp6tab[] =
+ {
+     {"Icmp6InMsgs", N_("%u ICMP messages received"), number},
+     {"Icmp6InErrors", N_("%u input ICMP message failed."), number},
+     {"Icmp6InDestUnreachs", N_("destination unreachable: %u"), i_inp_icmp | I_TITLE},
+     {"Icmp6InPktTooBigs", N_("packets too big: %u"), i_inp_icmp | I_TITLE},
+     {"Icmp6InTimeExcds", N_("received ICMPv6 time exceeded: %u"), i_inp_icmp | I_TITLE},
+     {"Icmp6InParmProblems", N_("parameter problem: %u"), i_inp_icmp | I_TITLE},
+     {"Icmp6InEchos", N_("echo requests: %u"), i_inp_icmp | I_TITLE},
+     {"Icmp6InEchoReplies", N_("echo replies: %u"), i_inp_icmp | I_TITLE},
+     {"Icmp6InGroupMembQueries", N_("group member queries: %u"), i_inp_icmp | I_TITLE},
+     {"Icmp6InGroupMembResponses", N_("group member responses: %u"), i_inp_icmp | I_TITLE},
+     {"Icmp6InGroupMembReductions", N_("group member reductions: %u"), i_inp_icmp | I_TITLE},
+     {"Icmp6InRouterSolicits", N_("router solicits: %u"), i_inp_icmp | I_TITLE},
+     {"Icmp6InRouterAdvertisements", N_("router advertisement: %u"), i_inp_icmp | I_TITLE},
+     {"Icmp6InNeighborSolicits", N_("neighbour solicits: %u"), i_inp_icmp | I_TITLE},
+     {"Icmp6InNeighborAdvertisements", N_("neighbour advertisement: %u"), i_inp_icmp | I_TITLE},
+     {"Icmp6InRedirects", N_("redirects: %u"), i_inp_icmp | I_TITLE},
+     {"Icmp6OutMsgs", N_("%u ICMP messages sent"), number},
+     {"Icmp6OutDestUnreachs", N_("destination unreachable: %u"), i_outp_icmp | I_TITLE},
+     {"Icmp6OutPktTooBigs", N_("packets too big: %u"), i_outp_icmp | I_TITLE},
+     {"Icmp6OutTimeExcds", N_("sent ICMPv6 time exceeded: %u"), i_outp_icmp | I_TITLE},
+     {"Icmp6OutParmProblems", N_("parameter problem: %u"), i_outp_icmp | I_TITLE},
+     {"Icmp6OutEchos", N_("echo requests: %u"), i_outp_icmp | I_TITLE},
+     {"Icmp6OutEchoReplies", N_("echo replies: %u"), i_outp_icmp | I_TITLE},
+     {"Icmp6OutGroupMembQueries", N_("group member queries: %u"), i_outp_icmp | I_TITLE},
+     {"Icmp6OutGroupMembResponses", N_("group member responses: %u"), i_outp_icmp | I_TITLE},
+     {"Icmp6OutGroupMembReductions", N_("group member reductions: %u"), i_outp_icmp | I_TITLE},
+     {"Icmp6OutRouterSolicits", N_("router solicits: %u"), i_outp_icmp | I_TITLE},
+     {"Icmp6OutRouterAdvertisements ", N_("router advertisement: %u"), i_outp_icmp | I_TITLE},
+     {"Icmp6OutNeighborSolicits", N_("neighbor solicits: %u"), i_outp_icmp | I_TITLE},
+     {"Icmp6OutNeighborAdvertisements", N_("neighbor advertisements: %u"), i_outp_icmp | I_TITLE},
+     {"Icmp6OutRedirects", N_("redirects: %u"), i_outp_icmp | I_TITLE},
+ };
+ 
  struct entry Tcptab[] =
  {
***************
*** 141,144 ****
--- 202,213 ----
  };
  
+ struct entry Udp6tab[] =
+ {
+     {"Udp6InDatagrams", N_("%u packets received"), number},
+     {"Udp6NoPorts", N_("%u packets to unknown port received."), number},
+     {"Udp6InErrors", N_("%u packet receive errors"), number},
+     {"Udp6OutDatagrams", N_("%u packets sent"), number},
+ };
+ 
  struct entry Tcpexttab[] =
  {
***************
*** 246,249 ****
--- 315,327 ----
  };
  
+ struct tabtab snmp6tabs[] =
+ {
+     {"Ip6", Ip6tab, sizeof(Ip6tab), &f_raw},
+     {"Icmp6", Icmp6tab, sizeof(Icmp6tab), &f_raw},
+     {"Udp6", Udp6tab, sizeof(Udp6tab), &f_udp},
+     {"Tcp6", Tcptab, sizeof(Tcptab), &f_tcp},
+     {NULL}
+ };
+ 
  /* XXX IGMP */
  
***************
*** 332,336 ****
  }
  
! int process_fd(FILE *f)
  {
      char buf1[2048], buf2[2048];
--- 410,414 ----
  }
  
! int process_fd(FILE *f, int all, char *filter)
  {
      char buf1[2048], buf2[2048];
***************
*** 351,354 ****
--- 429,436 ----
  	*sp = '\0';
  
+         if (!all)
+            if (strncmp(buf1, filter, strlen(filter)))
+                continue;
+ 
  	tab = newtable(snmptabs, buf1);
  	if (tab == NULL) {
***************
*** 382,385 ****
--- 464,502 ----
  }
  
+ void cpytitle(char *original, char *new)
+ {
+      char *ptr = original;
+      while(*ptr != '6' && *ptr != '\0') {
+            *new = *ptr;
+             new++;
+             ptr++;
+      }
+     *new = *ptr;
+     new++;
+     *new = '\0';
+ }
+ 
+ void process6_fd(FILE *f)
+ {
+    char buf1[1024],buf2[50],buf3[1024];
+    unsigned long val;
+    struct tabtab *tab = NULL;
+    int cpflg = 0;
+ 
+    while (fgets(buf1, sizeof buf1, f)) {
+           sscanf(buf1, "%s %lu", buf2, &val);
+           if(!cpflg) {
+              cpytitle(buf2, buf3);
+              tab = newtable(snmp6tabs, buf3);
+              cpflg = 1;
+           }
+           if(!strstr(buf2, buf3)) {
+              cpytitle(buf2, buf3);
+              tab = newtable(snmp6tabs, buf3);
+           }
+           printval(tab, buf2, val);
+    }
+ 
+ }
  
  void parsesnmp(int flag_raw, int flag_tcp, int flag_udp)
***************
*** 395,399 ****
      }
  
!     if (process_fd(f) < 0)
        fprintf(stderr, _("Problem while parsing /proc/net/snmp\n"));
  
--- 512,516 ----
      }
  
!     if (process_fd(f, 1, NULL) < 0)
        fprintf(stderr, _("Problem while parsing /proc/net/snmp\n"));
  
***************
*** 406,410 ****
  
      if (f) {
!     	if (process_fd(f) <0)
            fprintf(stderr, _("Problem while parsing /proc/net/netstat\n"));
  
--- 523,527 ----
  
      if (f) {
!     	if (process_fd(f, 1, NULL) <0)
            fprintf(stderr, _("Problem while parsing /proc/net/netstat\n"));
  
***************
*** 417,420 ****
--- 534,564 ----
  }
      
+ void parsesnmp6(int flag_raw, int flag_tcp, int flag_udp)
+ {
+     FILE *f;
+ 
+     f_raw = flag_raw; f_tcp = flag_tcp; f_udp = flag_udp;
+ 
+     f = fopen("/proc/net/snmp6", "r");
+     if (!f) {
+         perror(_("cannot open /proc/net/snmp6"));
+         return;
+     }
+     process6_fd(f);
+     if (ferror(f))
+         perror("/proc/net/snmp6");
+ 
+     fclose(f);
+     f = fopen("/proc/net/snmp", "r");
+     if (!f) {
+         perror(_("cannot open /proc/net/snmp"));
+         return;
+     }
+     process_fd(f, 0, "Tcp");
+     if (ferror(f))
+         perror("/proc/net/snmp");
+ 
+     fclose(f);
+ }
  
  void inittab(void)
***************
*** 427,428 ****
--- 571,582 ----
  	      sizeof(struct entry), cmpentries);
  }
+ 
+ void inittab6(void)
+ {
+     struct tabtab *t;
+ 
+     for (t = snmp6tabs; t->title; t++)
+         qsort(t->tab, t->size / sizeof(struct entry),
+               sizeof(struct entry), cmpentries);
+ }
+ 

_______________________________________________
net-tools-cvscommit mailing list
net-tools-cvscommit at lists.berlios.de
https://lists.berlios.de/mailman/listinfo/net-tools-cvscommit

----- End forwarded message -----

-- 
  (OO)     -- Bernd_Eckenfels at Mörscher_Strasse_8.76185Karlsruhe.de --
 ( .. )    ecki@{inka.de,linux.de,debian.org}  http://www.eckes.org/
  o--o   1024D/E383CD7E  eckes at IRCNet  v:+497211603874  f:+49721151516129
(O____O)  When cryptography is outlawed, bayl bhgynjf jvyy unir cevinpl!





More information about the Pkg-net-tools-maintainers mailing list