Plan 9 from Bell Labs’s /usr/web/sources/contrib/steve/root/sys/src/cmd/ndb/glean/dump.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include <ip.h>
#include <ctype.h>
#include "nbcache.h"

void
dump(Pkt *p)
{
	uchar buf[16];
	int i, n, pos;

	pos = 0;
	while(p->pos < p->end){
		n = 16;
		if(p->end - p->pos < 16)
			n = p->end - p->pos;

		rmem(p, buf, n);
		print("%04x   ", pos);
		for(i = 0; i < n; i++)
			print("%02x ", buf[i]);
		for(; i < 16; i++)
			print("   ");
		print("    ");
		for(i = 0; i < n; i++)
			if(isprint(buf[i]))
				print("%c", buf[i]);
			else
				print(".");
		print("\n");
		pos += 16;
	}
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].