home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume06 / hname < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  2.2 KB

  1. From decwrl!wyse!uunet!allbery Sun Jan 29 16:45:39 PST 1989
  2. Article 787 of comp.sources.misc:
  3. Path: granite!decwrl!wyse!uunet!allbery
  4. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5. Newsgroups: comp.sources.misc
  6. Subject: v06i012: reverse hostname lookup program
  7. Message-ID: <47277@uunet.UU.NET>
  8. Date: 24 Jan 89 03:04:46 GMT
  9. Sender: allbery@uunet.UU.NET
  10. Reply-To: koreth@ssyx.UCSC.EDU (Steven Grimm)
  11. Lines: 72
  12. Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  13.  
  14. Posting-number: Volume 6, Issue 12
  15. Submitted-by: koreth@ssyx.UCSC.EDU (Steven Grimm)
  16. Archive-name: hname
  17.  
  18. This is primarily useful for sites running the Berkeley Internet Name Daemon
  19. or some other form of Internet name server; it looks up a host name given
  20. the host's internet address.  It looks up each of the arguments, or prompts
  21. for addresses if no arguments are given.  Example:
  22.  
  23. % hname 128.114.133.1
  24. 128.114.133.1 = SSYX.UCSC.EDU
  25.  
  26. This program isn't robust or complex or anything, but it works.  Note that
  27. your gethostbyaddr() routine must use the nameserver for this to work.
  28. ---
  29. These are my opinions, which you can probably ignore if you want to.
  30. Steven Grimm        Moderator, comp.{sources,binaries}.atari.st
  31. koreth@ssyx.ucsc.edu    uunet!ucbvax!ucscc!ssyx!koreth
  32.  
  33. #-------------- cut here -------------
  34. #!/bin/sh
  35. # shar:    Shell Archiver  (v1.22)
  36. #
  37. #    Run the following text with /bin/sh to create:
  38. #      hname.c
  39. #
  40. sed 's/^X//' << 'SHAR_EOF' > hname.c &&
  41. X#include <ctype.h>
  42. X#include <stdio.h>
  43. X#include <sys/types.h>
  44. X#include <netdb.h>
  45. X#include <sys/socket.h>
  46. X
  47. Xmain(argc, argv)
  48. Xchar **argv;
  49. X{
  50. X    int i;
  51. X    if (argc == 1)
  52. X    {
  53. X        char string[80];
  54. X
  55. X        while (! feof(stdin))
  56. X        {
  57. X            printf("> ");
  58. X            fflush(stdout);
  59. X            lookup(gets(string));
  60. X        }
  61. X    }
  62. X    else
  63. X        for (i=1; i<argc; i++)
  64. X            lookup(argv[i]);
  65. X}
  66. X
  67. Xlookup(string)
  68. Xchar *string;
  69. X{
  70. X    struct hostent *hp, *gethostbyaddr();
  71. X    long        addr, inet_addr();
  72. X
  73. X    if (! string || ! isdigit(string[0]))
  74. X        return;
  75. X    addr = inet_addr(string);
  76. X    hp = gethostbyaddr(&addr, sizeof(addr), AF_INET);
  77. X    if (hp == (struct hostent *)NULL)
  78. X        printf("%s not found\n", string);
  79. X    else
  80. X        printf("%s = %s\n", string, hp->h_name);
  81. X}
  82. X
  83. SHAR_EOF
  84. chmod 0600 hname.c || echo "restore of hname.c fails"
  85. exit 0
  86.  
  87.  
  88.