On Fri, Oct 13, 2006 at 01:51:00AM +0100, AJ McKee wrote:
> function ipv4Toipv6 ($ipv4Address) {
> if(!$ipv4Address) {
> return false;
> }
> list($octet1, $octet2, $octet3, $octet4) = split ("\.",
> $ipv4Address, 4);
> $decimal = ((((($octet1 * 256 + $octet2) *256 ) + $octet3) * 256 ) +
> $octet4);
> $hex = dechex($decimal);
> $splitHex = str_split($hex, 4);
> $ipv6 = "2002:$splitHex[0]:$splitHex[1]:0:0:0:0:0";
> return $ipv6;
> }
> echo ipv4Toipv6("127.0.0.1");
>> This produces;
>> 2002:7f00:0001:0:0:0:0:0
This is the /48 prefix that you get when you use 6to4. 6to4 is a
transition mechanism that lets you route an IPv6 /48 to any public
IPv4 address in the world. There's a series of routers which are
configured to decode the prefix and forward the traffic (over protocol
41) to the correct IPv4 node. It is not a generic IPv4-to-IPv6
translation mechanism.
If you want create some unique IPv6 addresses based on some unique
IPv4 addresses, the easiest way is to take your prefix and just append
the IPv4 address;
2001:770:18:10::193.1.219.90
for example, which is a perfectly legitimate IPv4 address.
> Which is wrong, firstly the 2002 should be FFFF, and secondly the 0001
> I think can have the 0 droped from it. Is this correct? I can work
> around the FFFF or the reserved addresses issues, however if I left
> the preceding 0's in would that invaildate any address I enter?
No, you're getting very confused there. Addresses that start with FF are
in the IPv6 multicast and reserved ranges. Typically you see them being
used as link-local addresses and so on.
> If I run my home IP address through this (212.17.57.169) I get
> 2002:d411:39a9:0:0:0:0:0 which appears to be correct.
Yes, if you wanted to use 6to4 at home, that's the IPv6 range you'd use.
--
Colm MacCárthaigh Public Key: colm+pgp at stdlib.net
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!