bigdaddydad / android-xbmcremote

Automatically exported from code.google.com/p/android-xbmcremote
0 stars 0 forks source link

WOL needs broadcast mode #424

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
WOL needs to have broadcast mode aswell (to support units behind bridges and so 
on)

What version of XBMC Remote are you using?
v.8

Which Android device are you using (and which ROM, if custom)?
x10

Which XBMC revision are you running and on which platform?
Dharma beta 3

Please provide any additional information below.

Original issue reported on code.google.com by ravedog1...@gmail.com on 24 Oct 2010 at 8:54

GoogleCodeExporter commented 8 years ago
A workaround for now... I have my mediaPC behind a WiFi-bridge. And if you 
enable your bridge to clone your units mac addresses it will work with WoL.

Original comment by bolin.andreas@gmail.com on 5 Nov 2010 at 1:52

GoogleCodeExporter commented 8 years ago

Original comment by phree...@gmail.com on 28 Nov 2010 at 4:35

GoogleCodeExporter commented 8 years ago

Original comment by phree...@gmail.com on 15 Aug 2011 at 1:25

GoogleCodeExporter commented 8 years ago
Same issue here, as a new and happy xbmc-remote user, only function not working 
for me was the power on button :-(
I implemented this fastfix, and recompiled the source, everything is OK now. 
Please consider broadcast as a feature in upcoming releases.

my modified version of WakoOnLan.java:
----
/*
 *      Copyright (C) 2005-2009 Team XBMC
 *      http://xbmc.org
 *
 *  This Program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  This Program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with XBMC Remote; see the file license.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *  http://www.gnu.org/copyleft/gpl.html
 *
 */

package org.xbmc.android.util;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.StringTokenizer;

import android.widget.Toast;

/**
 * The WoL implementation
 * 
 * @author Team XBMC
 */
public class WakeOnLan {
    public Boolean sendMagicPacket(String macStr, String ipStr, int PORT) {              
        try {
            byte[] macBytes = getMacBytes(macStr);
            byte[] bytes = new byte[6 + 16 * macBytes.length];
            for (int i = 0; i < 6; i++) {
                bytes[i] = (byte) 0xff;
            }
            for (int i = 6; i < bytes.length; i += macBytes.length) {
                System.arraycopy(macBytes, 0, bytes, i, macBytes.length);
            }

            InetAddress address = InetAddress.getByName(getBroadcastIP());
            DatagramPacket packet = new DatagramPacket(bytes, bytes.length, address, PORT);
            DatagramSocket socket = new DatagramSocket();
            socket.send(packet);
            socket.close();
            return true;
        }
        catch (Exception e) {
            return false;
        }
    }

    public Boolean sendMagicPacket(String macStr, int PORT) {
        return sendMagicPacket(macStr, "255.255.255.255", PORT);
    }

    public Boolean sendMagicPacket(String macStr) {
        return sendMagicPacket(macStr, "255.255.255.255", 9);
    }

    public String getLocalIpAddress() { 
        try { 
            for (Enumeration<NetworkInterface> en = NetworkInterface 
                    .getNetworkInterfaces(); en.hasMoreElements();) { 
                NetworkInterface intf = en.nextElement(); 
                for (Enumeration<InetAddress> enumIpAddr = intf 
                        .getInetAddresses(); enumIpAddr.hasMoreElements();) { 
                    InetAddress inetAddress = enumIpAddr.nextElement(); 
                    if (!inetAddress.isLoopbackAddress()) { 
                        return inetAddress.getHostAddress().toString(); 
                    } 
                } 
            } 
        } catch (SocketException ex) {} 
        return null; 
    } 

    public String getBroadcastIP(){ 
        String myIP = getLocalIpAddress(); 
        StringTokenizer tokens = new StringTokenizer(myIP, "."); 
        int count = 0; 
        String broadcast = ""; 
        while (count < 3) { 
            broadcast += tokens.nextToken() + "."; 
            count++; 
        } 
        return broadcast+"255"; 
    } 
  private static byte[] getMacBytes(String macStr) throws IllegalArgumentException {
        byte[] bytes = new byte[6];
        String[] hex = macStr.split("(\\:|\\-)");
        if (hex.length != 6) {
            throw new IllegalArgumentException("Invalid MAC address.");
        }
        try {
            for (int i = 0; i < 6; i++) {
                bytes[i] = (byte) Integer.parseInt(hex[i], 16);
            }
        }
        catch (NumberFormatException e) {
            throw new IllegalArgumentException("Invalid hex digit in MAC address.");
        }
        return bytes;
    }
 }

Original comment by r.o.niel...@gmail.com on 13 Mar 2012 at 7:30