[PATCH] libosmo-sccp[master]: xua_msg: Add xua_msg_dump() to print parsed XUA message

Harald Welte gerrit-no-reply at lists.osmocom.org
Wed Feb 15 23:05:55 UTC 2017


Review at  https://gerrit.osmocom.org/1831

xua_msg: Add xua_msg_dump() to print parsed XUA message

Change-Id: I2f3ae77f440e0c27f78302cdb80e1d25fe5aebb6
---
M include/osmocom/sigtran/xua_msg.h
M src/xua_msg.c
2 files changed, 31 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmo-sccp refs/changes/31/1831/1

diff --git a/include/osmocom/sigtran/xua_msg.h b/include/osmocom/sigtran/xua_msg.h
index 2a6e3ae..949c850 100644
--- a/include/osmocom/sigtran/xua_msg.h
+++ b/include/osmocom/sigtran/xua_msg.h
@@ -63,3 +63,4 @@
 uint32_t xua_msg_part_get_u32(struct xua_msg_part *part);
 uint32_t xua_msg_get_u32(struct xua_msg *xua, uint16_t iei);
 int xua_msg_add_sccp_addr(struct xua_msg *xua, uint16_t iei, const struct osmo_sccp_addr *addr);
+char *xua_msg_dump(struct xua_msg *xua);
diff --git a/src/xua_msg.c b/src/xua_msg.c
index be3b9a2..f7b0386 100644
--- a/src/xua_msg.c
+++ b/src/xua_msg.c
@@ -287,3 +287,33 @@
 
 	return rc;
 }
+
+static void append_to_buf(char *buf, bool *comma, const char *fmt, ...)
+{
+	va_list ap;
+
+	va_start(ap, fmt);
+	if (!comma || *comma == true) {
+		strcat(buf, ",");
+	} else if (comma)
+		*comma = true;
+	vsprintf(buf+strlen(buf), fmt, ap);
+	va_end(ap);
+}
+
+char *xua_msg_dump(struct xua_msg *xua)
+{
+	static char buf[1024];
+	struct xua_msg_part *part;
+
+	buf[0] = '\0';
+
+	append_to_buf(buf, NULL, "HDR=(V=%u,C=0x%04x,T=0x%04x,LEN=%u)",
+			xua->hdr.version, xua->hdr.msg_class,
+			xua->hdr.msg_type, xua->hdr.msg_length);
+	llist_for_each_entry(part, &xua->headers, entry)
+		append_to_buf(buf, NULL, "\n\tPART(T=0x%04x,L=%u,D=%s)",
+				part->tag, part->len,
+				osmo_hexdump_nospc(part->dat, part->len));
+	return buf;
+}

-- 
To view, visit https://gerrit.osmocom.org/1831
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2f3ae77f440e0c27f78302cdb80e1d25fe5aebb6
Gerrit-PatchSet: 1
Gerrit-Project: libosmo-sccp
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>


More information about the gerrit-log mailing list