Bringing up TLS connections working.
[radsecproxy.git] / lib / debug.c
1 /* See the file COPYING for licensing information.  */
2
3 #if defined HAVE_CONFIG_H
4 #include <config.h>
5 #endif
6
7 #include <stdio.h>
8 #include <freeradius/libradius.h>
9 #include <radsec/radsec.h>
10 #include <radsec/radsec-impl.h>
11 #include "debug.h"
12
13 /* From freeradius-server/src/lib/radius.c */
14 static void print_hex(RADIUS_PACKET *packet)
15 {
16         int i;
17
18         if (!packet->data) return;
19
20         printf("  Code:\t\t%u\n", packet->data[0]);
21         printf("  Id:\t\t%u\n", packet->data[1]);
22         printf("  Length:\t%u\n", ((packet->data[2] << 8) |
23                                    (packet->data[3])));
24         printf("  Vector:\t");
25         for (i = 4; i < 20; i++) {
26                 printf("%02x", packet->data[i]);
27         }
28         printf("\n");
29
30         if (packet->data_len > 20) {
31                 int total;
32                 const uint8_t *ptr;
33                 printf("  Data:");
34
35                 total = packet->data_len - 20;
36                 ptr = packet->data + 20;
37
38                 while (total > 0) {
39                         int attrlen;
40
41                         printf("\t\t");
42                         if (total < 2) { /* too short */
43                                 printf("%02x\n", *ptr);
44                                 break;
45                         }
46
47                         if (ptr[1] > total) { /* too long */
48                                 for (i = 0; i < total; i++) {
49                                         printf("%02x ", ptr[i]);
50                                 }
51                                 break;
52                         }
53
54                         printf("%02x  %02x  ", ptr[0], ptr[1]);
55                         attrlen = ptr[1] - 2;
56                         ptr += 2;
57                         total -= 2;
58
59                         for (i = 0; i < attrlen; i++) {
60                                 if ((i > 0) && ((i & 0x0f) == 0x00))
61                                         printf("\t\t\t");
62                                 printf("%02x ", ptr[i]);
63                                 if ((i & 0x0f) == 0x0f) printf("\n");
64                         }
65
66                         if ((attrlen & 0x0f) != 0x00) printf("\n");
67
68                         ptr += attrlen;
69                         total -= attrlen;
70                 }
71         }
72         fflush(stdout);
73 }
74
75 void
76 rs_dump_packet (const struct rs_packet *pkt)
77 {
78   print_hex (pkt->rpkt);
79 }
80
81 void
82 rs_dump_attr (const struct rs_attr *attr)
83 {
84   vp_printlist (stderr, attr->vp);
85 }