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
17.1
Igor Goncharovsky 6 years ago
parent 16ae4cd2db
commit 056ddf76ce

@ -1003,27 +1003,36 @@ static int get_to_address(int fd, struct sockaddr_in *toAddr)
{ {
#ifdef HAVE_PKTINFO #ifdef HAVE_PKTINFO
int err; int err;
struct msghdr msg; char cmbuf[0x100];
struct { struct cmsghdr *cmsg;
struct cmsghdr cm; struct sockaddr_in peeraddr;
int len; struct in_addr addr;
struct in_addr address; struct msghdr mh = {
} ip_msg; .msg_name = &peeraddr,
.msg_namelen = sizeof(peeraddr),
/* Zero out the structures before we use them */ .msg_control = cmbuf,
/* This sets several key values to NULL */ .msg_controllen = sizeof(cmbuf),
memset(&msg, 0, sizeof(msg)); };
memset(&ip_msg, 0, sizeof(ip_msg)); memset(&addr, 0, sizeof(addr));
/* Initialize the message structure */
msg.msg_control = &ip_msg;
msg.msg_controllen = sizeof(ip_msg);
/* Get info about the incoming packet */ /* Get info about the incoming packet */
err = recvmsg(fd, &msg, MSG_PEEK); err = recvmsg(fd, &mh, MSG_PEEK);
if (err == -1) { if (err == -1) {
ast_log(LOG_WARNING, "recvmsg returned an error: %s\n", strerror(errno)); ast_log(LOG_WARNING, "recvmsg returned an error: %s\n", strerror(errno));
return err;
}
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, &ip_msg.address, sizeof(struct in_addr)); }
}
memcpy(&toAddr->sin_addr, &addr, sizeof(struct in_addr));
return err; return err;
#else #else
memcpy(toAddr, &public_ip, sizeof(*toAddr)); memcpy(toAddr, &public_ip, sizeof(*toAddr));
@ -1031,6 +1040,7 @@ static int get_to_address(int fd, struct sockaddr_in *toAddr)
#endif #endif
} }
/* Allocate memory & initialize structures for a new phone */ /* Allocate memory & initialize structures for a new phone */
/* addr_from : ip address of the phone */ /* addr_from : ip address of the phone */
static struct unistimsession *create_client(const struct sockaddr_in *addr_from) static struct unistimsession *create_client(const struct sockaddr_in *addr_from)
@ -1042,7 +1052,10 @@ static struct unistimsession *create_client(const struct sockaddr_in *addr_from)
return NULL; return NULL;
memcpy(&s->sin, addr_from, sizeof(struct sockaddr_in)); memcpy(&s->sin, addr_from, sizeof(struct sockaddr_in));
get_to_address(unistimsock, &s->sout); if (get_to_address(unistimsock, &s->sout) < 0) {
ast_free(s);
return NULL;
}
s->sout.sin_family = AF_INET; s->sout.sin_family = AF_INET;
if (unistimdebug) { if (unistimdebug) {
ast_verb(0, "Creating a new entry for the phone from %s received via server ip %s\n", ast_verb(0, "Creating a new entry for the phone from %s received via server ip %s\n",

Loading…
Cancel
Save