network: use originating RTP packet address for loopback

When a connection is created in loopback mode all incoming
packets should be reflected back to their origin. If the
user did not supply a destination address with the CRCX
command all incoming packets will be tossed because no
destination address is officially known yet.

If there is no destination address set and the connection
is in loopback mode. Then use the originating address of
the incoming packet as destination address.

Change-Id: I3d1abe56d016e28c97f60635eb574679d36e2c52
diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c
index eb44f9b..aac3e51 100644
--- a/src/libosmo-mgcp/mgcp_network.c
+++ b/src/libosmo-mgcp/mgcp_network.c
@@ -1077,7 +1077,16 @@
 
 	/* Check if the connection is in loopback mode, if yes, just send the
 	 * incoming data back to the origin */
+
 	if (conn_src->conn->mode == MGCP_CONN_LOOPBACK) {
+		/* When we are in loopback mode, we loop back all incoming
+		 * packets back to their origin. We will use the originating
+		 * address data from the UDP packet header to patch the
+		 * outgoing address in connection on the fly */
+		if (conn_src->end.rtp_port == 0) {
+			conn_src->end.addr = addr.sin_addr;
+			conn_src->end.rtp_port = addr.sin_port;
+		}
 		return mgcp_send_rtp(proto, &addr, buf,
 				     len, conn_src, conn_src);
 	}