Fwd: data type for ip addresses



Reply, instead of Reply-All, didn't go to list...


---------- Forwarded message ----------
From: Jonathan Leffler <jleffler.iiug@xxxxxxxxx>
Date: Fri, Jun 19, 2009 at 11:29
Subject: Re: data type for ip addresses
To: steven_nospam at Yahoo! Canada <steven_nospam@xxxxxxxx>




On Fri, Jun 19, 2009 at 08:54, steven_nospam at Yahoo! Canada
<steven_nospam@xxxxxxxx> wrote:

On Jun 19, 3:59 am, Holger de Wall <hol...@xxxxxxxxxxxxx> wrote:
how can I create a data type that can store ip addresses (ipv4 and ipv6)?
We use IDS 10.00 UC6 and 11.50 UC3.


I would probably store it in a field CHAR(15) and just have
"xxx.xxx.xxx.xxx" stored inside.

That's OK  for IPv4; not so good for IPv6.
Or, rather, the length is not long enough for IPv6.
IPv6 addresses are 128-bits - that's up to 32 hex digits, with
separators every 4 hex digits, and some compression available for
strings of zeroes.
XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX
That needs VARCHAR(39), I think - and probably VARCHAR rather than
CHAR, though it isn't the biggest waste of space in this world.


However, you could also decide to store it as four fields of SMALLINT.
If I am not mistaken, using four SMALLINT fields would store each
octet as a number and only use 4 bytes, whereas the CHAR field would
use 15 bytes and you would have to do conversions from the CHAR to an
integer for each octet to do any validation of values. (ie. must be in
range 1-255).

Definite IPv4-centrism...


I guess the question is how many rows are we talking about (to see a
significant savings in row size) and will you want to do anything to
the field in that data?

--
Jonathan Leffler                   #include <disclaimer.h>
Email: jleffler@xxxxxxxxxxxxx, jleffler@xxxxxxxxxx
Guardian of DBD::Informix v2008.0513 -- http://dbi.perl.org/
"Blessed are we who can laugh at ourselves, for we shall never cease
to be amused."
NB: Please do not use this email for correspondence.
I don't necessarily read it every week, even.
Rodney Dangerfield  - "What a dog I got, his favorite bone is in my arm."


--
Jonathan Leffler #include <disclaimer.h>
Email: jleffler@xxxxxxxxxxxxx, jleffler@xxxxxxxxxx
Guardian of DBD::Informix v2008.0513 -- http://dbi.perl.org/
"Blessed are we who can laugh at ourselves, for we shall never cease
to be amused."
NB: Please do not use this email for correspondence.
I don't necessarily read it every week, even.
P. J. O'Rourke - "If government were a product, selling it would be
illegal." - http://www.brainyquote.com/quotes/authors/p/p_j_orourke.html
.



Relevant Pages

  • Re: Require Help in Parsing strings!!!
    ... contains the following structure to store the data of these RRs as: ... the rdata part can have several fields depending on the specific ... port (all of unsigned int type) and a target string (the ... flags, services, regexp and replacement (all of type char *). ...
    (comp.programming)
  • Re: How does C cope if architecture doesnt address bytes?
    ... >> 'storage units' required to store an object of the type of its operand? ... > for pointers to char and void. ... > Exactly how these programs will fail is something that's notoriously hard ...
    (comp.lang.c)
  • Re: dereferencing type-punned pointer
    ... I keep getting this warning in GCC with the code segment below. ... the opposite -- that you can use the same memory to store, say, ... char, because it's always permitted to peek and poke the individual ... char and the compiler can't prove that the char isn't part of some ...
    (comp.lang.c)
  • Re: Record representation
    ... >>you change the data type from an Integer to a Natural? ... A series of messages related to alignment - not quite sure this is ... struct taxi_select_criteria { ... char starting_at; ...
    (comp.lang.ada)
  • Re: Newbie help on string splitting
    ... a logical first step would be to find out how to store the ... You can use an unsigned int to store the first and second ... int StrPos(const char *s, char c) ... To your problem, to store an individual IP, load it into an array of four chars ...
    (comp.lang.c)