2

I need to do a manual conversion of a string representation of IPv6 to a byte array. I'm on an embedded device and don't have access to external libraries.

For example:

String addr_str = "bbbb::1"

with manual conversion would be:

byte[] addr = new byte[]{(byte) 187,(byte) 187,0,0 //187 == bb
                                ,0,0,0,0
                                ,0,0,0,0
                                ,0,0,0,1};

Ideally, I would like to create a function, like 'convertToIPv6ByteArray', that would enable:

addr = convertToIPv6ByteArray(addr_str);

I'm having difficulties implementing this function efficiently though. Any help?

2

1 Answer 1

0

Look at this: Java IPv6 Address String to Bytes
And here is the implementation http://developer.classpath.org/doc/java/net/InetAddress-source.html
Options to do:
Easiest way would be just copy the source code of the this class to your project if you can if you can not add the libraries.
Or you can look into the implementation and reimplement it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.