debug.c 1.67 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
static int do_debug(struct abstract_write **w,
Niels Möller's avatar
Niels Möller committed
30
		    struct lsh_string *packet)
31
{
32
33
34
  struct packet_debug *closure
    = (struct packet_debug *) *w;
  
35
  UINT32 i;
Niels Möller's avatar
Niels Möller committed
36
37

  MDEBUG(closure);
38
39
  
  fprintf(closure->output, "DEBUG: (packet size %d = 0x%x)\n",
Niels Möller's avatar
Niels Möller committed
40
	  packet->length, packet->length);
41
42
43

  for(i=0; i<packet->length; i++)
  {
Niels Möller's avatar
Niels Möller committed
44
    if (! (i%16))
45
46
47
48
49
50
51
      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
52
  return A_WRITE(closure->super.next, packet);
53
54
}

Niels Möller's avatar
Niels Möller committed
55
struct abstract_write *
56
make_packet_debug(struct abstract_write *continuation, FILE *output)
57
{
58
  struct packet_debug *closure = xalloc(sizeof(struct packet_debug));
59

60
  closure->super.super.write = do_debug;
Niels Möller's avatar
Niels Möller committed
61
  closure->super.next = continuation;
62
63
  closure->output = output;

64
  return &closure->super.super;
65
66
67
}