[plug] strange behaviour of inet_aton().

Mike Holland myk at golden.wattle.id.au
Wed Apr 5 16:16:06 WST 2000


I found this from a bug in a Perl program.
When parsing an incomplete dotted quad e.g.

  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?
   
test code:

#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;
}

Mike Holland  <mike at golden.wattle.id.au>
                          --==--
"A dirty mind is a joy forever."
-- Randy Kunkee




More information about the plug mailing list