xref: /freebsd/sbin/ipf/libipf/mb_hexdump.c (revision efeb8bffe34422937c7f8df836afb5b817366d16)
141edb306SCy Schubert /*
241edb306SCy Schubert  * Copyright (C) 2012 by Darren Reed.
341edb306SCy Schubert  *
441edb306SCy Schubert  * See the IPFILTER.LICENCE file for details on licencing.
541edb306SCy Schubert  *
641edb306SCy Schubert  * $Id: mb_hexdump.c,v 1.1.2.3 2012/07/22 08:04:24 darren_r Exp $
741edb306SCy Schubert  */
841edb306SCy Schubert 
941edb306SCy Schubert #include "ipf.h"
1041edb306SCy Schubert 
1141edb306SCy Schubert void
mb_hexdump(mb_t * m,FILE * fp)12*efeb8bffSCy Schubert mb_hexdump(mb_t *m, FILE *fp)
1341edb306SCy Schubert {
1441edb306SCy Schubert 	u_char *s;
1541edb306SCy Schubert 	int len;
1641edb306SCy Schubert 	int i;
1741edb306SCy Schubert 
1841edb306SCy Schubert 	for (; m != NULL; m = m->mb_next) {
1941edb306SCy Schubert 		len = m->mb_len;
2041edb306SCy Schubert 		for (s = (u_char *)m->mb_data, i = 0; i < len; i++) {
2141edb306SCy Schubert 			fprintf(fp, "%02x", *s++ & 0xff);
2241edb306SCy Schubert 			if (len - i > 1) {
2341edb306SCy Schubert 				i++;
2441edb306SCy Schubert 				fprintf(fp, "%02x", *s++ & 0xff);
2541edb306SCy Schubert 			}
2641edb306SCy Schubert 			fputc(' ', fp);
2741edb306SCy Schubert 		}
2841edb306SCy Schubert 	}
2941edb306SCy Schubert 	fputc('\n', fp);
3041edb306SCy Schubert }
31