Post
Topic
Board Development & Technical Discussion
Re: Java Bitcoin-Client - IPv4 to IPv6
by
grau
on 18/06/2015, 14:24:13 UTC
Here is a fragment that works for me. Not complete but you get the idea how to deal with ipv4 or 6.

It is used to connect you, assuming your node was accepting incoming connections. If so, you should indicate in the service bits.

Code:
Address a;
Writer writer;

.....

a.address = InetAddress.getLocalHost ();
a.port = myport;

writer.writeAddress (a, getVersion (), true);

class Writer {
.....

public void writeAddress (Address address, long version, boolean versionMessage)
{
if ( !versionMessage && version > 31402 )
{
writeUint32 (address.time);
}
writeUint64 (address.services);
byte[] a = address.address.getAddress ();
if ( a.length == 4 )
{
byte[] prefix = new byte[10];
writeBytes (prefix);
writeUint16 (0xffffl);
}
writeBytes (a);
bs.write ((int) (0xFF & (address.port >> 8)));
bs.write ((int) (0xFF & address.port));
}