[Asterisk-code-review] chan_unistim: Fix clang warning: variable sized type not at end of a ... (...asterisk[13])

Igor Goncharovsky asteriskteam at digium.com
Tue Aug 27 06:15:17 CDT 2019


Igor Goncharovsky has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/12807


Change subject: chan_unistim: Fix clang warning: variable sized type not at end of a struct
......................................................................

chan_unistim: Fix clang warning: variable sized type not at end of a struct

On reading information about initial client packet unistim use dirty
implementation of destination ip address retrieval. This fix uses
CMSG_*(..) to get ip address and make clang compile without warning.

ASTERISK-25592 #close
Reported-by: Alexander Traud

Change-Id: Ic1fd34c2c2bcc951da65bf62e3f7a8adff8351b1
---
M channels/chan_unistim.c
1 file changed, 26 insertions(+), 17 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/07/12807/1

diff --git a/channels/chan_unistim.c b/channels/chan_unistim.c
index b846585..1ef373a 100644
--- a/channels/chan_unistim.c
+++ b/channels/chan_unistim.c
@@ -1004,27 +1004,35 @@
 {
 #ifdef HAVE_PKTINFO
 	int err;
-	struct msghdr msg;
-	struct {
-		struct cmsghdr cm;
-		int len;
-		struct in_addr address;
-	} ip_msg;
-
-	/* Zero out the structures before we use them */
-	/* This sets several key values to NULL */
-	memset(&msg, 0, sizeof(msg));
-	memset(&ip_msg, 0, sizeof(ip_msg));
-
-	/* Initialize the message structure */
-	msg.msg_control = &ip_msg;
-	msg.msg_controllen = sizeof(ip_msg);
+	char cmbuf[0x100];
+	struct cmsghdr *cmsg;
+	struct sockaddr_in peeraddr;
+	struct in_addr addr;
+	struct msghdr mh = {
+		.msg_name = &peeraddr,
+		.msg_namelen = sizeof(peeraddr),
+		.msg_control = cmbuf,
+		.msg_controllen = sizeof(cmbuf),
+	};
+	memset(&addr, 0, sizeof(addr));
 	/* Get info about the incoming packet */
-	err = recvmsg(fd, &msg, MSG_PEEK);
+	err = recvmsg(fd, &mh, MSG_PEEK);
 	if (err == -1) {
 		ast_log(LOG_WARNING, "recvmsg returned an error: %s\n", strerror(errno));
 	}
-	memcpy(&toAddr->sin_addr, &ip_msg.address, sizeof(struct in_addr));
+	for(cmsg = CMSG_FIRSTHDR(&mh);
+		cmsg != NULL;
+		cmsg = CMSG_NXTHDR(&mh, cmsg))
+	{
+		 if (cmsg->cmsg_level == IPPROTO_IP && cmsg->cmsg_type == IP_PKTINFO) {
+			struct in_pktinfo *pkt = (struct in_pktinfo*)CMSG_DATA(cmsg);
+			addr = pkt->ipi_addr;
+			if (unistimdebug) {
+				ast_verb(0, "message received on address %s\n", ast_inet_ntoa(addr));
+			}
+		}
+	}
+	memcpy(&toAddr->sin_addr, &addr, sizeof(struct in_addr));
 	return err;
 #else
 	memcpy(toAddr, &public_ip, sizeof(*toAddr));
@@ -1032,6 +1040,7 @@
 #endif
 }
 
+
 /* Allocate memory & initialize structures for a new phone */
 /* addr_from : ip address of the phone */
 static struct unistimsession *create_client(const struct sockaddr_in *addr_from)

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/12807
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: Ic1fd34c2c2bcc951da65bf62e3f7a8adff8351b1
Gerrit-Change-Number: 12807
Gerrit-PatchSet: 1
Gerrit-Owner: Igor Goncharovsky <igor.goncharovsky at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190827/efe59fc8/attachment.html>


More information about the asterisk-code-review mailing list