debug.c 1.75 KB
Newer Older
1
2
/* debug.c
 *
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 *
 *
 * $Id$ */

/* lsh, an implementation of the ssh protocol
 *
 * Copyright (C) 1998 Niels Mller
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24
25
 */

Niels Möller's avatar
Niels Möller committed
26
27
28
#include "debug.h"
#include "xalloc.h"

29
30
31
32
33
34
struct packet_debug
{
  struct abstract_write_pipe super;
  FILE *output;
};

35
static int do_debug(struct abstract_write **w,
Niels Möller's avatar
Niels Möller committed
36
		    struct lsh_string *packet)
37
{
38
39
40
  struct packet_debug *closure
    = (struct packet_debug *) *w;
  
41
  UINT32 i;
Niels Möller's avatar
Niels Möller committed
42
43

  MDEBUG(closure);
44
45
  
  fprintf(closure->output, "DEBUG: (packet size %d = 0x%x)\n",
Niels Möller's avatar
Niels Möller committed
46
	  packet->length, packet->length);
47
48
49

  for(i=0; i<packet->length; i++)
  {
Niels Möller's avatar
Niels Möller committed
50
    if (! (i%16))
51
52
53
54
55
56
57
      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
58
  return A_WRITE(closure->super.next, packet);
59
60
}

Niels Möller's avatar
Niels Möller committed
61
struct abstract_write *
62
make_packet_debug(struct abstract_write *continuation, FILE *output)
63
{
64
  struct packet_debug *closure = xalloc(sizeof(struct packet_debug));
65

66
  closure->super.super.write = do_debug;
Niels Möller's avatar
Niels Möller committed
67
  closure->super.next = continuation;
68
69
  closure->output = output;

70
  return &closure->super.super;
71
72
73
}