xref: /freebsd/sbin/ipf/libipf/mb_hexdump.c (revision 994297b01b98816bea1abf45ae4bac1bc69ee7a0)
1 /*
2  * Copyright (C) 2012 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * $Id: mb_hexdump.c,v 1.1.2.3 2012/07/22 08:04:24 darren_r Exp $
7  */
8 
9 #include "ipf.h"
10 
11 void
12 mb_hexdump(mb_t *m, FILE *fp)
13 {
14 	u_char *s;
15 	int len;
16 	int i;
17 
18 	for (; m != NULL; m = m->mb_next) {
19 		len = m->mb_len;
20 		for (s = (u_char *)m->mb_data, i = 0; i < len; i++) {
21 			fprintf(fp, "%02x", *s++ & 0xff);
22 			if (len - i > 1) {
23 				i++;
24 				fprintf(fp, "%02x", *s++ & 0xff);
25 			}
26 			fputc(' ', fp);
27 		}
28 	}
29 	fputc('\n', fp);
30 }
31