[PATCH] osmo-mgw[master]: client: add ip address parsing to the client

dexter gerrit-no-reply at lists.osmocom.org
Tue Oct 10 14:58:04 UTC 2017


Hello Harald Welte, Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/4147

to look at the new patch set (#4).

client: add ip address parsing to the client

Some MGCP messages (CRCX, MDCX) return IP-Addresses. Make use of
this information.

Change-Id: I44b338b09de45e1675cedf9737fa72dde72e979a
---
M include/osmocom/mgcp_client/mgcp_client.h
M src/libosmo-mgcp-client/mgcp_client.c
M tests/mgcp_client/mgcp_client_test.c
M tests/mgcp_client/mgcp_client_test.ok
4 files changed, 32 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/47/4147/4

diff --git a/include/osmocom/mgcp_client/mgcp_client.h b/include/osmocom/mgcp_client/mgcp_client.h
index 1e92da7..ab273eb 100644
--- a/include/osmocom/mgcp_client/mgcp_client.h
+++ b/include/osmocom/mgcp_client/mgcp_client.h
@@ -36,6 +36,7 @@
 	char *body;
 	struct mgcp_response_head head;
 	uint16_t audio_port;
+        char audio_ip[INET_ADDRSTRLEN];
 };
 
 enum mgcp_verb {
diff --git a/src/libosmo-mgcp-client/mgcp_client.c b/src/libosmo-mgcp-client/mgcp_client.c
index 2bb669e..3bff1f0 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -174,7 +174,7 @@
 }
 
 /* Parse a line like "m=audio 16002 RTP/AVP 98" */
-static int mgcp_parse_audio(struct mgcp_response *r, const char *line)
+static int mgcp_parse_audio_port(struct mgcp_response *r, const char *line)
 {
         if (sscanf(line, "m=audio %hu",
 		   &r->audio_port) != 1)
@@ -184,7 +184,25 @@
 
 response_parse_failure:
 	LOGP(DLMGCP, LOGL_ERROR,
-	     "Failed to parse MGCP response header\n");
+	     "Failed to parse MGCP response header (audio port)\n");
+	return -EINVAL;
+}
+
+/* Parse a line like "c=IN IP4 10.11.12.13" */
+static int mgcp_parse_audio_ip(struct mgcp_response *r, const char *line)
+{
+	if (strlen(line) < 16)
+		goto response_parse_failure;
+
+	if (memcmp("c=IN IP4 ", line, 9) != 0)
+		goto response_parse_failure;
+
+	strcpy(r->audio_ip, line + 9);
+	return 0;
+
+response_parse_failure:
+	LOGP(DLMGCP, LOGL_ERROR,
+	     "Failed to parse MGCP response header (audio ip)\n");
 	return -EINVAL;
 }
 
@@ -213,7 +231,12 @@
 
 		switch (line[0]) {
 		case 'm':
-			rc = mgcp_parse_audio(r, line);
+			rc = mgcp_parse_audio_port(r, line);
+			if (rc)
+				return rc;
+			break;
+		case 'c':
+			rc = mgcp_parse_audio_ip(r, line);
 			if (rc)
 				return rc;
 			break;
diff --git a/tests/mgcp_client/mgcp_client_test.c b/tests/mgcp_client/mgcp_client_test.c
index 750aa0e..6671a3c 100644
--- a/tests/mgcp_client/mgcp_client_test.c
+++ b/tests/mgcp_client/mgcp_client_test.c
@@ -99,11 +99,13 @@
 	       "  head.response_code = %d\n"
 	       "  head.trans_id = %u\n"
 	       "  head.comment = %s\n"
-	       "  audio_port = %u\n",
+	       "  audio_port = %u\n"
+	       "  audio_ip = %s\n",
 	       response->head.response_code,
 	       response->head.trans_id,
 	       response->head.comment,
-	       response->audio_port
+	       response->audio_port,
+	       response->audio_ip
 	      );
 }
 
diff --git a/tests/mgcp_client/mgcp_client_test.ok b/tests/mgcp_client/mgcp_client_test.ok
index 7c4819d..3e84e89 100644
--- a/tests/mgcp_client/mgcp_client_test.ok
+++ b/tests/mgcp_client/mgcp_client_test.ok
@@ -28,6 +28,7 @@
   head.trans_id = 1
   head.comment = OK
   audio_port = 16002
+  audio_ip = 10.9.1.120
 
 Generated CRCX message:
 CRCX 1 23 at mgw MGCP 1.0

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

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I44b338b09de45e1675cedf9737fa72dde72e979a
Gerrit-PatchSet: 4
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder


More information about the gerrit-log mailing list