[158380] in North American Network Operators' Group

home help back first fref pref prev next nref lref last post

Re: "Programmers can't get IPv6 thus that is why they do not have

daemon@ATHENA.MIT.EDU (William Herrin)
Thu Nov 29 09:55:59 2012

In-Reply-To: <CALFTrnM+a56hx3CP0qqszfNrbirQZOefS_0uHVC8VQk=+QDC2g@mail.gmail.com>
From: William Herrin <bill@herrin.us>
Date: Thu, 29 Nov 2012 09:55:19 -0500
To: Ray Soucy <rps@maine.edu>
Cc: NANOG list <nanog@nanog.org>
Errors-To: nanog-bounces+nanog.discuss=bloom-picayune.mit.edu@nanog.org

On Thu, Nov 29, 2012 at 9:01 AM, Ray Soucy <rps@maine.edu> wrote:
> You should store IPv6 as a pair of 64-bit integers.  While PHP lacks
> the function set to do this on its own, it's not very difficult to do.

Hi Ray,

I have to disagree. In your SQL database you should store addresses as
a fixed length character string containing a zero-padded hexadecimal
representation of the IPv4 or IPv6 address with A through F forced to
the consistent case of your choice. Expand :: and optionally strip the
colons entirely. If you want to store a block of addresses, store it
as two character strings: start and end of the range.

Bytes are cheap and query simplicity is important. Multi-element
indexes are messy and the code to manage an array of integers is
messier than managing a character string in most programming
languages. memcmp() that integer array for less or greater than? Not
on a little endian machine!


> Here are a set of functions I wrote a while back to do just that
> (though I admit I should spend some time to try and make it more
> elegant and I'm not sure it's completely up to date compared to my
> local copy ... I would love some eyes on it to make some
> improvements).
>
> http://soucy.org/project/inet6/

If we're plugging our code, give my public domain libeasyv6 a try. It
eases entry into dual stack programming for anyone used to doing
gethostbyname followed by a blocking connect(). Just do a
connectbyname() with the hostname or textual IP address, the port, a
timeout and null options. The library takes care of finding a working
IPv4 or IPv6 address for the host and connecting to it in a timely
manner.

http://bill.herrin.us/freebies/

Currently Linux only but if you're willing to lose timeout control on
the DNS lookup you can replace getaddrinfo_a() with standard
getaddrinfo() and the code should run anywhere.

Regards,
Bill Herrin


-- 
William D. Herrin ................ herrin@dirtside.com  bill@herrin.us
3005 Crane Dr. ...................... Web: <http://bill.herrin.us/>
Falls Church, VA 22042-3004


home help back first fref pref prev next nref lref last post