Index: libs/libmyth/libmyth.pro
===================================================================
--- libs/libmyth/libmyth.pro	(revision 8106)
+++ libs/libmyth/libmyth.pro	(working copy)
@@ -22,6 +22,7 @@
 HEADERS += langsettings.h audiooutputnull.h
 HEADERS += DisplayResScreen.h util-x11.h mythdeque.h qmdcodec.h
 HEADERS += exitcodes.h virtualkeyboard.h
+HEADERS += zeroconfigclient.h
 
 SOURCES += dialogbox.cpp lcddevice.cpp mythcontext.cpp mythwidgets.cpp 
 SOURCES += oldsettings.cpp remotefile.cpp settings.cpp themedmenu.cpp
@@ -32,7 +33,7 @@
 SOURCES += volumecontrol.cpp volumebase.cpp audiooutputbase.cpp
 SOURCES += dbsettings.cpp screensaver.cpp screensaver-null.cpp output.cpp
 SOURCES += langsettings.cpp mythdbcon.cpp audiooutputnull.cpp
-SOURCES += DisplayResScreen.cpp util-x11.cpp qmdcodec.cpp
+SOURCES += DisplayResScreen.cpp util-x11.cpp qmdcodec.cpp zeroconfigclient.cpp
 SOURCES += virtualkeyboard.cpp
 
 INCLUDEPATH += ../libmythsamplerate ../libmythsoundtouch ../..
Index: libs/libmyth/mythcontext.cpp
===================================================================
--- libs/libmyth/mythcontext.cpp	(revision 8106)
+++ libs/libmyth/mythcontext.cpp	(working copy)
@@ -19,6 +19,7 @@
 
 #include "config.h"
 #include "mythcontext.h"
+#include "zeroconfigclient.h"
 #include "exitcodes.h"
 #include "oldsettings.h"
 #include "themedmenu.h"
@@ -550,8 +551,30 @@
 
 bool MythContextPrivate::FixSettingsFile(void)
 {
+    DatabaseParams defaultParams;
+
+    /* Zero Configuration attempt */
+    VERBOSE(VB_IMPORTANT, "Trying to find a backend on the network");
+
+    /* Try to connect to the backend */
+    ZeroConfigClient *zeroconfigclient = new ZeroConfigClient(true);
+    defaultParams = zeroconfigclient->GetDBInfo();
+
+    /* Lets give zeroconfig 2 seconds to find the backend */
+    sleep(2);
+
+    /* We got some data from the backend */
+    if(zeroconfigclient->FoundBackend())
+    {
+	VERBOSE(VB_IMPORTANT, "Found Mythtv Backend via zeroconfig");
+        return WriteSettingsFile(defaultParams);
+    }
+
+    /* Standard attempt, Zero Configuration failed */
+    VERBOSE(VB_IMPORTANT, "ZeroConfig failed, unable to find a master backend"
+		          " to get database details from");
     VERBOSE(VB_IMPORTANT, "Trying to create a basic mysql.txt file");
-    DatabaseParams defaultParams = parent->GetDatabaseParams();
+    defaultParams = parent->GetDatabaseParams();
     
     return WriteSettingsFile(defaultParams);
 }
Index: libs/libmyth/zeroconfigclient.cpp
===================================================================
--- libs/libmyth/zeroconfigclient.cpp	(revision 0)
+++ libs/libmyth/zeroconfigclient.cpp	(revision 0)
@@ -0,0 +1,163 @@
+#include <unistd.h>
+#include <qsqldatabase.h>
+#include <qsqlquery.h>
+#include <qregexp.h>
+#include <qstring.h>
+#include <qdatetime.h>
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <stdio.h>
+
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+
+using namespace std;
+
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include "mythcontext.h"
+#include "zeroconfigclient.h"
+
+ZeroConfigClient::ZeroConfigClient(bool runthread)
+{
+    foundBackend = false;
+
+    threadrunning = runthread;
+
+    if (runthread)
+    {
+        pthread_create(&zeroconfigclientthread, NULL, ZeroConfigClientThread, this);
+    }
+}
+ 
+ZeroConfigClient::~ZeroConfigClient()
+{
+    pthread_cancel(zeroconfigclientthread);
+}
+
+void *ZeroConfigClient::ZeroConfigClientThread(void *param)
+{
+    ZeroConfigClient *zeroconfigclient = (ZeroConfigClient *)param;
+    zeroconfigclient->GetDBInfo();
+
+    return NULL;
+}
+
+DatabaseParams ZeroConfigClient::GetDBInfo(void)
+{
+    // Parse the returned data and store it in the defaultParams structure
+    DatabaseParams dbParams;
+
+    int bytesRecieved;
+    struct sockaddr_in serveraddr;
+    char sendmsg[15] = "MYTHTVDISCOVER";
+    char buffer[10000];
+    QString recvmsg;
+    int x = 1;
+
+    // Clear the structure
+    bzero(&serveraddr,sizeof(serveraddr));
+
+    // Create the UDP socket
+    socketfd = socket(AF_INET,SOCK_DGRAM,0);
+
+    // Set the socket so that we can broadcast to the entire network
+    setsockopt(socketfd, SOL_SOCKET, SO_BROADCAST, (char*) &x, sizeof(int));
+
+    // Set the important information
+    serveraddr.sin_family = AF_INET;
+    serveraddr.sin_addr.s_addr = inet_addr("255.255.255.255");
+    serveraddr.sin_port = htons(32000);
+
+    // Broadcast the message
+    sendto(socketfd, sendmsg, strlen(sendmsg), 0, (struct sockaddr *)&serveraddr, sizeof(serveraddr));
+
+    // Recieve the response from the server
+    //   We have to get all the data in one "swoop" since UDP doesn't allow re-broadcasts,
+    //   which means we have to have a large buffer for the largest possible response that
+    //   can be expected
+
+    bytesRecieved = recvfrom(socketfd, buffer, sizeof(buffer), 0, NULL, NULL);
+    recvmsg.append(buffer);
+
+#if DEBUG
+    printf("buffer: %s\n", buffer);
+    printf("recvmsg: %s\n", recvmsg.ascii());
+#endif
+    bzero(buffer, sizeof(buffer));
+
+    foundBackend = true;
+
+    QString str(recvmsg);
+
+#if DEBUG
+    printf("str: %s\n", str.ascii());
+#endif
+    QString parameter(" ");
+    QString value(" ");
+
+    int cnt = 0;
+    QString tmp(str.section(';', cnt, cnt));
+    parameter = tmp.section(':', 0, 0);
+    value = tmp.section(':', 1, 1);
+
+    while( (!parameter.isNull() && !parameter.isEmpty()) && (!value.isNull() && !value.isEmpty()) )
+    {
+#if DEBUG
+        // Print out each parameter and value
+        printf(">>>>>parameter: [%s]\n", parameter.ascii());
+        printf(">>>>>value: [%s]\n", value.ascii());
+#endif
+	
+        if(parameter.compare("dbHostName") == 0)
+        {
+             dbParams.dbHostName = value;
+        }
+        else if(parameter.compare("dbUserName") == 0)
+        {
+             dbParams.dbUserName = value;
+        }
+        else if(parameter.compare("dbPassword") == 0)
+        {
+             dbParams.dbPassword = value;
+        }
+        else if(parameter.compare("dbName") == 0)
+        {
+             dbParams.dbName = value;
+        }
+        else if(parameter.compare("dbType") == 0)
+        {
+             dbParams.dbType = value;
+        }
+
+        cnt++;
+        
+        QString tmp(str.section(';', cnt, cnt));
+        parameter = tmp.section(':', 0, 0);
+        value = tmp.section(':', 1, 1);
+    }
+
+#if DEBUG
+    // Print out the values we were able to parse out
+    printf("-----------------------------\n");
+    printf("dbHostName: %s\n",dbParams.dbHostName.ascii());
+    printf("dbUserName: %s\n",dbParams.dbUserName.ascii());
+    printf("dbPassword: %s\n",dbParams.dbPassword.ascii());
+    printf("dbName: %s\n",dbParams.dbName.ascii());
+    printf("dbType: %s\n",dbParams.dbType.ascii());
+    printf("-----------------------------\n");
+#endif
+
+    return dbParams;
+}
+
+bool ZeroConfigClient::FoundBackend()
+{
+    return foundBackend;
+}
Index: libs/libmyth/zeroconfigclient.h
===================================================================
--- libs/libmyth/zeroconfigclient.h	(revision 0)
+++ libs/libmyth/zeroconfigclient.h	(revision 0)
@@ -0,0 +1,30 @@
+#include <qobject.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <stdio.h>
+
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+
+#include "mythcontext.h"
+
+using namespace std;
+
+class ZeroConfigClient : public QObject
+{
+  public:
+    ZeroConfigClient(bool runthread);
+    ~ZeroConfigClient();
+    bool FoundBackend();
+    DatabaseParams GetDBInfo(void);
+
+  protected:
+    static void *ZeroConfigClientThread(void *param);
+
+  private:
+    pthread_t zeroconfigclientthread;
+    bool threadrunning;
+    bool foundBackend;
+    int socketfd;
+};
Index: programs/mythbackend/main.cpp
===================================================================
--- programs/mythbackend/main.cpp	(revision 8106)
+++ programs/mythbackend/main.cpp	(working copy)
@@ -22,6 +22,7 @@
 #include "tv.h"
 #include "autoexpire.h"
 #include "scheduler.h"
+#include "zeroconfigserver.h"
 #include "mainserver.h"
 #include "encoderlink.h"
 #include "remoteutil.h"
@@ -38,6 +39,7 @@
 AutoExpire *expirer = NULL;
 Scheduler *sched = NULL;
 JobQueue *jobqueue = NULL;
+ZeroConfigServer *zeroconfigserver = NULL;
 QString pidfile;
 QString lockfile_location;
 HouseKeeper *housekeeping = NULL;
@@ -233,6 +235,7 @@
     bool nosched = false;
     bool nojobqueue = false;
     bool noexpirer = false;
+    bool usezeroconfig = false;
     bool printexpire = false;
     for (int argpos = 1; argpos < a.argc(); ++argpos)
     {
@@ -317,6 +320,10 @@
         {
             noexpirer = true;
         } 
+        else if (!strcmp(a.argv()[argpos],"--usezeroconfig"))
+        {
+            usezeroconfig = true;
+        }
         else if (!strcmp(a.argv()[argpos],"--printexpire"))
         {
             printexpire = true;
@@ -349,6 +356,7 @@
                     "--nosched                      Do not perform any scheduling" << endl <<
                     "--nojobqueue                   Do not start the JobQueue" << endl <<
                     "--noautoexpire                 Do not start the AutoExpire thread" << endl <<
+                    "--usezeroconfig                Enable the Zero Configuration thread" << endl <<
                     "--version                      Version information" << endl;
             return BACKEND_EXIT_INVALID_CMDLINE;
         }
@@ -517,6 +525,15 @@
     else
         jobqueue = new JobQueue(ismaster);
 
+    if(usezeroconfig)
+    {
+        cerr << "********* Using Zero Config *********\n";
+        zeroconfigserver = new ZeroConfigServer(true);
+    }
+    else
+    {
+        cerr << "********* The Zero Config has been DISABLED by default*********\n";
+    }
     VERBOSE(VB_ALL, QString("%1 version: %2 www.mythtv.org")
                             .arg(binname).arg(MYTH_BINARY_VERSION));
 
Index: programs/mythbackend/mythbackend.pro
===================================================================
--- programs/mythbackend/mythbackend.pro	(revision 8106)
+++ programs/mythbackend/mythbackend.pro	(working copy)
@@ -12,11 +12,11 @@
 
 # Input
 HEADERS += autoexpire.h encoderlink.h filetransfer.h httpstatus.h mainserver.h
-HEADERS += playbacksock.h scheduler.h server.h housekeeper.h
+HEADERS += playbacksock.h scheduler.h server.h housekeeper.h zeroconfigserver.h
 
 SOURCES += autoexpire.cpp encoderlink.cpp filetransfer.cpp httpstatus.cpp
 SOURCES += main.cpp mainserver.cpp playbacksock.cpp scheduler.cpp server.cpp
-SOURCES += housekeeper.cpp
+SOURCES += housekeeper.cpp zeroconfigserver.cpp
 
 using_oss:DEFINES += USING_OSS
 
Index: programs/mythbackend/zeroconfigserver.cpp
===================================================================
--- programs/mythbackend/zeroconfigserver.cpp	(revision 0)
+++ programs/mythbackend/zeroconfigserver.cpp	(revision 0)
@@ -0,0 +1,98 @@
+#include <unistd.h>
+#include <qsqldatabase.h>
+#include <qsqlquery.h>
+#include <qregexp.h>
+#include <qstring.h>
+#include <qdatetime.h>
+
+using namespace std;
+
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <stdio.h>
+
+#include "libmyth/exitcodes.h"
+#include "libmyth/mythcontext.h"
+#include "libmyth/mythdbcon.h"
+#include "zeroconfigserver.h"
+
+ZeroConfigServer::ZeroConfigServer(bool runthread)
+{
+    threadrunning = runthread;
+
+    if (runthread)
+    {
+        pthread_t zeroconfigserverthread;
+        pthread_create(&zeroconfigserverthread, NULL, ZeroConfigServerThread, this);
+    }   
+}
+
+ZeroConfigServer::~ZeroConfigServer()
+{
+
+}
+
+void *ZeroConfigServer::ZeroConfigServerThread(void *param)
+{
+    ZeroConfigServer *zeroconfigserver = (ZeroConfigServer *)param;
+    zeroconfigserver->RunZeroConfigServer();
+
+    return NULL;
+}
+
+void ZeroConfigServer::RunZeroConfigServer(void)
+{
+    int sockfd,n;
+    struct sockaddr_in servaddr,cliaddr;
+    socklen_t len;
+    char mesg[1000];
+
+    sockfd=socket(AF_INET,SOCK_DGRAM,0);
+
+    bzero(&servaddr,sizeof(servaddr));
+    servaddr.sin_family = AF_INET;
+    servaddr.sin_addr.s_addr=htonl(INADDR_ANY);
+    servaddr.sin_port=htons(32000);
+    bind(sockfd,(struct sockaddr *)&servaddr,sizeof(servaddr));
+
+    while (1)
+    {
+       len = sizeof(cliaddr);
+       n = recvfrom(sockfd, mesg, 1000, 0, (struct sockaddr *)&cliaddr, &len);
+       mesg[n] = 0;
+#if DEBUG
+       printf("-------------------------------------------------------\n");
+       printf("Received the following:\n");
+       printf("[%s]\n",mesg);
+#endif
+
+       if(strcmp(mesg, "MYTHTVDISCOVER") == 0) {
+          DatabaseParams dbParams = gContext->GetDatabaseParams();
+          QString msg;
+
+          msg.sprintf("dbHostName:%s;dbUserName:%s;dbPassword:%s;dbType:%s;dbName:%s",
+                         dbParams.dbHostName.ascii(),
+                         dbParams.dbUserName.ascii(),
+                         dbParams.dbPassword.ascii(),
+                         dbParams.dbType.ascii(),
+                         dbParams.dbName.ascii());
+#if DEBUG
+          printf("Sending msg: %s\n", msg.ascii());
+#endif
+          sendto(sockfd,msg.ascii(),msg.length(),0,(struct sockaddr *)&cliaddr,sizeof(cliaddr));
+       }
+       else {
+          QString msg;
+          msg.sprintf("ERROR: Unknown query\n");
+          sendto(sockfd,msg.ascii(),msg.length(),0,(struct sockaddr *)&cliaddr,sizeof(cliaddr));
+       }
+#if DEBUG
+       printf("-------------------------------------------------------\n");
+#endif
+    }
+}
Index: programs/mythbackend/zeroconfigserver.h
===================================================================
--- programs/mythbackend/zeroconfigserver.h	(revision 0)
+++ programs/mythbackend/zeroconfigserver.h	(revision 0)
@@ -0,0 +1,18 @@
+#include <qmutex.h>
+#include <qobject.h>
+
+using namespace std;
+
+class ZeroConfigServer : public QObject
+{
+  public:
+    ZeroConfigServer(bool runthread);
+    ~ZeroConfigServer();
+
+  protected:
+    void RunZeroConfigServer(void);
+    static void *ZeroConfigServerThread(void *param);
+
+  private:
+    bool threadrunning;
+};
