debug.c 886 Bytes
Newer Older
1
2
3
4
/* debug.c
 *
 */

Niels Möller's avatar
Niels Möller committed
5
6
7
#include "debug.h"
#include "xalloc.h"

8
static int do_debug(struct abstract_write **w,
Niels Möller's avatar
Niels Möller committed
9
		    struct lsh_string *packet)
10
{
11
12
13
  struct packet_debug *closure
    = (struct packet_debug *) *w;
  
14
15
16
  UINT32 i;
  
  fprintf(closure->output, "DEBUG: (packet size %d = 0x%x)\n",
Niels Möller's avatar
Niels Möller committed
17
	  packet->length, packet->length);
18
19
20
21
22
23
24
25
26
27
28

  for(i=0; i<packet->length; i++)
  {
    if (! i%16)
      fprintf(closure->output, "\n%08x: ", i);
    
    fprintf(closure->output, "%02x ", packet->data[i]);
  }

  fprintf(closure->output, "\n");

Niels Möller's avatar
Niels Möller committed
29
  return A_WRITE(closure->super.next, packet);
30
31
}

Niels Möller's avatar
Niels Möller committed
32
struct abstract_write *
33
make_packet_debug(struct abstract_write *continuation, FILE *output)
34
{
35
  struct packet_debug *closure = xalloc(sizeof(struct packet_debug));
36

37
  closure->super.super.write = do_debug;
Niels Möller's avatar
Niels Möller committed
38
  closure->super.next = continuation;
39
40
  closure->output = output;

41
  return &closure->super.super;
42
43
44
}