aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc
diff options
context:
space:
mode:
Diffstat (limited to 'openbsc')
-rw-r--r--openbsc/tests/mgcp/Makefile.am3
-rw-r--r--openbsc/tests/mgcp/mgcp_test.c32
2 files changed, 34 insertions, 1 deletions
diff --git a/openbsc/tests/mgcp/Makefile.am b/openbsc/tests/mgcp/Makefile.am
index 8c365b416..470cdd80e 100644
--- a/openbsc/tests/mgcp/Makefile.am
+++ b/openbsc/tests/mgcp/Makefile.am
@@ -11,4 +11,5 @@ mgcp_test_SOURCES = mgcp_test.c
mgcp_test_LDADD = $(top_builddir)/src/libbsc/libbsc.a \
$(top_builddir)/src/libmgcp/libmgcp.a \
$(top_builddir)/src/libcommon/libcommon.a \
- $(LIBOSMOCORE_LIBS) -lrt $(LIBOSMOSCCP_LIBS) $(LIBOSMOVTY_LIBS)
+ $(LIBOSMOCORE_LIBS) -lrt $(LIBOSMOSCCP_LIBS) $(LIBOSMOVTY_LIBS) \
+ $(LIBRARY_DL)
diff --git a/openbsc/tests/mgcp/mgcp_test.c b/openbsc/tests/mgcp/mgcp_test.c
index 538dc9fa2..7eeef99af 100644
--- a/openbsc/tests/mgcp/mgcp_test.c
+++ b/openbsc/tests/mgcp/mgcp_test.c
@@ -16,6 +16,8 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#undef _GNU_SOURCE
+#define _GNU_SOURCE
#include <openbsc/mgcp.h>
#include <openbsc/mgcp_internal.h>
@@ -24,6 +26,7 @@
#include <osmocom/core/talloc.h>
#include <string.h>
#include <limits.h>
+#include <dlfcn.h>
char *strline_r(char *str, char **saveptr);
@@ -293,6 +296,31 @@ static int mgcp_test_policy_cb(struct mgcp_trunk_config *cfg, int endpoint,
return MGCP_POLICY_CONT;
}
+#define MGCP_DUMMY_LOAD 0x23
+static int dummy_packets = 0;
+/* override and forward */
+ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,
+ const struct sockaddr *dest_addr, socklen_t addrlen)
+{
+ typedef ssize_t (*sendto_t)(int, const void *, size_t, int,
+ const struct sockaddr *, socklen_t);
+ static sendto_t real_sendto = NULL;
+ uint32_t dest_host = htonl(((struct sockaddr_in *)dest_addr)->sin_addr.s_addr);
+ int dest_port = htons(((struct sockaddr_in *)dest_addr)->sin_port);
+
+ if (!real_sendto)
+ real_sendto = dlsym(RTLD_NEXT, "sendto");
+
+ if (len == 1 && ((const char *)buf)[0] == MGCP_DUMMY_LOAD ) {
+ fprintf(stderr, "Dummy packet to 0x%08x:%d, msg length %d\n%s\n\n",
+ dest_host, dest_port,
+ len, osmo_hexdump(buf, len));
+ dummy_packets += 1;
+ }
+
+ return real_sendto(sockfd, buf, len, flags, dest_addr, addrlen);
+}
+
static void test_messages(void)
{
struct mgcp_config *cfg;
@@ -326,6 +354,7 @@ static void test_messages(void)
printf("Testing %s\n", t->name);
last_endpoint = -1;
+ dummy_packets = 0;
inp = create_msg(t->req);
msg = mgcp_handle_message(cfg, inp);
@@ -337,6 +366,9 @@ static void test_messages(void)
printf("%s failed '%s'\n", t->name, (char *) msg->data);
msgb_free(msg);
+ if (dummy_packets)
+ printf("Dummy packets: %d\n", dummy_packets);
+
if (last_endpoint != -1) {
endp = &cfg->trunk.endpoints[last_endpoint];