home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / network / src_1218.zip / UDPDUMP.C < prev    next >
C/C++ Source or Header  |  1991-03-17  |  1KB  |  59 lines

  1. /* UDP packet tracing
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. #include <stdio.h>
  5. #include "global.h"
  6. #include "mbuf.h"
  7. #include "netuser.h"
  8. #include "internet.h"
  9. #include "udp.h"
  10. #include "ip.h"
  11. #include "socket.h"
  12. #include "trace.h"
  13.  
  14. /* Dump a UDP header */
  15. void
  16. udp_dump(fp,bpp,source,dest,check)
  17. FILE *fp;
  18. struct mbuf **bpp;
  19. int32 source,dest;
  20. int check;        /* If 0, bypass checksum verify */
  21. {
  22.     struct udp udp;
  23.     struct pseudo_header ph;
  24.     int16 csum;
  25.  
  26.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  27.         return;
  28.  
  29.     fprintf(fp,"UDP:");
  30.  
  31.     /* Compute checksum */
  32.     ph.source = source;
  33.     ph.dest = dest;
  34.     ph.protocol = UDP_PTCL;
  35.     ph.length = len_p(*bpp);
  36.     if((csum = cksum(&ph,*bpp,ph.length)) == 0)
  37.         check = 0;    /* No checksum error */
  38.  
  39.     ntohudp(&udp,bpp);
  40.  
  41.     fprintf(fp," len %u",udp.length);
  42.     fprintf(fp," %u->%u",udp.source,udp.dest);
  43.     if(udp.length > UDPHDR)
  44.         fprintf(fp," Data %u",udp.length - UDPHDR);
  45.     if(udp.checksum == 0)
  46.         check = 0;
  47.     if(check)
  48.         fprintf(fp," CHECKSUM ERROR (%u)",csum);
  49.  
  50.     putc('\n',fp);
  51.  
  52.     switch(udp.dest){
  53.     case IPPORT_RIP:
  54.         rip_dump(fp,bpp);
  55.     }
  56.  
  57. }
  58.  
  59.