2 ms·
0 prefix octal notation is a mistake. It bites people in the strangest places, like when they decide to make the IP addresses line up in a file by changing:
by jandrese 8y ago
0 prefix octal notation is a mistake. It bites people in the strangest places, like when they decide to make the IP addresses line up in a file by changing:
192.168.1.10
192.168.130.22
to:
192.168.001.010
192.168.130.022
What they thought would be a cosmetic change breaks their application. I've seen this happen several times. The new replacement for inet_addr (inet_pton) removes this braindamage, but it is not available on Windows.
- Something1234 8y agoI always thought I had to quote my ip addresses whenever I do socket programming? Is that not the case? Or does one the parsing routines in C do something with the 0? I could understand it if I was using commas instead of dots, and passing the parts to a function, but I'm not, I'm quoting them as a string.
- jandrese 8y agoYou pass it in as a string, and the standard library does strtol() on each component. The problem is that strtol() is "smart" and tries to autodetect the base of the input. So you could specify your IP address as 0xc0.0xa8.0xa.0x1 if you wanted, but who the hell does that?