In the last episode (Feb 11), Aaron Conaway said:
> I'm looking to develop a database of IP addresses for the company and
> have, of course, chosen mySQL as the backend. I want the app to add
> (remove, etc.) a host, giving its hostname and segment. The app will
> add the next available address to the database and, looking at the
> segment, provide the subnet mask and default gateway for said new
> host. I've got the db structure written out, but I'm having issues on
> how to store the data like address, subnet mask, default gateway.
>
> Our network is very diverse, covering many ranges of addresses and,
> more importantly, many subnet masks. Some are 24bit, some are 16bit,
> and some are 23bit. What is the best way to store this data in
> mySQL?
>
> If I do a varchar, then how do I restrict the data to between 0 and
> 255? Also, how would I manipulate any address with a classless mask?
> I'm thinking storage as binary so I can parse out a byte of binary
> data and present it as a decimal number; this also limits the data to
> numbers between 0 and 255, based on an 8-bit byte. The problem is
> that I have no clue how to store such.
Store your addresses as INTs, so you would have three fields:
"address", "netmask", and "gateway". You can either encode the values
yourself, or use mysql's INET_NTOA()/INET_ATON() functions.
--
Dan Nelson
[EMAIL PROTECTED]
sql, query
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php