home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / ImageMagick-4.0.6.tar.gz / ImageMagick-4.0.6.tar / ImageMagick-4.0.6 / xtp / network.c < prev    next >
C/C++ Source or Header  |  1998-01-30  |  6KB  |  134 lines

  1. /*
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. %                                                                             %
  4. %                                                                             %
  5. %                                                                             %
  6. %             N   N  EEEEE  TTTTT  W   W   OOO   RRRR   K   K                 %
  7. %             NN  N  E        T    W   W  O   O  R   R  K  K                  %
  8. %             N N N  EEE      T    W W W  O   O  RRRR   KKK                   %
  9. %             N  NN  E        T    WW WW  O   O  R R    K  K                  %
  10. %             N   N  EEEEE    T    W   W   OOO   R  R   K   K                 %
  11. %                                                                             %
  12. %                                                                             %
  13. %                          Network Routines.                                  %
  14. %                                                                             %
  15. %                                                                             %
  16. %                           Software Design                                   %
  17. %                             John Cristy                                     %
  18. %                             October 1992                                    %
  19. %                                                                             %
  20. %                                                                             %
  21. %  Copyright 1998 E. I. du Pont de Nemours and Company                        %
  22. %                                                                             %
  23. %  Permission is hereby granted, free of charge, to any person obtaining a    %
  24. %  copy of this software and associated documentation files ("ImageMagick"),  %
  25. %  to deal in ImageMagick without restriction, including without limitation   %
  26. %  the rights to use, copy, modify, merge, publish, distribute, sublicense,   %
  27. %  and/or sell copies of ImageMagick, and to permit persons to whom the       %
  28. %  ImageMagick is furnished to do so, subject to the following conditions:    %
  29. %                                                                             %
  30. %  The above copyright notice and this permission notice shall be included in %
  31. %  all copies or substantial portions of ImageMagick.                         %
  32. %                                                                             %
  33. %  The software is provided "as is", without warranty of any kind, express or %
  34. %  implied, including but not limited to the warranties of merchantability,   %
  35. %  fitness for a particular purpose and noninfringement.  In no event shall   %
  36. %  E. I. du Pont de Nemours and Company be liable for any claim, damages or   %
  37. %  other liability, whether in an action of contract, tort or otherwise,      %
  38. %  arising from, out of or in connection with ImageMagick or the use or other %
  39. %  dealings in ImageMagick.                                                   %
  40. %                                                                             %
  41. %  Except as contained in this notice, the name of the E. I. du Pont de       %
  42. %  Nemours and Company shall not be used in advertising or otherwise to       %
  43. %  promote the sale, use or other dealings in ImageMagick without prior       %
  44. %  written authorization from the E. I. du Pont de Nemours and Company.       %
  45. %                                                                             %
  46. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  47. %
  48. %
  49. */
  50.  
  51. #include "xtp.h"
  52. #include "regular.h"
  53. #include <sys/types.h>
  54. #include <sys/socket.h>
  55. #include <netinet/in.h>
  56. #include <netdb.h>
  57. #include <arpa/inet.h>
  58.  
  59. /*
  60. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  61. %                                                                             %
  62. %                                                                             %
  63. %                                                                             %
  64. %   G e t H o s t I n f o                                                     %
  65. %                                                                             %
  66. %                                                                             %
  67. %                                                                             %
  68. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  69. %
  70. %  Function GetHostInfo accepts a host name or address, verifies it is valid,
  71. %  and returns both the host name and address from the network host entry.
  72. %
  73. %  The format of the GetHostInfo routine is:
  74. %
  75. %    info=GetHostInfo(name)
  76. %
  77. %  A description of each parameter follows:
  78. %
  79. %    o info:  Function GetHostInfo returns a pointer to the host name and
  80. %      IP address.  A null pointer is returned if there the host cannot be
  81. %      located.
  82. %
  83. %    o name:  Specifies a pointer to a character array that contains either
  84. %      a name of a host or an IP address.
  85. %
  86. %
  87. */
  88. char *GetHostInfo(char *name)
  89. {
  90.   char
  91.     *p;
  92.  
  93.   static char
  94.     info[2048];
  95.  
  96.   struct in_addr
  97.     in;
  98.  
  99.   struct hostent
  100.     *hp;
  101.  
  102.   /*
  103.     Get host name and address.
  104.   */
  105.   if (isascii(*name) && isdigit(*name))
  106.     in.s_addr=inet_addr(name);
  107.   else
  108.     {
  109.       in.s_addr=(unsigned long) -1;
  110.       hp=gethostbyname(name);
  111.       if (hp != (struct hostent *) NULL)
  112.         in.s_addr=(*(int *) hp->h_addr);
  113.     }
  114.   hp=gethostbyaddr((char *) &in,sizeof(struct in_addr),AF_INET);
  115.   if (hp == (struct hostent *) NULL)
  116.     {
  117.       hp=gethostbyname(name);
  118.       if (hp == (struct hostent *) NULL)
  119.         return((char *) NULL);
  120.     }
  121.   /*
  122.     Convert hostname to lower-case characters.
  123.   */
  124.   p=(char *) hp->h_name;
  125.   while (*p)
  126.   {
  127.     if (isupper(*p))
  128.       *p=tolower(*p);
  129.     p++;
  130.   }
  131.   (void) sprintf(info,"%s [%s]: ",hp->h_name,inet_ntoa(in));
  132.   return(info);
  133. }
  134.