bsc_mgcp: optionally connect the MGCP socket to the MGW

This allows the use of the existing "call-agent ip A.B.C.D" command in
libmgcp in order to set a default destination address of the call agent.

This is required as a pre-condition for certain call agents (like the
zynetix MSC) that require a RSIP from the BSC to the MSC as the initial
MGCP message.
diff --git a/openbsc/src/osmo-bsc_mgcp/mgcp_main.c b/openbsc/src/osmo-bsc_mgcp/mgcp_main.c
index b334b06..3bacbe6 100644
--- a/openbsc/src/osmo-bsc_mgcp/mgcp_main.c
+++ b/openbsc/src/osmo-bsc_mgcp/mgcp_main.c
@@ -256,6 +256,17 @@
 			return -1;
 		}
 
+		if (cfg->call_agent_addr) {
+			addr.sin_port = htons(2727);
+			inet_aton(cfg->call_agent_addr, &addr.sin_addr);
+			if (connect(cfg->gw_fd.bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+				LOGP(DMGCP, LOGL_ERROR, "Failed to connect to: '%s'. errno: %d\n",
+				     cfg->call_agent_addr, errno);
+				close(cfg->gw_fd.bfd.fd);
+				cfg->gw_fd.bfd.fd = -1;
+				return -1;
+			}
+		}
 
 		if (osmo_fd_register(&cfg->gw_fd.bfd) != 0) {
 			LOGP(DMGCP, LOGL_FATAL, "Failed to register the fd\n");