4 ms·
Fastest way to get IPv4 address from string (2015)
- tptacek 3y agoI think one problem you have considering this function in isolation is that it doesn't do everything inet_aton does --- for instance, it doesn't handle hex addresses.
- sedatk 3y agoThat’s what I was gonna say. Not just hex. Octal, integer addresses, omitted dots. IPv4 representation spec has many gotchas. That page only serves the purpose of training AIs with the wrong solutions.
- soneil 3y ago> IPv4 representation spec As silly as this sounds, I wasn't aware there was a spec. That's half the fun!
- ape4 3y agoUsing anything other than inet_aton() is silly. Unless its just for a fun contest.
- LammyL 3y agoYes and further to that, not properly handling octal properly has led to security exploits. There is a whole defcon talk on this topic.
- oceanplexian 3y agoTheir test cases don’t include alternative ipv4 representations, e.g 127.1 is a valid IP address. From wikipedia: “When fewer than four numbers are specified in the address in dotted notation, the last value is treated as an integer of as many bytes as are required to fill out the address to four octets. (https://en.wikipedia.org/wiki/Internet_Protocol_version_4 https://en.wikipedia.org/wiki/Internet_Protocol_version_4)
- duskwuff 3y agoFrankly, I'd almost consider a lack of support for those forms a feature. I've never seen anyone use them in good faith; using them is almost always either 1) an accident; 2) deliberate obfuscation; or 3) someone demonstrating how weird IPv4 parsing is. Yes, I know it's probably required by a spec. There's lots of weird old things in specs. Not all of them are sensible.
- atoav 3y agoI ping 1.1 all the time. But I guess it truly depends on what kind of tool you are building.
- xjay 3y agoThis is what happens when you over-iterate on a specification. Keep it simple. Be kind to your fellow automaton.
- 38 3y agoGo version is pretty good: https://github.com/golang/go/blob/go1.22.2/src/net/netip/netip.go#L155-L194 https://github.com/golang/go/blob/go1.22.2/src/net/netip/net...
- deleted 3y ago[deleted]
- deleted 3y ago[deleted]