[PATCH 1/2] msgb: Add msgb_hexdump() function

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Holger Hans Peter Freyther holger at freyther.de
Sun Mar 2 07:06:17 UTC 2014


On Fri, Feb 28, 2014 at 08:47:45PM +0100, Jacob Erlbeck wrote:

Good morning Jacob,

as usual thank you very much for your work.


> This function works like osmo_hexdump() and return a static buffer

						^ returns

> containing hex bytes along with markes for the layers.

				   ^ markers

> +/*! \brief Return (static) buffer containing a hexdump of the msg

              ^ Return "a" 
           
> +const char *msgb_hexdump(const struct msgb *msg)
> +{
> +	static char buf[4100];
> +	int buf_offs = 0;
> +	int nchars;
> +	const unsigned char *start = msg->data;
> +	const unsigned char *lxhs[4];
> +	int i;
> +
> +	lxhs[0] = msg->l1h;
> +	lxhs[1] = msg->l2h;
> +	lxhs[2] = msg->l3h;
> +	lxhs[3] = msg->l4h;
> +
> +	for (i = 0; i < ARRAY_SIZE(lxhs); i++) {
> +		if (lxhs[i]) {


		if (!lxhs[i])
			continue;

This avoids having the show at three levels of indention in.


> +			nchars = snprintf(buf + buf_offs, sizeof(buf) - buf_offs,
> +					  "%s[L%d]> ",
> +					  osmo_hexdump(start, lxhs[i] - start),
> +					  i+1);

> +	nchars = snprintf(buf + buf_offs, sizeof(buf) - buf_offs,
> +			  "%s", osmo_hexdump(start, msg->tail - start));
> +	nchars = snprintf(buf, sizeof(buf) - buf_offs,
> +			  "!!! L%d out of range", i+1);

So sizeof(buf) - buf_offs can only be 0 when the output is already null
terminated?

kind regards
	holger




More information about the OpenBSC mailing list