Index: trunk/BNC/src/bncnetqueryudp0.cpp
===================================================================
--- trunk/BNC/src/bncnetqueryudp0.cpp	(revision 6787)
+++ trunk/BNC/src/bncnetqueryudp0.cpp	(revision 11128)
@@ -14,4 +14,6 @@
  *
  * -----------------------------------------------------------------------*/
+
+#include <QHostInfo>
 
 #include "bncnetqueryudp0.h"
@@ -47,17 +49,34 @@
 void bncNetQueryUdp0::waitForReadyRead(QByteArray& outData) {
 
-  // Wait Loop
-  // ---------
-  if (!_udpSocket->hasPendingDatagrams()) {
-    _eventLoop->exec();
+  if (!_udpSocket) {
+    return;
   }
 
-  // Append Data
-  // -----------
-  QByteArray datagram;
-  datagram.resize(_udpSocket->pendingDatagramSize());
-  _udpSocket->readDatagram(datagram.data(), datagram.size());
+  while (true) {
 
-  outData.append(datagram);
+    // Wait Loop
+    // ---------
+    if (!_udpSocket->hasPendingDatagrams()) {
+      _eventLoop->exec();
+      if (!_udpSocket->hasPendingDatagrams()) { // stopped
+        return;
+      }
+    }
+
+    // Append Data, only from the accepted senders
+    // -------------------------------------------
+    QByteArray datagram;
+    QHostAddress sender;
+    datagram.resize(_udpSocket->pendingDatagramSize());
+    _udpSocket->readDatagram(datagram.data(), datagram.size(), &sender);
+    bool accepted = _senders.isEmpty();
+    for (int ii = 0; !accepted && ii < _senders.size(); ii++) {
+      accepted = sender.isEqual(_senders[ii], QHostAddress::ConvertV4MappedToIPv4);
+    }
+    if (accepted) {
+      outData.append(datagram);
+      return;
+    }
+  }
 }
 
@@ -67,4 +86,25 @@
 
   _status = running;
+
+  // Host of the URL: sender whose datagrams are accepted; 127.0.0.1 (as
+  // written by the 'Add Stream - Coming from UDP Port' dialog), localhost
+  // or 0.0.0.0: datagrams from any sender
+  _senders.clear();
+  QString host = url.host();
+  if (!host.isEmpty() && host != "127.0.0.1" && host != "localhost" && host != "0.0.0.0") {
+    QHostAddress address;
+    if (address.setAddress(host)) {
+      _senders << address;
+    }
+    else {
+      _senders = QHostInfo::fromName(host).addresses();
+      if (_senders.isEmpty()) {
+        emit newMessage(url.path().toLatin1().replace(0,1,"") +
+                        ": Cannot resolve UDP sender " + host.toLatin1(), true);
+        _status = error;
+        return;
+      }
+    }
+  }
 
   delete _udpSocket;
