debug.c 1.65 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
36
37
  UINT32 i;
  
  fprintf(closure->output, "DEBUG: (packet size %d = 0x%x)\n",
Niels Möller's avatar
Niels Möller committed
38
	  packet->length, packet->length);
39
40
41

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

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

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

62
  return &closure->super.super;
63
64
65
}