home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / TCPIP / NETKIT-A.06 / NETKIT-A / NetKit-A-0.06 / dip337d-uri / ipdump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-16  |  1.4 KB  |  48 lines

  1. /*
  2.  * dip        A program for handling dialup IP connecions.
  3.  *        IP Datagram dumping routines.
  4.  *
  5.  * Version:    @(#)ipdump.c    3.3.3    08/16/93
  6.  *
  7.  * Author:      Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  8.  *        Copyright 1988-1993 MicroWalt Corporation
  9.  *
  10.  *        This program is free software; you can redistribute it
  11.  *        and/or  modify it under  the terms of  the GNU General
  12.  *        Public  License as  published  by  the  Free  Software
  13.  *        Foundation;  either  version 2 of the License, or  (at
  14.  *        your option) any later version.
  15.  */
  16. #include "dip.h"
  17. #include <netinet/in_systm.h>
  18. #include <netinet/ip.h>
  19.  
  20.  
  21. void
  22. ip_dump(char *ptr, int len)
  23. {
  24.   struct ip *ip;
  25.   int flags, dlen, doff;
  26.  
  27.   ip = (struct ip *) ptr;
  28.   dlen = ntohs(ip->ip_len);
  29.   flags = (ntohs(ip->ip_off) & ~IP_OFFSET);
  30.   doff = ((ntohs(ip->ip_off) & IP_OFFSET) << 3);
  31.  
  32.   fprintf(stderr, "\r*****\n");
  33.   fprintf(stderr, "IP: %s->", inet_ntoa(ip->ip_src));
  34.   fprintf(stderr, "%s\n", inet_ntoa(ip->ip_dst));
  35.   fprintf(stderr, " len %u ihl %u ver %u ttl %u prot %u sum %u",
  36.     dlen, ip->ip_hl, ip->ip_v, ip->ip_ttl, ip->ip_p, ip->ip_sum);
  37.  
  38.   if (ip->ip_tos != 0) fprintf(stderr, " tos 0x%02X", ip->ip_tos);
  39.   if (doff != 0 || (flags & IP_MF))
  40.     fprintf(stderr, " id %u offs %u", ntohs(ip->ip_id), doff);
  41.  
  42.   if (flags & IP_DF) fprintf(stderr, " DF");
  43.   if (flags & IP_MF) fprintf(stderr, " MF");
  44.   if (flags & IP_CE) fprintf(stderr, " CE");
  45.   fprintf(stderr, "\n*****\n");
  46.   (void) fflush(stderr);
  47. }
  48.