While trying to get freenet working on Kaffe, I discovered a side
issue... we use the attached code to detect the local internet IP
address. Basically, we open a datagram socket to the A-root nameserver
and call getLocalAddress(). This returns 0.0.0.0 on Kaffe CVS; any 
chance of fixing? Anything I can do to help?
-- 
Matthew Toseland
[EMAIL PROTECTED]/[EMAIL PROTECTED]
Full time freenet hacker.
http://freenetproject.org/
Freenet Distribution Node (temporary) at http://0.0.0.0:8889/HPhwJMG1iEE/
ICTHUS.
package freenet.node;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.net.DatagramSocket;
import java.net.SocketException;
import freenet.support.Checkpointed;
import freenet.Core;
import freenet.Address;
import freenet.Transport;
import freenet.BadAddressException;

/**
 * A class to autodetect our IP address(es)
 */

class IPAddressDetector implements Checkpointed {

    public IPAddressDetector() {
    }
    

    /**
     * @return our name
     */
    public String getCheckpointName() {
	return "Autodetection of IP addresses";
    }

    /** 
     * @return next scheduling point
     */
    public long nextCheckpoint() {
	return System.currentTimeMillis() + 10000; // We are pretty cheap
    }

    InetAddress lastAddress = null;
    long lastDetectedTime = -1;

    public InetAddress getAddress() {
	return getAddress(0);
    }
    
    /**
     * Get the IP address
     */
    public InetAddress getAddress(long recheckTime) {
	if(lastAddress == null || 
	   System.currentTimeMillis() > 
	   (lastDetectedTime + recheckTime))
	    checkpoint();
	return lastAddress;
    }
    
    /**
     * Execute a checkpoint - detect our internet IP address and log it
     */
    public void checkpoint() {
	DatagramSocket ds;
	try {
	    ds = new DatagramSocket();
	} catch (SocketException e) {
	    Core.logger.log(this, "SocketException", e,
			    Core.logger.ERROR);
	    return;
	}
	// This does not transfer any data
	// The ip is a.root-servers.net, 42 is DNS
	try {
	    ds.connect(InetAddress.getByName("198.41.0.4"), 42);
	} catch (UnknownHostException e) {
	    Core.logger.log(this, "UnknownHostException", e,
			    Core.logger.ERROR);
	    return;
	}
	InetAddress myAddress = ds.getLocalAddress();
	if(lastAddress != null && (!myAddress.equals(lastAddress))) {
	    Core.logger.log(this, "Address changed!", Core.logger.MINOR);
	    lastAddress = myAddress;
	    lastDetectedTime = System.currentTimeMillis();
	    ds.close();
	    Main.newInetAddress(myAddress);
	} else {
	    ds.close();
	    lastAddress = myAddress;
	    lastDetectedTime = System.currentTimeMillis();
	}
    }
}


Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to