aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/libmgcp/mgcp_common.c
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2016-10-14 17:56:17 +0200
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-01-23 13:58:01 +0100
commit5fc6d4bc4bed0dd05a34f097547dbb6af1814d8a (patch)
treea01556caecbd6c878ff96a956b518132e2000c5a /openbsc/src/libmgcp/mgcp_common.c
parent12f4f9d89fac989ced3cf7344e61a579a3c17eac (diff)
mgcp: handle responses from the MGCP GW
Diffstat (limited to 'openbsc/src/libmgcp/mgcp_common.c')
-rw-r--r--openbsc/src/libmgcp/mgcp_common.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/openbsc/src/libmgcp/mgcp_common.c b/openbsc/src/libmgcp/mgcp_common.c
index 9f104739a..4d7d36ab8 100644
--- a/openbsc/src/libmgcp/mgcp_common.c
+++ b/openbsc/src/libmgcp/mgcp_common.c
@@ -20,6 +20,8 @@
*
*/
+#include <errno.h>
+
#include <osmocom/core/utils.h>
#include <openbsc/mgcp.h>
@@ -30,3 +32,22 @@ const struct value_string mgcp_connection_mode_strs[] = {
{ MGCP_CONN_RECV_ONLY, "recvonly" },
{ MGCP_CONN_LOOPBACK, "loopback" },
};
+
+/* Ensure that the msg->l2h is NUL terminated. */
+int mgcp_msg_terminate_nul(struct msgb *msg)
+{
+ unsigned char *tail = msg->l2h + msgb_l2len(msg); /* char after l2 data */
+ if (tail[-1] == '\0')
+ /* nothing to do */;
+ else if (msgb_tailroom(msg) > 0)
+ tail[0] = '\0';
+ else if (tail[-1] == '\r' || tail[-1] == '\n')
+ tail[-1] = '\0';
+ else {
+ LOGP(DMGCP, LOGL_ERROR, "Cannot NUL terminate MGCP message: "
+ "Length: %d, Buffer size: %d\n",
+ msgb_l2len(msg), msg->data_len);
+ return -ENOTSUP;
+ }
+ return 0;
+}