#include #include #include #include #include #include #include #include "tivodns.h" #define RESOLVCONF_FILE "./resolv.conf" char nameserver[] = "nameserver 192.168.1.1\n"; int main( int argc, char **argv ) { struct in_addr *result; char *hostname; int fd; int b; int lookup = 1; if ( argc < 2 ) { fprintf( stderr, "usage: %s -f /tmp/resolv.conf \n", argv[ 0 ] ); return 2; } if ( strcmp( argv[ 1 ], "-f" ) != 0 ) { fd = open( RESOLVCONF_FILE, O_WRONLY | O_CREAT, 0666 ); if ( fd < 0 ) { perror( "open resolv.conf" ); exit( 1 ); } write( fd, nameserver, sizeof( nameserver ) ); close( fd ); tivodns_init( RESOLVCONF_FILE ); } else { lookup = 3; fd = open( argv[ 2 ], O_RDONLY ); if ( fd < 0 ) { perror( "open resolv.conf" ); exit( 1 ); } tivodns_init( argv[ 2 ] ); } if ( sscanf( argv[ lookup ], "%d.%d.%d.%d", &b, &b, &b, &b ) == 4 ) { // printf( "Reverse\n" ); result = tivodns_aton4( argv[ lookup ] ); hostname = tivodns_resolvename4( result ); if ( hostname ) { printf( "%s\n", hostname ); return 0; } } else { // printf( "Forward\n" ); result = tivodns_resolveip4( argv[ lookup ] ); if (result) { printf( "%s\n", tivodns_ntoa4( result ) ); return 0; } } return 1; }