File: payload.c

package info (click to toggle)
ipgrab 0.8.2-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 540 kB
  • ctags: 555
  • sloc: ansic: 4,608; sh: 1,507; makefile: 120
file content (74 lines) | stat: -rw-r--r-- 1,564 bytes parent folder | download
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
/**************************************************************************** 
** File: payload.c
**
** Author: Mike Borella
**
** Comments: Dump packet payload
**
*****************************************************************************/

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

#define BUF_SIZE 128

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;
  char *buf_ptr, *buf_end;
  int col;
  int i;
  char hexbuf[BUF_SIZE], charbuf[BUF_SIZE];


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

  if (ep > packet_end) 
    ep = packet_end;

  printf("-----------------------------------------------------------------\n");

  buf_ptr = bp;
  buf_end = ep;

  do
    {
      col = 0;
      memset(hexbuf, 0, BUF_SIZE);
      memset(charbuf, 0, BUF_SIZE);

      for(i=0;i<16;i++)
	{
	  if(buf_ptr < buf_end)
            {
	      snprintf(hexbuf+(i*3), BUF_SIZE-1,"%.2X ",buf_ptr[0] & 0xFF);
	      
	      if(*buf_ptr > 0x1F && *buf_ptr < 0x7E)
		snprintf(charbuf+i+col, BUF_SIZE-1,"%c",buf_ptr[0]);
	      else
		snprintf(charbuf+i+col, BUF_SIZE-1, ".");
	      
	      buf_ptr++;
            }
	}
      printf("%-48s %s\n",hexbuf,charbuf);
    }
  while(buf_ptr < buf_end);
}