3 ms·
That covers the most common format accepted by the BSD and POSIX inet_* functions, but misses the less common ones. If anyone wants to have a go at a more comp
by tzs 9y ago
That covers the most common format accepted by the BSD and POSIX inet_* functions, but misses the less common ones.
If anyone wants to have a go at a more complete one, here are some test cases for you that it misses, using Google's well known public name server 8.8.4.4. These all work in the classic command line tools like ping on MacOS, Linux, and Windows:
134743044
8.525316
8.8.1028
POSIX and BSD also allow the numbers to be written in hex:
0x8080404
0x8.0x8.0x404
0x8.0x80404
0x8.0x8.0x4.0x4
or octal:
01002002004
010.2002004
010.010.02004
or mixed:
010.8.0x404