commit - a89104b15c575f62abac27cdf91ca61b75e2e3b3
commit + 78b94752d5b26103aad5205bb948c9e0639728c3
blob - e081cbabcca108aafea75112f78412ab5d1c3de8
blob + cad31417325f16acb78e589d5e3d209c5b1c8b56
--- client.c
+++ client.c
#include <sys/stat.h>
-#include <ctype.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <pwd.h>
#include <signal.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
static void tflush(struct np_msg_header *, const uint8_t *, size_t);
static void twalk(struct np_msg_header *, const uint8_t *, size_t);
static void handle_message(struct imsg *, size_t);
-
-void client_hexdump(const char *, uint8_t *data, size_t len);
ATTR_DEAD void
client(int debug, int verbose)
data = EVBUFFER_DATA(evb);
#if DEBUG_PACKETS
- client_hexdump("outgoing packet", data, len);
+ hexdump("outgoing packet", data, len);
#endif
client_send_listener(IMSG_BUF, data, len);
evbuffer_drain(evb, len);
uint8_t *data;
#if DEBUG_PACKETS
- client_hexdump("incoming packet", imsg->data, len);
+ hexdump("incoming packet", imsg->data, len);
#endif
parse_message(imsg->data, len, &hdr, &data);
}
np_error(hdr.tag, "Not supported.");
-}
-
-static void
-hexdump_ppline(int x, uint8_t *data, size_t len)
-{
- for (; x < 50; x++)
- printf(" ");
-
- printf("|");
-
- for (x = 0; x < (int)len; ++x) {
- if (isgraph(data[x]))
- printf("%c", data[x]);
- else
- printf(".");
- }
-
- printf("|\n");
-}
-
-void
-client_hexdump(const char *label, uint8_t *data, size_t len)
-{
- size_t i;
- int x, n;
-
- /*
- * Layout:
- * === first block === == second block == |........|\n
- * first and second block are 8 bytes long (for a total of 48
- * columns), plus two separator plus two | plus 16 chars, for
- * a total of 68 characters.
- */
-
- printf("\nhexdump \"%s\": (%zu bytes)\n", label, len);
- for (x = 0, n = 0, i = 0; i < len; ++i) {
- if (i != 0 && i % 8 == 0) {
- printf(" ");
- x++;
- }
-
- if (n == 16) {
- hexdump_ppline(x, &data[i - 16], 16);
- x = 0;
- n = 0;
- }
-
- printf("%02x ", data[i]);
- x += 3;
- n++;
- }
-
- if (n != 0)
- hexdump_ppline(x, &data[i - n], n);
-
- printf("\n");
}
blob - aaa6581d70ad25f33100ea688d1b3b5e14aa6a32
blob + 85aa93ab18963a7747b411498011918c13d61f33
--- utils.c
+++ utils.c
#include "compat.h"
+#include <ctype.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
default: return "unknown";
}
}
+
+static void
+hexdump_ppline(int x, uint8_t *data, size_t len)
+{
+ for (; x < 50; x++)
+ printf(" ");
+
+ printf("|");
+
+ for (x = 0; x < (int)len; ++x) {
+ if (isgraph(data[x]))
+ printf("%c", data[x]);
+ else
+ printf(".");
+ }
+
+ printf("|\n");
+}
+
+void
+hexdump(const char *label, uint8_t *data, size_t len)
+{
+ size_t i;
+ int x, n;
+
+ /*
+ * Layout:
+ * === first block === == second block == |........|\n
+ * first and second block are 8 bytes long (for a total of 48
+ * columns), plus two separator plus two | plus 16 chars, for
+ * a total of 68 characters.
+ */
+
+ printf("\nhexdump \"%s\": (%zu bytes)\n", label, len);
+ for (x = 0, n = 0, i = 0; i < len; ++i) {
+ if (i != 0 && i % 8 == 0) {
+ printf(" ");
+ x++;
+ }
+
+ if (n == 16) {
+ hexdump_ppline(x, &data[i - 16], 16);
+ x = 0;
+ n = 0;
+ }
+
+ printf("%02x ", data[i]);
+ x += 3;
+ n++;
+ }
+
+ if (n != 0)
+ hexdump_ppline(x, &data[i - n], n);
+
+ printf("\n");
+}
blob - f5c47029680f781be4f4e63ddea8ad0ffedfab95
blob + 5d1db0ca9655d142dd36c66b40d518738daa838c
--- utils.h
+++ utils.h
const char *pp_msg_type(uint8_t);
+void hexdump(const char *, uint8_t *data, size_t len);
+
#endif