File: payload.c

package info (click to toggle)
ipgrab 0.5-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 268 kB
  • ctags: 169
  • sloc: sh: 1,507; ansic: 1,234; makefile: 56
file content (89 lines) | stat: -rw-r--r-- 1,586 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**************************************************************************** 
** File: payload.c
**
** Author: Mike Borella
**
** Comments: Dump packet payload
**
*****************************************************************************/

#include <stdio.h>
#include <unistd.h>
#include <arpa/inet.h>
#include "config.h"

extern u_char *packet_end;

/*----------------------------------------------------------------------------
**
** dump_payload()
**
** Dump printable portions of packet payload
**
**----------------------------------------------------------------------------
*/

void dump_payload(u_char *bp, int length)
{
  u_char *ep = bp + length;
  u_char *p;
  int col;
  static char last = 0;


  /*
   * Make sure we don't run off the end of the packet
   */

  if (ep > packet_end) ep = packet_end;

  /*
   * Print 64 bytes at a time, using .'s for "unprintable" chars.
   */

  col = 0;
  p = bp;
  printf("----------------------------------------------------------\n");
  while (p < ep)
    {
      if (*p < ' ' || *p > '~') 
	{
	  /*
	   * Eventually expand this and put it somewhere else?
	   */
	  
	  switch (*p)
	    {
	    case 10: 
	      printf("<LF>");
              col += 3;
	      break;
	    case 13:
	      printf("<CR>");
              col += 3;
	      break;
	    default:	
	      putchar('.');
	      break;
	    }
	}
      else 
	putchar(*p);
      last = *p;

      /*
       * Make sure that we only print 64 columns of chars
       */

      col++;
      if (col >= 64)
	{
	  putchar('\n');
	  col = 0;
	}

      p++;
    }

  putchar('\n');
}