EmuProxyZA / tdnsip.c

From TivoZA

Back to emuProxyZA.
Download source (You will need to rename it to: tdnsip.c)

To update the below source file, select Upload file and upload your new tdnsip.c file (there is no need to upload it as a .txt). If you do upload a new version, please add a brief description to the change log at the bottom of this page indicating what changes you made and why.

Source

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <fcntl.h>
  7. #include <string.h>
  8. #include "tivodns.h"
  9.  
  10. #define RESOLVCONF_FILE "./resolv.conf"
  11.  
  12. char nameserver[] = "nameserver 192.168.1.1\n";
  13.  
  14. int main( int argc, char **argv )
  15. {
  16. struct in_addr *result;
  17. char *hostname;
  18. int fd;
  19. int b;
  20. int lookup = 1;
  21.  
  22. if ( argc < 2 )
  23. {
  24. fprintf( stderr, "usage: %s -f /tmp/resolv.conf <hostname|ipAddress>\n",
  25. argv[ 0 ] );
  26. return 2;
  27. }
  28.  
  29. if ( strcmp( argv[ 1 ], "-f" ) != 0 )
  30. {
  31. fd = open( RESOLVCONF_FILE, O_WRONLY | O_CREAT, 0666 );
  32. if ( fd < 0 )
  33. {
  34. perror( "open resolv.conf" );
  35. exit( 1 );
  36. }
  37. write( fd, nameserver, sizeof( nameserver ) );
  38. close( fd );
  39.  
  40. tivodns_init( RESOLVCONF_FILE );
  41. }
  42. else
  43. {
  44. lookup = 3;
  45. fd = open( argv[ 2 ], O_RDONLY );
  46. if ( fd < 0 )
  47. {
  48. perror( "open resolv.conf" );
  49. exit( 1 );
  50. }
  51. tivodns_init( argv[ 2 ] );
  52. }
  53.  
  54. if ( sscanf( argv[ lookup ], "%d.%d.%d.%d", &b, &b, &b, &b ) == 4 )
  55. {
  56. // printf( "Reverse\n" );
  57. result = tivodns_aton4( argv[ lookup ] );
  58. hostname = tivodns_resolvename4( result );
  59. if ( hostname )
  60. {
  61. printf( "%s\n", hostname );
  62. return 0;
  63. }
  64. }
  65. else
  66. {
  67. // printf( "Forward\n" );
  68. result = tivodns_resolveip4( argv[ lookup ] );
  69. if (result)
  70. {
  71. printf( "%s\n", tivodns_ntoa4( result ) );
  72. return 0;
  73. }
  74. }
  75.  
  76. return 1;
  77. }

Change Log

13 Oct 2005 - TivoZA: Uploaded the file

Advertisement