OpenViX / HRTunerProxy

Setup Enigma2 to act as HR-Tuner Proxy
GNU General Public License v2.0
76 stars 26 forks source link

IP address does not get determined #52

Closed matmielke closed 2 years ago

matmielke commented 2 years ago

Hello,

I'm very happy for this plugin. So far, I was able to set up the plugin in a way PLEX sees the channels from the bouquet. Unfortunately, the plugin does not recognize the address of my VU+ Uno4K SE, it always uses "0.0.0.0" as IP which is obviously wrong as I can connect to the receiver. That results in none playable streams as the resulting address for playback is wrong. Here is the ifconfig output:

eth0      Link encap:Ethernet  HWaddr 00:1d:ec:11:8c:a6
          inet addr:10.0.10.50  Bcast:10.0.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:130716 errors:0 dropped:19 overruns:0 frame:0
          TX packets:260423 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:17395389 (16.5 MiB)  TX bytes:333512229 (318.0 MiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:50 errors:0 dropped:0 overruns:0 frame:0
          TX packets:50 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:3397 (3.3 KiB)  TX bytes:3397 (3.3 KiB)

From the code and some testing (without good Python knowledge), I see problems in this part of the code:

def getIfConfig(ifname):
    ifreq = {'ifname': ifname}
    infos = {}
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    # offsets defined in /usr/include/linux/sockios.h on linux 2.6
    infos['addr'] = 0x8915 # SIOCGIFADDR
    infos['brdaddr'] = 0x8919 # SIOCGIFBRDADDR
    infos['hwaddr'] = 0x8927 # SIOCSIFHWADDR
    infos['netmask'] = 0x891b # SIOCGIFNETMASK
    try:
        for k, v in infos.items():
            ifreq[k] = _ifinfo(sock, v, ifname)
                        ------ <<< print statement here >>> ------
    except:
        pass
    sock.close()
    return ifreq

When I insert a print statement at the place marked, I can see the loop does not get executed at all.

Can you please give advice?

Thanks in advance and best regards, Matthias

Huevos commented 2 years ago

What image? When was it built?

matmielke commented 2 years ago

That's what the info of the receiver says: OE-System:OpenVuplus 2.1 Firmware-Version:VTi-Team Image 15.0.0 (2021-02-08-vti-master (9849f8edd)) Kernel / Treiber:4.1.20 / 20210407

Is that already fine for you or do you need further information from command line? If so, please give me a hint which command I should use.

Best regards, Matthias

Huevos commented 2 years ago

In OE-Alliance images, e.g. OpenATV, and OpenViX, this problem does not exist.

Are you certain you are using the latest version?

1) Print infos.items() before the loop. Maybe it is empty. 2) Most likely crashing here: ifreq[k] = _ifinfo(sock, v, ifname) so you need to add some debug to read the exception.

nrpetonr commented 2 years ago

actually exactly same problem with openATV 6.4 on octagon SF8008.

System OE:OE-Alliance 4.4 Firmware:OpenATV 6.4.20211228 (2021-12-25) Kernel/ Drivers:4.4.35 / 20210402

eth0      Link encap:Ethernet  HWaddr D0:27:24:00:5C:E1
          inet addr:192.168.9.226  Bcast:0.0.0.0  Mask:255.255.255.0
          inet6 addr: fe80::d227:24ff:fe00:5ce1/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3100370 errors:0 dropped:203 overruns:0 frame:0
          TX packets:1642619 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3255521134 (3.0 GiB)  TX bytes:724787345 (691.2 MiB)
          Interrupt:33

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:115537 errors:0 dropped:0 overruns:0 frame:0
          TX packets:115537 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:400836479 (382.2 MiB)  TX bytes:400836479 (382.2 MiB)
matmielke commented 2 years ago

With the following code, I get a result that seems to show a non-empty infos.items() (Please note: I copied the relevant functions to a separate file to be able to test. It's plain copy&paste, no changes except the print statement.)

def getIfConfig(ifname):
    ifreq = {'ifname': ifname}
    infos = {}
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    # offsets defined in /usr/include/linux/sockios.h on linux 2.6
    infos['addr'] = 0x8915 # SIOCGIFADDR
    infos['brdaddr'] = 0x8919 # SIOCGIFBRDADDR
    infos['hwaddr'] = 0x8927 # SIOCSIFHWADDR
    infos['netmask'] = 0x891b # SIOCGIFNETMASK
    print(infos.items())
    try:
        for k, v in infos.items():
            ifreq[k] = _ifinfo(sock, v, ifname)
    except:
        pass
    print(sock)
    sock.close()
    return ifreq

Result on command line:

root@VU+:~# python test.py
[('hwaddr', 35111), ('netmask', 35099), ('addr', 35093), ('brdaddr', 35097)]
<socket._socketobject object at 0xb6a612d0>
{'ifname': 'eth0'}

The version is the most actual one, I downloaded two days ago and did not have the plugin before.

Best regards, Matthias

Huevos commented 2 years ago

So it is failing here:

    try:
        for k, v in infos.items():
            ifreq[k] = _ifinfo(sock, v, ifname)
    except:
        pass

You need debug. For example:

    try:
        for k, v in infos.items():
            ifreq[k] = _ifinfo(sock, v, ifname)
    except:
        import traceback
        traceback.print_exc()
matmielke commented 2 years ago

Here is the output when calling the script:

root@VU+:~# python test.py
Traceback (most recent call last):
  File "test.py", line 41, in getIfConfig
    ifreq[k] = _ifinfo(sock, v, ifname)
  File "test.py", line 24, in _ifinfo
    return ''.join(['%02x:' % char if six.PY3 else ord(char) for char in info[18:24]])[:-1].upper()
TypeError: sequence item 0: expected string, int found
<socket._socketobject object at 0xb69ad298>
{'ifname': 'eth0'}

As the trace refers to lines, here is the full script I used:

from __future__ import print_function
from __future__ import absolute_import

import gettext
import socket
import fcntl
import struct
import logging
from os import path, remove, environ as os_environ

try:
    from enigma import eMediaDatabase
    isDreamOS = True
except:
    isDreamOS = False

import six

def _ifinfo(sock, addr, ifname):
    iface = struct.pack('256s', six.ensure_binary(ifname[:15]))
    info = fcntl.ioctl(sock.fileno(), addr, iface)
    if addr == 0x8927:
        return ''.join(['%02x:' % char if six.PY3 else ord(char) for char in info[18:24]])[:-1].upper()
    else:
        return socket.inet_ntoa(info[20:24])

def getIfConfig(ifname):
    ifreq = {'ifname': ifname}
    infos = {}
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    # offsets defined in /usr/include/linux/sockios.h on linux 2.6
    infos['addr'] = 0x8915 # SIOCGIFADDR
    infos['brdaddr'] = 0x8919 # SIOCGIFBRDADDR
    infos['hwaddr'] = 0x8927 # SIOCSIFHWADDR
    infos['netmask'] = 0x891b # SIOCGIFNETMASK
    #print(infos.items())
    try:
        for k, v in infos.items():
            ifreq[k] = _ifinfo(sock, v, ifname)
    except:
        import traceback
        traceback.print_exc()
    print(sock)
    sock.close()
    return ifreq

def getIfInfo():
    for port in ('eth0', 'eth1', 'wlan0', 'wlan1', 'wlan2', 'wlan3', 'ra0'):
        ifinfo = getIfConfig(port)
        if 'addr' in ifinfo:
            return ifinfo
    return None

def getIP():
    IP = '0.0.0.0'
    ifinfo = getIfInfo()
    if ifinfo:
        IP = ifinfo['addr']
    return '%s' % IP

#following line added to test by MM
print(getIfConfig('eth0'))
Huevos commented 2 years ago

Is this a Py3 image?

matmielke commented 2 years ago

Doesn't look like (assuming I used the correct command):

root@VU+:~# python --version
Python 2.7.9
Huevos commented 2 years ago

Get more debug:

def _ifinfo(sock, addr, ifname):
    iface = struct.pack('256s', six.ensure_binary(ifname[:15]))
    print("iface", iface)
    info = fcntl.ioctl(sock.fileno(), addr, iface)
    print("info", info)
    if addr == 0x8927:
        print("info[18:24]", info[18:24])
        print("info[18:24] processed", [char for char in info[18:24]])
        return ''.join(['%02x:' % char if six.PY3 else ord(char) for char in info[18:24]])[:-1].upper()
    else:
        return socket.inet_ntoa(info[20:24])
matmielke commented 2 years ago
root@VU+:~# python test.py
iface eth0
info eth0쌦
info[18:24] 쌦
info[18:24] processed ['\x00', '\x1d', '\xec', '\x11', '\x8c', '\xa6']
<socket._socketobject object at 0xb69fe298>
iface eth1
<socket._socketobject object at 0xb69fe298>
iface wlan0
<socket._socketobject object at 0xb69fe298>
iface wlan1
<socket._socketobject object at 0xb69fe298>
iface wlan2
<socket._socketobject object at 0xb69fe298>
iface wlan3
<socket._socketobject object at 0xb69fe298>
iface ra0
<socket._socketobject object at 0xb69fe298>
0.0.0.0

iface eth0
info eth0쌦
info[18:24] 쌦
info[18:24] processed ['\x00', '\x1d', '\xec', '\x11', '\x8c', '\xa6']
<socket._socketobject object at 0xb69fe298>
{'ifname': 'eth0'}
root@VU+:~#
Huevos commented 2 years ago

Try this: https://github.com/OpenViX/HRTunerProxy/commit/64389b9a2e33e038700fe9bbfdb8958dc2ffd878

matmielke commented 2 years ago

Great, that one seems to do the job!

Thanks a lot and best regards, Matthias

Huevos commented 2 years ago

Cool.