LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] [OT] - One for the IPv6 guys

[ILUG] [OT] - One for the IPv6 guys

AJ McKee aj.mckee at gmail.com
Fri Oct 13 01:51:00 IST 2006


Hi All,

I am trying to figure out this IPv6 stuff here, especially in a script
I need to generate IPv6 addresses from a list of IPv4 addresses in a
database. But I am not too sure if I am on the right road or not. Dave
Wilson gave a good presentation on IPv6 at an AGM a few years ago, but
I cannot see to find it... maybe its gone.

Anyhow, here is a wee function in php to calculate the IPv6 address,
modified from one I found on hotscripts;

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

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?

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.

So, I am almost there I think, but alas my understanding of IPv6 is
very limited, if anyone can point out a few pitfalls of the above way
and things I need to consider that would be great.

Thanks In advance.
AJ



More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


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!
RSS Version
Powered by Dell