home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / tcpdumpb.zip / print-igrp.c < prev    next >
C/C++ Source or Header  |  1997-02-14  |  5KB  |  141 lines

  1. /*
  2.  * Copyright (c) 1996
  3.  *      The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that: (1) source code distributions
  7.  * retain the above copyright notice and this paragraph in its entirety, (2)
  8.  * distributions including binary code include the above copyright notice and
  9.  * this paragraph in its entirety in the documentation or other materials
  10.  * provided with the distribution, and (3) all advertising materials mentioning
  11.  * features or use of this software display the following acknowledgement:
  12.  * ``This product includes software developed by the University of California,
  13.  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  14.  * the University nor the names of its contributors may be used to endorse
  15.  * or promote products derived from this software without specific prior
  16.  * written permission.
  17.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  18.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  19.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20.  *
  21.  * Initial contribution from Francis Dupont (francis.dupont@inria.fr)
  22.  */
  23.  
  24. #ifndef lint
  25. static char rcsid[] =
  26. "@(#) $Header: print-igrp.c,v 1.4 96/07/23 14:04:55 leres Exp $ (LBL)";
  27. #endif
  28.  
  29. #include <sys/param.h>
  30. #include <sys/socket.h>
  31.  
  32. #include <netinet/in.h>
  33. #include <netinet/in_systm.h>
  34. #include <netinet/ip.h>
  35. #ifndef __EMX__
  36. #include <netinet/ip_var.h>
  37. #endif
  38. #include <netinet/udp.h>
  39. #include <netinet/udp_var.h>
  40.  
  41. #include <errno.h>
  42. #include <stdio.h>
  43.  
  44. #include "addrtoname.h"
  45. #include "interface.h"
  46. #include "igrp.h"
  47. #include "extract.h"                    /* must come after interface.h */
  48.  
  49. static void
  50. igrp_entry_print(register struct igrprte *igr, register int is_interior,
  51.     register int is_exterior)
  52. {
  53.         register u_int delay, bandwidth;
  54.         u_int metric, mtu;
  55.  
  56.         if (is_interior)
  57.                 printf(" *.%d.%d.%d", igr->igr_net[0],
  58.                     igr->igr_net[1], igr->igr_net[2]);
  59.         else if (is_exterior)
  60.                 printf(" X%d.%d.%d.0", igr->igr_net[0],
  61.                     igr->igr_net[1], igr->igr_net[2]);
  62.         else
  63.                 printf(" %d.%d.%d.0", igr->igr_net[0],
  64.                     igr->igr_net[1], igr->igr_net[2]);
  65.  
  66.         delay = EXTRACT_24BITS(igr->igr_dly);
  67.         bandwidth = EXTRACT_24BITS(igr->igr_bw);
  68.         metric = bandwidth + delay;
  69.         if (metric > 0xffffff)
  70.                 metric = 0xffffff;
  71.         mtu = EXTRACT_16BITS(igr->igr_mtu);
  72.  
  73.         printf(" d=%d b=%d r=%d l=%d M=%d mtu=%d in %d hops",
  74.             10 * delay, bandwidth == 0 ? 0 : 10000000 / bandwidth,
  75.             igr->igr_rel, igr->igr_ld, metric,
  76.             mtu, igr->igr_hct);
  77. }
  78.  
  79. static struct tok op2str[] = {
  80.         { IGRP_UPDATE,          "update" },
  81.         { IGRP_REQUEST,         "request" },
  82.         { 0,                    NULL }
  83. };
  84.  
  85. void
  86. igrp_print(register const u_char *bp, u_int length, register const u_char *bp2)
  87. {
  88.         register struct igrphdr *hdr;
  89.         register struct ip *ip;
  90.         register u_char *cp;
  91.         u_int nint, nsys, next;
  92.  
  93.         hdr = (struct igrphdr *)bp;
  94.         ip = (struct ip *)bp2;
  95.         cp = (u_char *)(hdr + 1);
  96.         (void)printf("%s > %s: igrp: ",
  97.             ipaddr_string(&ip->ip_src),
  98.             ipaddr_string(&ip->ip_dst));
  99.  
  100.         /* Header */
  101.         TCHECK(*hdr);
  102.         nint = EXTRACT_16BITS(&hdr->ig_ni);
  103.         nsys = EXTRACT_16BITS(&hdr->ig_ns);
  104.         next = EXTRACT_16BITS(&hdr->ig_nx);
  105.  
  106.         (void)printf(" %s V%d edit=%d AS=%d (%d/%d/%d)",
  107.             tok2str(op2str, "op-#%d", hdr->ig_op),
  108.             hdr->ig_v,
  109.             hdr->ig_ed,
  110.             EXTRACT_16BITS(&hdr->ig_as),
  111.             nint,
  112.             nsys,
  113.             next);
  114.  
  115.         length -= sizeof(*hdr);
  116.         while (length >= IGRP_RTE_SIZE) {
  117.                 if (nint > 0) {
  118.                         TCHECK2(*cp, IGRP_RTE_SIZE);
  119.                         igrp_entry_print((struct igrprte *)cp, 1, 0);
  120.                         --nint;
  121.                 } else if (nsys > 0) {
  122.                         TCHECK2(*cp, IGRP_RTE_SIZE);
  123.                         igrp_entry_print((struct igrprte *)cp, 0, 0);
  124.                         --nsys;
  125.                 } else if (next > 0) {
  126.                         TCHECK2(*cp, IGRP_RTE_SIZE);
  127.                         igrp_entry_print((struct igrprte *)cp, 0, 1);
  128.                         --next;
  129.                 } else {
  130.                         (void)printf("[extra bytes %d]", length);
  131.                         break;
  132.                 }
  133.                 cp += IGRP_RTE_SIZE;
  134.                 length -= IGRP_RTE_SIZE;
  135.         }
  136.         if (nint == 0 && nsys == 0 && next == 0)
  137.                 return;
  138. trunc:
  139.         fputs("[|igrp]", stdout);
  140. }
  141.