4 ms·
It won't solve most of the problems, but if you're using PostgreSQL its native inet datatype (which supports 4 or 6) instead of a text or binary string can save
by nieve 8y ago
It won't solve most of the problems, but if you're using PostgreSQL its native inet datatype (which supports 4 or 6) instead of a text or binary string can save a world of pain and there are alternatives in some other RDBMSs:
https://www.postgresql.org/docs/current/datatype-net-types.html#DATATYPE-INET https://www.postgresql.org/docs/current/datatype-net-types.h...
https://www.postgresql.org/docs/current/functions-net.html https://www.postgresql.org/docs/current/functions-net.html
First class network and ip types that properly support contains and exclusion operators make a lot of things less error-prone and potentially much faster.
- jschwartzi 8y agoYeah, most of these problems can be solved by declaring a new type of data, defining how a string address is parsed into that data type, defining rules for comparison, and using that type whenever a host is input into the system. These are problems that happen when you don't use the type system of a language or the language doesn't allow you to enforce specific types as input.
- nieve 8y agoI doubt we're ever going to get standardization on a given ip data type even within most languages, much less across them, but there's a tiny bit of hope that the various databases might converge on something vaguely portable. It's taken twenty years, but I'm actually seeing it with some other types. We just need to make sure MySQL doesn't release something where internally all ip addresses (4 & 6) are stored as 47 EBCDIC characters and silently corrupts your dumps if you're using a really-no-I-mean-it UTF-8 locale. (Not entirely fair to the MySQL devs, but a lot of database people have been burned by their approach and Oracle is not making this better.)
- nly 8y agoAny language with networking in the standard library should have a data type for IP addresses. There's no good reason for API bindings for database libs to not use them, and no good reason for you to not use them even if you're not using a database.
- nieve 8y agoAgreed in theory, but I've seen plenty of hand-rolled solutions even so and I think the dbs are at least slightly more likely to get standardization via ORM devs. One of the most painful I've run across was a system that was allocating ips for short, but highly variable lifespan VMs and trying to store them in MySQL database manipulated with both Ruby and Python. Even with language support there was no real defense against coworkers trying to brute-force complicated network checks on assignments when sub-second responses were needed. Unless your work is only ever in a small corner of a large system a single language and standard library having a native type won't always protect you from your code getting handed ip addresses from a foreign source in various text formats. The original post explains why this is a potential nightmare in detail.