2 ms·
Ah, parsing IPs. Just how exactly was the BSD's original inet_ntoa written, I wonder? The atoi/atol and sscanf with %d/%u always parse exactly decimal integers;
by Joker_vD 3y ago
Ah, parsing IPs. Just how exactly was the BSD's original inet_ntoa written, I wonder? The atoi/atol and sscanf with %d/%u always parse exactly decimal integers; it would had to use either %i or strtou with 0 base to have this silly effect.
- wahern 3y agoNo need to guess. My man page for inet_aton says it comes from 4.3BSD: https://github.com/dank101/4.3BSD-Reno/blob/master/lib/libc/net/inet_addr.c https://github.com/dank101/4.3BSD-Reno/blob/master/lib/libc/... The earlier inet_addr from 4.2BSD has the same logic: https://github.com/dank101/4.2BSD/blob/master/lib/libc/inet/inet_addr.c https://github.com/dank101/4.2BSD/blob/master/lib/libc/inet/... inet_aton and inet_addr parse addresses the obvious way. Using something like strtoul or especially sscanf would be stilted. The beauty of C pointers is that it makes simple parsing tasks very easy--perhaps too easy.
- Joker_vD 3y agoO_O They've intentionally coded it that way? This is atrocious. And this hand-rolled mess that doesn't even parse numbers correctly! It would parse "099" as 81 and "99999999999999999" as whatever it is modulo (MAX_ULONG+1), without any overflow detection. Well, at least they don't accept negative numbers, that's something. Anf mind you, beauty of C pointers has nothing to do with neither of these two bugs not the original decision to support octals and hexadecimals.
- doctor_eval 3y agoI laughed when I read that. “Back in the day” I decided to “clean up” my /etc/hosts by zero padding the quads. Anyway, the outcome was that I had to go back and remove the zeroes.