Forum Moderators: coopster

Message Too Old, No Replies

Set bingint to 11 for optimal IP storage?

         

JAB Creations

10:01 am on Nov 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I noticed that when using long2ip on certain integers for IP addresses that many IP addresses were being listed as 127.255.255.255. Clearly the integers were hitting the 32 bit maximum integer of 2130706433.

So after setting the type for IP addresses in the database from int to bigint and tested inserting an IP of 255.255.255.255 the apparent maximum value turned out to be 4294967295 which is 11 characters in length. So I suppose this is a two fold question...

1.) If we're just talking IPV4 then is bigint with a limit of 11 the way to go?

2.) When taking IPV6 in to account how does this effect the optimal maximum length of integers?

- John

coopster

7:00 pm on Dec 1, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



1) Addresses are fixed length of four octets (32 bits) so INT UNSIGNED for dotted quad should suffice:
[dev.mysql.com...]

2) IPV6 is 128-bit. Here is a MySQL work log with some information and links that may help you get started: [forge.mysql.com...] ... which is my way of saying I don't know the answer to that question off hand John ;)