[mythtv] [patch] allow DNS names as well as IP addresses in server setup

Eric Cooper ecc at cmu.edu
Sun Mar 6 16:53:22 UTC 2005


On Sat, Mar 05, 2005 at 09:14:10PM -0500, Isaac Richards wrote:
> On Saturday 05 March 2005 09:07 pm, Eric Cooper wrote:
> > On Sat, Mar 05, 2005 at 09:01:15PM -0500, Isaac Richards wrote:
> > > On Saturday 05 March 2005 06:33 pm, Anduin Withers wrote:
> > > > > The following patch allows you to put in either hostnames or IP
> > > > > addresses in the BackendServerIP and MasterServerIP fields.
> > > > > I've only minimally tested it, but it seems to work in my setup.
> > > >
> > > > 4. You might want to push it through inet_aton first, only when it is
> > > > invalid push it to gethostbyname (instead of defaulting to a lookup and
> > > > falling back).
> > >
> > > Or just use the Qt DNS classes.
> >
> > I looked at that, but version 3 Qt only has asynchronous DNS lookups
> > that would require a more global change -- it was much less invasive
> > to use C's gethostbyname.  The version 4 Qt DNS class has a
> > synchronous call that would be cleaner.
> 
> It's rather easy to make it synchronous.  gethostbyname2 isn't portable.

OK, second try attached.

-- 
Eric Cooper             e c c @ c m u . e d u
-------------- next part --------------
diff -ur mythtv-0.17-orig/libs/libmyth/util.cpp mythtv-0.17/libs/libmyth/util.cpp
--- mythtv-0.17-orig/libs/libmyth/util.cpp	2005-01-27 18:43:13.000000000 -0500
+++ mythtv-0.17/libs/libmyth/util.cpp	2005-03-05 22:50:59.000000000 -0500
@@ -1,4 +1,5 @@
 #include <qapplication.h>
+#include <qdns.h>
 
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -78,8 +79,15 @@
 
 bool connectSocket(QSocketDevice *socket, const QString &host, int port)
 {
-    QHostAddress hadr;
-    hadr.setAddress(host);
+    QDns query(host);
+    while (query.isWorking ())
+	qApp->processEvents();
+    QValueList<QHostAddress> addrs = query.addresses();
+    if (addrs.empty()) {
+	VERBOSE(VB_NETWORK, QString("Unknown host: %1").arg(host));
+	return false;
+    }
+    QHostAddress hadr = addrs.first();
     
     socket->setAddressReusable(true);
     bool result = socket->connect(hadr, port);


More information about the mythtv-dev mailing list