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

Eric Cooper ecc at cmu.edu
Sat Mar 5 22:42:48 UTC 2005


I recently changed my home network to use DHCP with dynamic DNS
update, so I have almost no static IP addresses.  But I couldn't do
that with my MythTV backend machine, which required a static IP in the
database.

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.

I haven't been following this list, so my apologies if this feature
was previously considered and decided against for some reason (if so,
I couldn't find it in the archives).

-- 
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 16:01:07.000000000 -0500
@@ -4,6 +4,7 @@
 #include <sys/wait.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <netdb.h>
 
 #include "config.h"
 
@@ -79,7 +80,12 @@
 bool connectSocket(QSocketDevice *socket, const QString &host, int port)
 {
     QHostAddress hadr;
-    hadr.setAddress(host);
+    struct hostent *h = gethostbyname2(host, AF_INET);
+    if (h == 0 || h->h_length == 0) {
+	hadr.setAddress(host);
+    } else {
+	hadr.setAddress(ntohl(*(Q_UINT32 *)h->h_addr_list[0]));
+    }
     
     socket->setAddressReusable(true);
     bool result = socket->connect(hadr, port);


More information about the mythtv-dev mailing list