Bitcoin Forum
November 05, 2024, 01:19:51 PM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Java Bitcoin-Client - IPv4 to IPv6  (Read 1321 times)
husel2000 (OP)
Hero Member
*****
Offline Offline

Activity: 581
Merit: 504


View Profile
June 17, 2015, 01:01:19 PM
 #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
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3542
Merit: 6885


Just writing some code


View Profile WWW
June 17, 2015, 03:28:59 PM
 #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}

husel2000 (OP)
Hero Member
*****
Offline Offline

Activity: 581
Merit: 504


View Profile
June 18, 2015, 09: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...
grau
Hero Member
*****
Offline Offline

Activity: 836
Merit: 1030


bits of proof


View Profile WWW
June 18, 2015, 02:24:13 PM
 #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));
}
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!