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/gerrit-log@lists.osmocom.org/.
dexter gerrit-no-reply at lists.osmocom.orgReview at https://gerrit.osmocom.org/4147 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, 41 insertions(+), 5 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/47/4147/1 diff --git a/include/osmocom/mgcp_client/mgcp_client.h b/include/osmocom/mgcp_client/mgcp_client.h index 9368a76..f0d5fdc 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; + uint32_t audio_ip; }; enum mgcp_verb { diff --git a/src/libosmo-mgcp-client/mgcp_client.c b/src/libosmo-mgcp-client/mgcp_client.c index 175f81a..bbab3f4 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,28 @@ 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) +{ + char buf[32]; + + if (strlen(line) < 16) + goto response_parse_failure; + + if (memcmp("c=IN IP4 ", line, 9) != 0) + goto response_parse_failure; + + strcpy(buf, line + 9); + r->audio_ip = inet_addr(buf); + return 0; + +response_parse_failure: + LOGP(DLMGCP, LOGL_ERROR, + "Failed to parse MGCP response header (audio ip)\n"); return -EINVAL; } @@ -213,7 +234,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 1ed6a9a..b648986 100644 --- a/tests/mgcp_client/mgcp_client_test.c +++ b/tests/mgcp_client/mgcp_client_test.c @@ -97,16 +97,24 @@ { OSMO_ASSERT(priv == mgcp); mgcp_response_parse_params(response); + char buf[256]; + struct sockaddr_in sa; + + struct in_addr addr; + addr.s_addr = response->audio_ip; + inet_ntop(AF_INET, &(sa.sin_addr), buf, INET_ADDRSTRLEN); printf("response cb received:\n" " 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, + inet_ntoa(addr) ); } 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: newchange Gerrit-Change-Id: I44b338b09de45e1675cedf9737fa72dde72e979a Gerrit-PatchSet: 1 Gerrit-Project: osmo-mgw Gerrit-Branch: master Gerrit-Owner: dexter <pmaier at sysmocom.de>