Extracting IPv4 addresses from IPv6 in MySQL

Here’s a stored procedure that will let you find an IPv4 address embedded inside an IPv6 address, as a stored procedure in MySQL:


DELIMITER $$
CREATE DEFINER=`root`@`localhost` FUNCTION `IPv4_from_IPv6`(IPv6 varchar(255)) RETURNS varchar(255) CHARSET utf8
BEGIN
# Split into blocks
DECLARE Block1, Block2, Block3, Block4, Block5, Block6, Block7, Block8 varchar(4);
DECLARE IPv4 varchar(255);
SELECT SUBSTRING_INDEX(IPv6, ":", 1)                           INTO Block1;
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(IPv6, ":", 2), ":", -1) INTO Block2;
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(IPv6, ":", 3), ":", -1) INTO Block3;
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(IPv6, ":", 4), ":", -1) INTO Block4;
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(IPv6, ":", 5), ":", -1) INTO Block5;
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(IPv6, ":", 6), ":", -1) INTO Block6;
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(IPv6, ":", 7), ":", -1) INTO Block7;
SELECT SUBSTRING_INDEX(IPv6, ":", -1) INTO Block8;
SELECT INET_NTOA(CONV(concat(Block7, Block8), 16, 10)) INTO IPv4;
IF (Block1 <> 0)
THEN
RETURN NULL;
ELSEIF (Block2 <> 0)
THEN
RETURN NULL;
ELSEIF (Block3 <> 0)
THEN
RETURN NULL;
ELSEIF (Block4 <> 0)
THEN
RETURN NULL;
ELSEIF (Block5 <> 0)
THEN
RETURN NULL;
ELSEIF (Block6 <> "FFFF")
THEN
RETURN NULL;
END IF;
RETURN IPv4;
END $$

Very handy.

Subversion upgrades

Another nugget that took me a few minutes to go through, so a summary here: when upgrading subversion environments, you need to consider:

  • The version of the client tools (eg, svn from the command line, Tortoise, Subclipse, etc)
  • The version of the binaries in the web server (libapache-svn)
  • The version of the repository on disk

The repository on the server on disk generally does not auto-upgrade. Indeed, I just found that my personal SVN repo was still using format version 1! Version 1.4 uses format 2, and version 1.5 uses format 3. Thanks to this link its easy to see the format of a repo – cat $PATH/db/format.

Check the release notes to see the features that don’t work when the repo is not upgraded, and what version clients do and don’t work.

Now with IPv6 goodness

So, with about 10 mins of reading and 1 min of work, this site is now available with both IPv4 and IPv6. Thanks Bytemark for making it so easy, and of course to all the software stack that just works. If you want to test and ensure you’re using just IPv6, you can browse to ipv6.james.rcpt.to, which I have only published a AAAA address for.

Next up; update my Log3NF Apache module to understand IPv6 addresses as well as the IPv4 if currently does.

HP Dreamscreen 130 – first impressions

It’s a very clean, crisp screen. It’s a neat package, but boy — is it heavy. Even the stylus-like “stick” that screws into the rear of the frame to make it stand up feels like a fishing weight rather than a mere stand.

The default installed firmware was fine – it powered up, and within 30 seconds I was on the wireless network. Like most geeks, first thing was to tell the unit to go and perform a firmware check, which id dutifully did; and thus is downloaded and applied its first update smoothly. Well done, HP.

There is a “home screen” type of interface, with which you can launch any of the apps the literature talks of, or via the configuration of the device, you can tell it to launch a slide show when its idle. Sadly, the “slide show” it does when “idle” (which will be most of the time) is only from local storage. That’s not what I want; when idle, I want it to go and load some online content – photos from Facebook, Snapfish (or Flikr). I basically want it to be a hands-free automatic updating remote display for my online photo album. HP: please address this!!

The Facebook app is very good if you know what pictures you want to show, but for my taste seems to require far too much interaction. Your only choise here is to select which friend’s albums you wan tot see, and then browse their albums. I’d just like to see (or chose) which friends albums are going to be displayed (probably with their name somewhere on the screen, maybe with the caption as well).  Like a “recent photos from FriendA, FriendB, FriendC”, and have the “standby mode” of the DreamScreen just go find recent items from this selection.

Here’s something HP got correct: you can tell it to turn on at one time, and off at another. Great for night time in the bedroom: photo frame goes of at 11pm, and back on at 7am.

Next up – when idle, it would nice nice if we could get the “clock” app to display the time(s)  (with an alpha channel??). Or, for that matter, the weather for the configured location.

Minor bug bear for me; entering a password doesn’t obscure the entered password as you type it from the on-screen keyboard.

There’s a calendar app in here; it shows… a calendar. Wouldn’t this be so much better if you could give it a URL to an ICS or ICAL file and get it to display your calendar appointments? (Don’t forget to set a refresh period, and have the calendar be able to always show the current day/week/month).

More interesting tid-bits as I keep playing with this.