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:
parent
a2d8c367f6
commit
12b54fbbc2
70
socket.c
70
socket.c
@ -136,46 +136,44 @@ 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 (BufferAddr[0] == TS_SYNC_BYTE)
|
||||
return len;
|
||||
else if (len > 3) {
|
||||
// http://www.networksorcery.com/enp/rfc/rfc2250.txt
|
||||
// version
|
||||
unsigned int v = (BufferAddr[0] >> 6) & 0x03;
|
||||
// extension bit
|
||||
unsigned int x = (BufferAddr[0] >> 4) & 0x01;
|
||||
// cscr count
|
||||
unsigned int cc = BufferAddr[0] & 0x0F;
|
||||
// payload type: MPEG2 TS = 33
|
||||
//unsigned int pt = readBuffer[1] & 0x7F;
|
||||
// header lenght
|
||||
unsigned int headerlen = (3 + cc) * (unsigned int)sizeof(uint32_t);
|
||||
// check if extension
|
||||
if (x) {
|
||||
// extension header length
|
||||
unsigned int ehl = (((BufferAddr[headerlen + 2] & 0xFF) << 8) |
|
||||
(BufferAddr[headerlen + 3] & 0xFF));
|
||||
// update header length
|
||||
headerlen += (ehl + 1) * (unsigned int)sizeof(uint32_t);
|
||||
}
|
||||
// Check that rtp is version 2 and payload contains multiple of TS packet data
|
||||
if ((v == 2) && (((len - headerlen) % TS_SIZE) == 0) &&
|
||||
(BufferAddr[headerlen] == TS_SYNC_BYTE)) {
|
||||
// Set argument point to payload in read buffer
|
||||
memmove(BufferAddr, &BufferAddr[headerlen], (len - headerlen));
|
||||
return (len - headerlen);
|
||||
}
|
||||
}
|
||||
if (i->ipi_addr.s_addr != inetAddr)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (BufferAddr[0] == TS_SYNC_BYTE)
|
||||
return len;
|
||||
else if (len > 3) {
|
||||
// http://www.networksorcery.com/enp/rfc/rfc2250.txt
|
||||
// version
|
||||
unsigned int v = (BufferAddr[0] >> 6) & 0x03;
|
||||
// extension bit
|
||||
unsigned int x = (BufferAddr[0] >> 4) & 0x01;
|
||||
// cscr count
|
||||
unsigned int cc = BufferAddr[0] & 0x0F;
|
||||
// payload type: MPEG2 TS = 33
|
||||
//unsigned int pt = readBuffer[1] & 0x7F;
|
||||
// header lenght
|
||||
unsigned int headerlen = (3 + cc) * (unsigned int)sizeof(uint32_t);
|
||||
// check if extension
|
||||
if (x) {
|
||||
// extension header length
|
||||
unsigned int ehl = (((BufferAddr[headerlen + 2] & 0xFF) << 8) |
|
||||
(BufferAddr[headerlen + 3] & 0xFF));
|
||||
// update header length
|
||||
headerlen += (ehl + 1) * (unsigned int)sizeof(uint32_t);
|
||||
}
|
||||
// Check that rtp is version 2 and payload contains multiple of TS packet data
|
||||
if ((v == 2) && (((len - headerlen) % TS_SIZE) == 0) &&
|
||||
(BufferAddr[headerlen] == TS_SYNC_BYTE)) {
|
||||
// Set argument point to payload in read buffer
|
||||
memmove(BufferAddr, &BufferAddr[headerlen], (len - headerlen));
|
||||
return (len - headerlen);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -209,8 +207,8 @@ 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,
|
||||
(struct sockaddr *)&sockAddr, &addrlen);
|
||||
len = (int)recvfrom(socketDesc, BufferAddr, BufferLen, MSG_DONTWAIT,
|
||||
(struct sockaddr *)&sockAddr, &addrlen);
|
||||
//if (inetAddr != sockAddr.sin_addr.s_addr)
|
||||
// return -1;
|
||||
return len;
|
||||
|
Loading…
Reference in New Issue
Block a user