Author

Topic: Java Bitcoin-Client - IPv4 to IPv6 (Read 1298 times)

hero member
Activity: 836
Merit: 1021
bits of proof
June 18, 2015, 10:24:13 AM
#4
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));
}
hero member
Activity: 581
Merit: 504
June 18, 2015, 05:58:37 AM
#3
Thanks!

The other Question: What is it used for? I only send 0x00 and everything seems to work fine.

BTW: I am missing the THX-Button to avoid these posts...
staff
Activity: 3374
Merit: 6530
Just writing some code
June 17, 2015, 11:28:59 AM
#2
An IPv4 address mapped to IPv6 will look like this
Code:
::ffff:127.0.0.1
This is what one looks like in the Bitcoin Core code in hex:
Code:
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x82,0xd3,0xb1,0xbe}
hero member
Activity: 581
Merit: 504
June 17, 2015, 09:01:19 AM
#1
Hello,

first, i am sorry for my english. Its not very good.

Now to my problem:
I am trying to create a minimal Bitcoin-Client to Connect to other (Test-)Nodes in Java.
At the moment, i can connect to other Nodes and send Messages, defined in https://bitcoin.org/en/developer-reference#p2p-network. My Problem is in the version-Message, specially the addr_recv IP address (16 Bytes).
Can someone give me a hint, how to generate a IPv6-Adress from IPv4 (127.0.0.1)?

Why is that addr_recv IP address needed? If i connect to one Node, an send 16 Bytes of 0x00 then there is no error and whe can confirm the Connection with the verack-Message.

Thanks for your help and explanation.

Greets
Husel
Jump to: