0

I'm trying to work on an app abandoned in Sourceforge. It is called kmttg (look it up). It is a java app that allows Tivo owners to edit and change OnePass entries on their Tivo devices from a computer. The RPC certificate is going to expire next month and I'm trying to see if I can correct that. I got the code from SourceForge and I'm working my way through getting it to work on my computer(s).

I have Eclipse for Java installed on my Windows 11 laptop and on my MacBook Pro 14" laptop running Monterey.

The problem I'm running into is when the app tries to get the local pc's IP address. It works fine on my PC running Windows 11, but fails on my Macbook Pro M1 Pro running Monterey.

The code below is where the problem occurs:

    package com.tivo.kmttg.main;

    import java.net.DatagramSocket;
    import java.net.InetAddress;
    //import java.util.Date;
    import java.util.Enumeration;
    import java.util.Hashtable;
    import java.util.Stack;

    import javax.jmdns.JmDNS;
    import javax.jmdns.ServiceInfo;

    import com.tivo.kmttg.util.log;

    public class mdns {
       private JmDNS jmdns = null;
       private Hashtable<String,ServiceInfo> SERVICE = new 
    Hashtable<String,ServiceInfo>();
       //private int timeout = 5;          // ~mins after which mdns 
    listening disabled
       //private long start_time;
   
       public mdns() {
          try {
             DatagramSocket socket = new DatagramSocket();
             socket.connect(InetAddress.getByName("8.8.8.8"), 10002);
             InetAddress IP = socket.getLocalAddress();  """ THIS WORKS ON WINDOWS 11 BUT NOT ON THE MACBOOK PRO MACHINE". 
             if (! IP.isReachable(3000))
                IP = InetAddress.getLocalHost();
             if (! IP.isReachable(3000))
                log.error("mdns error: Can't determine valid IP for host running kmttg");
             //log.print("IP=" + 
    socket.getLocalAddress().getHostAddress());
             jmdns = JmDNS.create(IP);
             socket.close();
             //start_time = new Date().getTime();
          } catch (Exception e) {
             log.error("mdns error: " + e.getMessage());
          } 
       }

The versions of the Java JRE in both machines are 10.0.2. Compliance level is 1.8. The old code doesn't work otherwise.

Eclipse is 2021-09 (4.2.1.0)

All supporting Jars are from the SourceForge project and are the same on both machines.

BELOW: are screen grabs of when it works in Eclipse on Windows 11 and returns an IP address and then again when it doesn't work on the Macbook and returns 0.0.0.0 IP

Any thoughts would be greatly appreciated.

Oh BTW I coded Java professionally from 2000 - 2014 and I'm just now dipping back into it after doing some Swift coding.

When it doesn't work

When it doesn't work

1 Answer 1

0

Try iterating through the network interfaces:

import java.net.Inet4Address;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
import java.util.Iterator;

public class PrintNonloopbackIPv4Addresses {
    public static void main(String[] args) throws Exception {
        Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
        while (networkInterfaces.hasMoreElements()) {
            NetworkInterface face = networkInterfaces.nextElement();
            for (Iterator<InterfaceAddress> iterator = face.getInterfaceAddresses().iterator(); iterator.hasNext();) {
                InterfaceAddress interfaceAddress = iterator.next();
                if (interfaceAddress.getAddress().isLoopbackAddress())
                    continue;
                if (interfaceAddress.getAddress() instanceof Inet4Address)
                    System.out.println(interfaceAddress.getAddress().getHostAddress());
            }
        }
    }
}
2
  • Thank you for this code, I've been running it and learned a lot about the MacBook interfaces. But I'm still puzzled why the code above does return an IP address on Windows 11 and not on MacOS Monterey. I should mention, that the kmttg.jar file from the product does run on my Mac with a clean install. I have a Java decompiler and after decompiling the jar I see that the code in it is the same as the source code I downloaded. I really appreciate you taking the time to do this though as it has put me on the track of the problem.
    – rpetruzz
    Commented Nov 21, 2021 at 16:09
  • I believe I've tracked down the source of the difficulty using the SecurityManager check connect. I"m getting the exception Check Connect Error access denied ("java.net.SocketPermission" "8.8.8.8:10002" "connect,resolve")
    – rpetruzz
    Commented Nov 21, 2021 at 16:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.