network vdr-xine-0.7.6, use -i to select the ip to bind to

Message ID 87veyxa4mq.87u0eha4mq@87slu1a4mq.message.id
State New
Headers

Commit Message

syrius.ml@no-log.org Nov. 12, 2005, 10:38 p.m. UTC
  Hi,

I did it for me, maybe it could be of some use for someone else.
With the genuine vdr-xine plugin -i could be used to choose the
instance number and one can have several vdr+vdr-xine running on the
same box.
Here with the networked vdr-xine, it could be used to select the ip to
bind to.

What are the differences ?
If -i is not used, the networked vdr-xine bind to all local interfaces
(as before)
If you want to run 2 vdr+vdr-xine on the same machine, it has to have
2 ip addresses, the first vdr has to be ran with -P 'xine -i
IP1.IP1.IP1.IP' and the second one with -P 'xine -i IP2.IP2.IP2.IP'

it's a quick hack, I hope i've been clear enough and that it may be of
some use.

--
  

Patch

diff -Nru xine-0.7.6+network~old/xine.c xine-0.7.6+network/xine.c
--- xine-0.7.6+network~old/xine.c	2005-09-25 18:19:35.000000000 +0200
+++ xine-0.7.6+network/xine.c	2005-11-12 23:37:19.000000000 +0100
@@ -33,7 +33,7 @@ 
   
 public:
   PluginXine::cXineLib *m_xineLib;
-  int m_instanceNo;
+  in_addr_t m_bindIp;
   
   cPluginXine(void);
   virtual ~cPluginXine();
@@ -56,7 +56,7 @@ 
   , m_remote(0)
   , m_remoteOn(false)
   , m_xineLib(0)
-  , m_instanceNo(-1)
+  , m_bindIp(0)
 {
   // Initialize any member variables here.
   // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
@@ -73,7 +73,7 @@ 
   //Return a string that describes all known command line options.
   //"  -         --             x                                                   \n"
   return
-    "  -i N                     instance number to append to FIFO directory\n"
+    "  -i ip                    ip address to bind to\n"
     "  -q                       turn off debug messages on console\n"
     "  -r                       turn on remote (pressing keys in xine controls VDR)\n"
     "  -s                       switch to curses skin, while xine is disconnected\n"
@@ -91,11 +91,9 @@ 
     {
     case 'i':
       {
-        const int no = ::atoi(::optarg);
-        if (no < 0)
+        m_bindIp = inet_addr(::optarg);
+        if (m_bindIp == INADDR_NONE)
           return false;
-        
-        m_instanceNo = no;
       }
       break;
       
@@ -181,9 +179,9 @@ 
 
 namespace PluginXine
 {
-  int GetInstanceNo(cPlugin *const plugin)
+  int GetBindIp(cPlugin *const plugin)
   {
-    return ((cPluginXine *)plugin)->m_instanceNo;
+    return ((cPluginXine *)plugin)->m_bindIp;
   }
 
   cXineLib *&GetXineLib(cPlugin *const plugin)
diff -Nru xine-0.7.6+network~old/xineLib.c xine-0.7.6+network/xineLib.c
--- xine-0.7.6+network~old/xineLib.c	2005-09-25 18:19:35.000000000 +0200
+++ xine-0.7.6+network/xineLib.c	2005-11-12 23:36:02.000000000 +0100
@@ -1847,7 +1847,7 @@ 
   
 #endif
 
-  extern int GetInstanceNo(cPlugin *const plugin);
+  extern int GetBindIp(cPlugin *const plugin);
   extern cXineLib *&GetXineLib(cPlugin *const plugin);
   
   cXineLib::cXineLib(cPlugin *const plugin, const cXineSettings &settings, cMutex &osdMutex, cXineRemote *const remote)
@@ -1877,14 +1877,9 @@ 
   {
     m_fifoDir = FIFO_DIR;
 
-    if (GetInstanceNo(plugin) >= 0)
-    {
-      char s[ 20 ];
-      ::sprintf(s, "%d", GetInstanceNo(plugin));
-      
-      m_fifoDir += s;
-    }
-
+    m_bindIp = GetBindIp(plugin);
+    m_fifoDir += itoa(m_bindIp);
+		
     m_fifoNameControl    = m_fifoDir + "/stream.control";
     m_fifoNameResult     = m_fifoDir + "/stream.result";
     m_fifoNameRemote     = m_fifoDir + "/stream.event";
@@ -1956,7 +1951,7 @@ 
 		return -1;
 	}
 
-	sain.sin_addr.s_addr = 0;
+	sain.sin_addr.s_addr = m_bindIp;
 	sain.sin_port = htons(port);
 
 	::setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,&onoff, sizeof(int) );
diff -Nru xine-0.7.6+network~old/xineLib.h xine-0.7.6+network/xineLib.h
--- xine-0.7.6+network~old/xineLib.h	2005-09-25 18:19:35.000000000 +0200
+++ xine-0.7.6+network/xineLib.h	2005-11-12 23:35:25.000000000 +0100
@@ -88,6 +88,7 @@ 
     string m_fifoNameStream;
     string m_fifoNameExtControl;
     string m_fifoNameExtResult;
+    in_addr_t m_bindIp;
 
   private:
     cPlugin *const m_plugin;