1
0
mirror of https://github.com/rofafor/vdr-plugin-iptv.git synced 2023-10-10 13:37:03 +02:00

Refactored source address validation.

This commit is contained in:
Rolf Ahrenberg 2010-07-02 23:08:02 +03:00
parent a2d8c367f6
commit 12b54fbbc2

View File

@ -136,12 +136,14 @@ int cIptvUdpSocket::Read(unsigned char* BufferAddr, unsigned int BufferLen)
if (len < 0)
return -1;
else if (len > 0) {
// Process auxiliary received data
// Process auxiliary received data and validate source address
for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL; cmsg = CMSG_NXTHDR(&msgh, cmsg)) {
if ((cmsg->cmsg_level == SOL_IP) && (cmsg->cmsg_type == IP_PKTINFO)) {
struct in_pktinfo *i = (struct in_pktinfo *)CMSG_DATA(cmsg);
// Validate source address
if (i->ipi_addr.s_addr == inetAddr) {
if (i->ipi_addr.s_addr != inetAddr)
return 0;
}
}
if (BufferAddr[0] == TS_SYNC_BYTE)
return len;
else if (len > 3) {
@ -172,10 +174,6 @@ int cIptvUdpSocket::Read(unsigned char* BufferAddr, unsigned int BufferLen)
return (len - headerlen);
}
}
return 0;
}
}
}
}
return 0;
}
@ -209,7 +207,7 @@ int cIptvTcpSocket::Read(unsigned char* BufferAddr, unsigned int BufferLen)
socklen_t addrlen = sizeof(sockAddr);
// Read data from socket
if (isActive && socketDesc && BufferAddr && (BufferLen > 0))
len = recvfrom(socketDesc, BufferAddr, BufferLen, MSG_DONTWAIT,
len = (int)recvfrom(socketDesc, BufferAddr, BufferLen, MSG_DONTWAIT,
(struct sockaddr *)&sockAddr, &addrlen);
//if (inetAddr != sockAddr.sin_addr.s_addr)
// return -1;