Bitcoin Forum
May 13, 2024, 09:04:03 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Java Bitcoin-Client - IPv4 to IPv6  (Read 1298 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
1715634243
Hero Member
*
Offline Offline

Posts: 1715634243

View Profile Personal Message (Offline)

Ignore
1715634243
Reply with quote  #2

1715634243
Report to moderator
Unlike traditional banking where clients have only a few account numbers, with Bitcoin people can create an unlimited number of accounts (addresses). This can be used to easily track payments, and it improves anonymity.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715634243
Hero Member
*
Offline Offline

Posts: 1715634243

View Profile Personal Message (Offline)

Ignore
1715634243
Reply with quote  #2

1715634243
Report to moderator
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6635


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: 1021


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!