home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / internet / other / ka9q / ka9q_src.arc / IPDUMP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-07-28  |  1.6 KB  |  76 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "internet.h"
  5. #include "timer.h"
  6. #include "iface.h"
  7. #include "ip.h"
  8. #include "trace.h"
  9. #include "netuser.h"
  10.  
  11. int
  12. ip_dump(bpp,check)
  13. struct mbuf **bpp;
  14. int check;
  15. {
  16.     void tcp_dump(),udp_dump(),icmp_dump();
  17.     struct ip ip;
  18.     int16 ip_len;
  19.     int16 offset;
  20.     int16 length;
  21.     int16 csum;
  22.  
  23.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  24.         return;    
  25.  
  26.     printf("IP: ");
  27.     /* Sneak peek at IP header and find length */
  28.     ip_len = ((*bpp)->data[0] & 0xf) << 2;
  29.     if(ip_len < IPLEN){
  30.         printf("bad header\n");
  31.         return;
  32.     }
  33.     if(check)
  34.         csum = cksum(NULLHEADER,*bpp,ip_len);
  35.     else
  36.         csum = 0;
  37.  
  38.     ntohip(&ip,bpp);    /* Can't fail, we've already checked ihl */
  39.  
  40.     /* Trim data segment if necessary. */
  41.     length = ip.length - ip_len;    /* Length of data portion */
  42.     trim_mbuf(bpp,length);    
  43.     printf("%s",inet_ntoa(ip.source));
  44.     printf("->%s len %u ihl %u ttl %u prot %u",
  45.         inet_ntoa(ip.dest),ip.length,ip_len,ip.ttl & 0xff,
  46.         ip.protocol & 0xff);
  47.     if(ip.tos != 0)
  48.         printf(" tos %u",ip.tos);
  49.     offset = (ip.fl_offs & F_OFFSET) << 3;
  50.     if(offset != 0 || (ip.fl_offs & MF))
  51.         printf(" id %u offs %u",ip.id,offset);
  52.     if(ip.fl_offs & DF)
  53.         printf(" DF");
  54.     if(ip.fl_offs & MF){
  55.         printf(" MF");
  56.         check = 0;    /* Bypass host-level checksum verify */
  57.     }
  58.     if(csum != 0)
  59.         printf(" CHECKSUM ERROR (%u)",csum);
  60.     printf("\n");
  61.     if(offset == 0){
  62.         switch(ip.protocol & 0xff){
  63.         case TCP_PTCL:
  64.             tcp_dump(bpp,ip.source,ip.dest,check);
  65.             break;
  66.         case UDP_PTCL:
  67.             udp_dump(bpp,ip.source,ip.dest,check);
  68.             break;
  69.         case ICMP_PTCL:
  70.             icmp_dump(bpp,ip.source,ip.dest,check);
  71.             break;
  72.         }
  73.     }
  74. }
  75.  
  76.