aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2015-08-09 18:15:16 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2015-08-09 18:15:16 +0200
commitce9792fc49e4722a927b790c08ad83bdad673e7e (patch)
tree25d6d097dfeea29bd997873c18fdebce9172763c
parentf9bdf5bec2f3778c4fef99da698a8a7a6f182fe0 (diff)
downloaddabmux-ce9792fc49e4722a927b790c08ad83bdad673e7e.tar.gz
dabmux-ce9792fc49e4722a927b790c08ad83bdad673e7e.tar.bz2
dabmux-ce9792fc49e4722a927b790c08ad83bdad673e7e.zip
EDI: Do not use misbehaving UdpPacket
-rw-r--r--src/DabMultiplexer.cpp15
-rw-r--r--src/UdpSocket.cpp25
-rw-r--r--src/UdpSocket.h13
-rw-r--r--src/dabOutput/edi/TagItems.cpp2
4 files changed, 38 insertions, 17 deletions
diff --git a/src/DabMultiplexer.cpp b/src/DabMultiplexer.cpp
index e9fb0c1..e1c815d 100644
--- a/src/DabMultiplexer.cpp
+++ b/src/DabMultiplexer.cpp
@@ -1790,15 +1790,12 @@ void DabMultiplexer::mux_frame(std::vector<boost::shared_ptr<DabOutput> >& outpu
// Send over ethernet
for (const auto& edi_frag : edi_fragments) {
- UdpPacket udppacket;
- InetAddress& addr = udppacket.getAddress();
+ InetAddress addr;
addr.setAddress(edi_conf.dest_addr.c_str());
addr.setPort(edi_conf.dest_port);
- udppacket.addData(&(edi_frag.front()), edi_frag.size());
-
- edi_output.send(udppacket);
+ edi_output.send(edi_frag, addr);
if (edi_conf.dump) {
std::ostream_iterator<uint8_t> debug_iterator(edi_debug_file);
@@ -1814,15 +1811,11 @@ void DabMultiplexer::mux_frame(std::vector<boost::shared_ptr<DabOutput> >& outpu
else {
// Send over ethernet
- UdpPacket udppacket;
-
- InetAddress& addr = udppacket.getAddress();
+ InetAddress addr;
addr.setAddress(edi_conf.dest_addr.c_str());
addr.setPort(edi_conf.dest_port);
- udppacket.addData(&(edi_afpacket.front()), edi_afpacket.size());
-
- edi_output.send(udppacket);
+ edi_output.send(edi_afpacket, addr);
if (edi_conf.dump) {
std::ostream_iterator<uint8_t> debug_iterator(edi_debug_file);
diff --git a/src/UdpSocket.cpp b/src/UdpSocket.cpp
index 74730e9..a1a7935 100644
--- a/src/UdpSocket.cpp
+++ b/src/UdpSocket.cpp
@@ -202,7 +202,6 @@ int UdpSocket::receive(UdpPacket &packet)
return 0;
}
-
/**
* Send an UDP packet.
* @param packet The UDP packet to be sent. It includes the data and the
@@ -229,6 +228,30 @@ int UdpSocket::send(UdpPacket &packet)
/**
+ * Send an UDP packet
+ *
+ * return 0 if ok, -1 if error
+ */
+int UdpSocket::send(std::vector<uint8_t> data, InetAddress destination)
+{
+#ifdef DUMP
+ TRACE_CLASS("UdpSocket", "send(vector<uint8_t>)");
+#endif
+ int ret = sendto(listenSocket, &data[0], data.size(), 0,
+ destination.getAddress(), sizeof(*destination.getAddress()));
+ if (ret == SOCKET_ERROR
+#ifndef _WIN32
+ && errno != ECONNREFUSED
+#endif
+ ) {
+ setInetError("Can't send UDP packet");
+ return -1;
+ }
+ return 0;
+}
+
+
+/**
* Must be called to receive data on a multicast address.
* @param groupname The multica
st address to join.
diff --git a/src/UdpSocket.h b/src/UdpSocket.h
index 109732f..e23401c 100644
--- a/src/UdpSocket.h
+++ b/src/UdpSocket.h
@@ -47,6 +47,8 @@
#include <stdlib.h>
#include <iostream>
+#include <vector>
+
class UdpPacket;
@@ -71,6 +73,8 @@ class UdpSocket {
int create(int port = 0, char *name = NULL);
int send(UdpPacket &packet);
+ int send(const std::vector<uint8_t> data);
+ int send(std::vector<uint8_t> data, InetAddress destination);
int receive(UdpPacket &packet);
int joinGroup(char* groupname);
/**
@@ -101,8 +105,10 @@ class UdpSocket {
class UdpPacket {
public:
UdpPacket(unsigned int initSize = 1024);
- // Not implemented
- UdpPacket(const UdpPacket& packet);
+ UdpPacket(const UdpPacket& packet) = delete;
+ const UdpPacket& operator=(const UdpPacket&) = delete;
+ UdpPacket(const UdpPacket&& packet) = delete;
+ const UdpPacket& operator=(const UdpPacket&&) = delete;
~UdpPacket();
char *getData();
@@ -114,8 +120,6 @@ class UdpPacket {
void setOffset(unsigned long val);
void setSize(unsigned newSize);
InetAddress &getAddress();
- // Not implemented
- const UdpPacket& operator=(const UdpPacket&);
private:
char *dataBuf;
@@ -124,3 +128,4 @@ class UdpPacket {
};
#endif // _UDPSOCKET
+
diff --git a/src/dabOutput/edi/TagItems.cpp b/src/dabOutput/edi/TagItems.cpp
index b97721a..f29eaeb 100644
--- a/src/dabOutput/edi/TagItems.cpp
+++ b/src/dabOutput/edi/TagItems.cpp
@@ -151,7 +151,7 @@ std::vector<uint8_t> TagESTn::Assemble()
packet.push_back((sstc >> 8) & 0xFF);
packet.push_back(sstc & 0xFF);
- for (size_t i = 0; i < mst_length; i++) {
+ for (size_t i = 0; i < mst_length * 8; i++) {
packet.push_back(mst_data[i]);
}