mgcp-client: Transmit remote IP addr in CRCX if known and port=0

A client may know the IP address during CRCX but not yet the port, or it
may simply want to hint an initial IP address so that the MGW can better
guess when allocating a local IP address.

Related: SYS#6657
Change-Id: I30165dbac5e484011d0acf46af36f105954a501d
diff --git a/src/libosmo-mgcp-client/mgcp_client_fsm.c b/src/libosmo-mgcp-client/mgcp_client_fsm.c
index 432ad84..218527c 100644
--- a/src/libosmo-mgcp-client/mgcp_client_fsm.c
+++ b/src/libosmo-mgcp-client/mgcp_client_fsm.c
@@ -136,10 +136,19 @@
 
 static void add_audio(struct mgcp_msg *mgcp_msg, struct mgcp_conn_peer *info)
 {
-	mgcp_msg->presence |= MGCP_MSG_PRESENCE_AUDIO_IP | MGCP_MSG_PRESENCE_AUDIO_PORT;
-	mgcp_msg->audio_ip = info->addr;
-	mgcp_msg->audio_port = info->port;
-	mgcp_msg->conn_mode = MGCP_CONN_RECV_SEND;
+	bool ip_is_set = info->addr[0] != '\0' &&
+			 strncmp(info->addr, "::", sizeof(info->addr)) != 0 &&
+			 strncmp(info->addr, "0.0.0.0", sizeof(info->addr)) != 0;
+	if (ip_is_set) {
+		mgcp_msg->presence |= MGCP_MSG_PRESENCE_AUDIO_IP;
+		mgcp_msg->audio_ip = info->addr;
+	}
+	if (info->port) {
+		mgcp_msg->presence |= MGCP_MSG_PRESENCE_AUDIO_PORT;
+		mgcp_msg->audio_port = info->port;
+	}
+	if (ip_is_set && info->port)
+		mgcp_msg->conn_mode = MGCP_CONN_RECV_SEND;
 }
 
 static void set_conn_mode(struct mgcp_msg *mgcp_msg, struct mgcp_conn_peer *peer)
@@ -221,8 +230,7 @@
 			 mgcp_ctx->conn_peer_local.endpoint);
 
 		make_crcx_msg(&mgcp_msg, &mgcp_ctx->conn_peer_local);
-		if (mgcp_ctx->conn_peer_local.port)
-			add_audio(&mgcp_msg, &mgcp_ctx->conn_peer_local);
+		add_audio(&mgcp_msg, &mgcp_ctx->conn_peer_local);
 		set_conn_mode(&mgcp_msg, &mgcp_ctx->conn_peer_local);
 
 		msg = mgcp_msg_gen(mgcp_ctx->mgcp, &mgcp_msg);