Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

vdr-plugin-vnsiserver: make network interface portable, consider byte…

… alignment and padding
  • Loading branch information...
commit db8b2f6a3babfca5819ea83655df71b424b9d17b 1 parent e95eb15
@FernetMenta FernetMenta authored
View
19 addons/pvr.vdr.vnsi/vdr-plugin-vnsiserver/receiver.c
@@ -913,18 +913,15 @@ void cLiveStreamer::sendStreamPacket(sStreamPacket *pkt)
m_IFrameSeen = true;
- m_streamHeader.channel = htonl(VNSI_CHANNEL_STREAM); // stream channel
- m_streamHeader.opcode = htonl(VNSI_STREAM_MUXPKT); // Stream packet operation code
-
- m_streamHeader.id = htonl(pkt->id); // Stream ID
- m_streamHeader.duration = htonl(pkt->duration); // Duration
-
- *(int64_t*)&m_streamHeader.dts = __cpu_to_be64(pkt->dts); // DTS
- *(int64_t*)&m_streamHeader.pts = __cpu_to_be64(pkt->pts); // PTS
-
- m_streamHeader.length = htonl(pkt->size); // Data length
- m_Socket->write(&m_streamHeader, sizeof(m_streamHeader), -1, true);
+ if (!m_streamHeader.initStream(VNSI_STREAM_MUXPKT, pkt->id, pkt->duration, pkt->pts, pkt->dts))
+ {
+ ERRORLOG("stream response packet init fail");
+ return;
+ }
+ m_streamHeader.setLen(m_streamHeader.getStreamHeaderLength() + pkt->size);
+ m_streamHeader.finaliseStream();
+ m_Socket->write(m_streamHeader.getPtr(), m_streamHeader.getStreamHeaderLength(), -1, true);
m_Socket->write(pkt->data, pkt->size);
m_last_tick.Set(0);
View
12 addons/pvr.vdr.vnsi/vdr-plugin-vnsiserver/receiver.h
@@ -35,6 +35,7 @@
#include <vdr/ringbuffer.h>
#include "demuxer.h"
+#include "responsepacket.h"
class cxSocket;
class cChannel;
@@ -83,16 +84,7 @@ class cLiveStreamer : public cThread
cTimeMs m_last_tick;
bool m_SignalLost;
bool m_IFrameSeen;
-
- struct {
- uint32_t channel;
- uint32_t opcode;
- uint32_t id;
- uint32_t duration;
- uint8_t pts[sizeof(int64_t)];
- uint8_t dts[sizeof(int64_t)];
- uint32_t length;
- } m_streamHeader;
+ cResponsePacket m_streamHeader;
protected:
virtual void Action(void);
View
18 addons/pvr.vdr.vnsi/vdr-plugin-vnsiserver/requestpacket.c
@@ -85,7 +85,9 @@ uint8_t cRequestPacket::extract_U8()
uint32_t cRequestPacket::extract_U32()
{
if ((packetPos + sizeof(uint32_t)) > userDataLength) return 0;
- uint32_t ul = ntohl(*(uint32_t*)&userData[packetPos]);
+ uint32_t ul;
+ memcpy(&ul, &userData[packetPos], sizeof(uint32_t));
+ ul = ntohl(ul);
packetPos += sizeof(uint32_t);
return ul;
}
@@ -93,7 +95,9 @@ uint32_t cRequestPacket::extract_U32()
uint64_t cRequestPacket::extract_U64()
{
if ((packetPos + sizeof(uint64_t)) > userDataLength) return 0;
- uint64_t ull = __be64_to_cpu(*(uint64_t*)&userData[packetPos]);
+ uint64_t ull;
+ memcpy(&ull, &userData[packetPos], sizeof(uint64_t));
+ ull = __be64_to_cpu(ull);
packetPos += sizeof(uint64_t);
return ull;
}
@@ -101,9 +105,11 @@ uint64_t cRequestPacket::extract_U64()
double cRequestPacket::extract_Double()
{
if ((packetPos + sizeof(uint64_t)) > userDataLength) return 0;
- uint64_t ull = __be64_to_cpu(*(uint64_t*)&userData[packetPos]);
+ uint64_t ull;
+ memcpy(&ull, &userData[packetPos], sizeof(uint64_t));
+ ull = __be64_to_cpu(ull);
double d;
- memcpy(&d,&ull,sizeof(double));
+ memcpy(&d, &ull, sizeof(double));
packetPos += sizeof(uint64_t);
return d;
}
@@ -111,7 +117,9 @@ double cRequestPacket::extract_Double()
int32_t cRequestPacket::extract_S32()
{
if ((packetPos + sizeof(int32_t)) > userDataLength) return 0;
- int32_t l = ntohl(*(int32_t*)&userData[packetPos]);
+ int32_t l;
+ memcpy(&l, &userData[packetPos], sizeof(int32_t));
+ l = ntohl(l);
packetPos += sizeof(int32_t);
return l;
}
View
83 addons/pvr.vdr.vnsi/vdr-plugin-vnsiserver/responsepacket.c
@@ -70,9 +70,15 @@ bool cResponsePacket::init(uint32_t requestID)
{
initBuffers();
- *(uint32_t*)&buffer[0] = htonl(VNSI_CHANNEL_REQUEST_RESPONSE); // RR channel
- *(uint32_t*)&buffer[4] = htonl(requestID);
- *(uint32_t*)&buffer[userDataLenPos] = 0;
+ uint32_t ul;
+
+ ul = htonl(VNSI_CHANNEL_REQUEST_RESPONSE); // RR channel
+ memcpy(&buffer[0], &ul, sizeof(uint32_t));
+ ul = htonl(requestID);
+ memcpy(&buffer[4], &ul, sizeof(uint32_t));
+ ul = 0;
+ memcpy(&buffer[userDataLenPos], &ul, sizeof(uint32_t));
+
bufUsed = headerLength;
return true;
@@ -82,9 +88,15 @@ bool cResponsePacket::initScan(uint32_t opCode)
{
initBuffers();
- *(uint32_t*)&buffer[0] = htonl(VNSI_CHANNEL_SCAN); // RR channel
- *(uint32_t*)&buffer[4] = htonl(opCode);
- *(uint32_t*)&buffer[userDataLenPos] = 0;
+ uint32_t ul;
+
+ ul = htonl(VNSI_CHANNEL_SCAN); // RR channel
+ memcpy(&buffer[0], &ul, sizeof(uint32_t));
+ ul = htonl(opCode);
+ memcpy(&buffer[4], &ul, sizeof(uint32_t));
+ ul = 0;
+ memcpy(&buffer[userDataLenPos], &ul, sizeof(uint32_t));
+
bufUsed = headerLength;
return true;
@@ -94,25 +106,42 @@ bool cResponsePacket::initStatus(uint32_t opCode)
{
initBuffers();
- *(uint32_t*)&buffer[0] = htonl(VNSI_CHANNEL_STATUS); // RR channel
- *(uint32_t*)&buffer[4] = htonl(opCode);
- *(uint32_t*)&buffer[userDataLenPos] = 0;
+ uint32_t ul;
+
+ ul = htonl(VNSI_CHANNEL_STATUS); // RR channel
+ memcpy(&buffer[0], &ul, sizeof(uint32_t));
+ ul = htonl(opCode);
+ memcpy(&buffer[4], &ul, sizeof(uint32_t));
+ ul = 0;
+ memcpy(&buffer[userDataLenPos], &ul, sizeof(uint32_t));
+
bufUsed = headerLength;
return true;
}
-bool cResponsePacket::initStream(uint32_t opCode, uint32_t streamID, uint32_t duration, int64_t dts, int64_t pts)
+bool cResponsePacket::initStream(uint32_t opCode, uint32_t streamID, uint32_t duration, int64_t pts, int64_t dts)
{
initBuffers();
- *(uint32_t*)&buffer[0] = htonl(VNSI_CHANNEL_STREAM); // stream channel
- *(uint32_t*)&buffer[4] = htonl(opCode); // Stream packet operation code
- *(uint32_t*)&buffer[8] = htonl(streamID); // Stream ID
- *(uint32_t*)&buffer[12] = htonl(duration); // Duration
- *(int64_t*) &buffer[16] = __cpu_to_be64(dts); // DTS
- *(int64_t*) &buffer[24] = __cpu_to_be64(pts); // PTS
- *(uint32_t*)&buffer[userDataLenPosStream] = 0;
+ uint32_t ul;
+ uint64_t ull;
+
+ ul = htonl(VNSI_CHANNEL_STREAM); // stream channel
+ memcpy(&buffer[0], &ul, sizeof(uint32_t));
+ ul = htonl(opCode); // Stream packet operation code
+ memcpy(&buffer[4], &ul, sizeof(uint32_t));
+ ul = htonl(streamID); // Stream ID
+ memcpy(&buffer[8], &ul, sizeof(uint32_t));
+ ul = htonl(duration); // Duration
+ memcpy(&buffer[12], &ul, sizeof(uint32_t));
+ ull = __cpu_to_be64(pts); // PTS
+ memcpy(&buffer[16], &ull, sizeof(uint64_t));
+ ull = __cpu_to_be64(dts); // DTS
+ memcpy(&buffer[24], &ull, sizeof(uint64_t));
+ ul = 0;
+ memcpy(&buffer[userDataLenPosStream], &ul, sizeof(uint32_t));
+
bufUsed = headerLengthStream;
return true;
@@ -120,12 +149,14 @@ bool cResponsePacket::initStream(uint32_t opCode, uint32_t streamID, uint32_t du
void cResponsePacket::finalise()
{
- *(uint32_t*)&buffer[userDataLenPos] = htonl(bufUsed - headerLength);
+ uint32_t ul = htonl(bufUsed - headerLength);
+ memcpy(&buffer[userDataLenPos], &ul, sizeof(uint32_t));
}
void cResponsePacket::finaliseStream()
{
- *(uint32_t*)&buffer[userDataLenPosStream] = htonl(bufUsed - headerLengthStream);
+ uint32_t ul = htonl(bufUsed - headerLengthStream);
+ memcpy(&buffer[userDataLenPosStream], &ul, sizeof(uint32_t));
}
@@ -162,7 +193,8 @@ bool cResponsePacket::add_String(const char* string)
bool cResponsePacket::add_U32(uint32_t ul)
{
if (!checkExtend(sizeof(uint32_t))) return false;
- *(uint32_t*)&buffer[bufUsed] = htonl(ul);
+ uint32_t tmp = htonl(ul);
+ memcpy(&buffer[bufUsed], &tmp, sizeof(uint32_t));
bufUsed += sizeof(uint32_t);
return true;
}
@@ -178,7 +210,8 @@ bool cResponsePacket::add_U8(uint8_t c)
bool cResponsePacket::add_S32(int32_t l)
{
if (!checkExtend(sizeof(int32_t))) return false;
- *(int32_t*)&buffer[bufUsed] = htonl(l);
+ int32_t tmp = htonl(l);
+ memcpy(&buffer[bufUsed], &tmp, sizeof(int32_t));
bufUsed += sizeof(int32_t);
return true;
}
@@ -186,7 +219,8 @@ bool cResponsePacket::add_S32(int32_t l)
bool cResponsePacket::add_U64(uint64_t ull)
{
if (!checkExtend(sizeof(uint64_t))) return false;
- *(uint64_t*)&buffer[bufUsed] = __cpu_to_be64(ull);
+ uint64_t tmp = __cpu_to_be64(ull);
+ memcpy(&buffer[bufUsed], &tmp, sizeof(uint64_t));
bufUsed += sizeof(uint64_t);
return true;
}
@@ -195,8 +229,9 @@ bool cResponsePacket::add_double(double d)
{
if (!checkExtend(sizeof(double))) return false;
uint64_t ull;
- memcpy(&ull,&d,sizeof(double));
- *(uint64_t*)&buffer[bufUsed] = __cpu_to_be64(ull);
+ memcpy(&ull, &d, sizeof(double));
+ ull = __cpu_to_be64(ull);
+ memcpy(&buffer[bufUsed], &ull, sizeof(uint64_t));
bufUsed += sizeof(uint64_t);
return true;
}
View
4 addons/pvr.vdr.vnsi/vdr-plugin-vnsiserver/responsepacket.h
@@ -40,7 +40,7 @@ class cResponsePacket
bool init(uint32_t requestID);
bool initScan(uint32_t opCode);
bool initStatus(uint32_t opCode);
- bool initStream(uint32_t opCode, uint32_t streamID, uint32_t duration, int64_t dts, int64_t pts);
+ bool initStream(uint32_t opCode, uint32_t streamID, uint32_t duration, int64_t pts, int64_t dts);
void finalise();
void finaliseStream();
bool copyin(const uint8_t* src, uint32_t len);
@@ -56,6 +56,8 @@ class cResponsePacket
uint8_t* getPtr() { return buffer; }
uint32_t getLen() { return bufUsed; }
+ uint32_t getStreamHeaderLength() { return headerLengthStream; } ;
+ void setLen(uint32_t len) { bufUsed = len; }
private:
uint8_t* buffer;
View
7 addons/pvr.vdr.vnsi/vdr-plugin-vnsiserver/vnsiclient.c
@@ -162,8 +162,11 @@ void cVNSIClient::Action(void)
kaTimeStamp = ntohl(kaTimeStamp);
uint8_t buffer[8];
- *(uint32_t*)&buffer[0] = htonl(3); // KA CHANNEL
- *(uint32_t*)&buffer[4] = htonl(kaTimeStamp);
+ uint32_t ul;
+ ul = htonl(3); // KA CHANNEL
+ memcpy(&buffer[0], &ul, sizeof(uint32_t));
+ ul = htonl(kaTimeStamp);
+ memcpy(&buffer[4], &ul, sizeof(uint32_t));
if (!m_socket.write(buffer, 8))
{
ERRORLOG("Could not send back KA reply");

0 comments on commit db8b2f6

Please sign in to comment.
Something went wrong with that request. Please try again.