[plug] strange behaviour of inet_aton().

Russell Steicke r.steicke at bom.gov.au
Thu Apr 6 13:15:44 WST 2000


>   inet_aton( "192.168" ) gives 192.0.0.168, and returns 1, indicating
> the argument was valid. This was intended as a shorthand for the
> network 192.168.0.0.  Is this buggy behaviour, or is there some reason for
> this? Do other Unixes do the same?

$ uname -sr  
OpenBSD 2.6
$ cat i.c
#include <sys/types.h>  /* Added this line */
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>

int main( int argc, char** argv ) {
    struct in_addr  addr;
    int n = inet_aton( argv[1], &addr );
    char* p = inet_ntoa( addr );
    printf( "n=%d, addr=%s.\n", n, p );
    return 0;
}
$ gcc -o i i.c
$ ./i 192.168
n=1, addr=192.0.0.168.
$ ./i 1.2     
n=1, addr=1.0.0.2.
$ ./i 192.168.1
n=1, addr=192.168.0.1.
$ 

Also tried on IRIX 6.5, but that reported

  n=1, addr=255.255.255.255.

for any quad.  Haven't time to look into why.

-- 
Russell Steicke

-- Fortune says:
If in doubt, mumble.



More information about the plug mailing list