home *** CD-ROM | disk | FTP | other *** search
/ Internet Publisher's Toolbox 2.0 / Internet Publisher's Toolbox.iso / internet / ntserver / wtsource / win32skt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-25  |  3.5 KB  |  95 lines

  1. /*
  2.  *  win32skt.c
  3.  *
  4.  *  This contains locking code for WAIS, called from irfiles.c.
  5.  *
  6.  *  (C) Copyright 1994 The University Court of the University of Edinburgh
  7.  *
  8.  *  Author:  Chris Adie <C.J.Adie@ed.ac.uk> 
  9.  *
  10.  */
  11.  
  12. /******************************************************************************/
  13. /* INCLUDE FILES                                                              */
  14. /******************************************************************************/
  15.  
  16. #include <windows.h>
  17. #include <winsock.h>
  18.  
  19. /******************************************************************************/
  20. /* CONSTANT DEFINITIONS                                                       */
  21. /******************************************************************************/
  22.  
  23. /* This section deliberately left blank */
  24.  
  25. /******************************************************************************/
  26. /* MACRO FUNCTION DEFINITIONS                                                 */
  27. /******************************************************************************/
  28.  
  29. /* This section deliberately left blank */
  30.  
  31. /******************************************************************************/
  32. /* TYPE DEFINITIONS                                                           */
  33. /******************************************************************************/
  34.  
  35. /* This section deliberately left blank */
  36.  
  37. /******************************************************************************/
  38. /* GLOBAL VARIABLES AND FUNCTIONS IMPORTED                                    */
  39. /******************************************************************************/
  40.  
  41. /* This section deliberately left blank */
  42. /* Consider whether these should appear in a header file */
  43.  
  44. /******************************************************************************/
  45. /* GLOBAL VARIABLES EXPORTED                                                  */
  46. /******************************************************************************/
  47.  
  48. /* This section deliberately left blank */
  49.  
  50. /******************************************************************************/
  51. /* VARIABLES PRIVATE TO THIS FILE                                             */
  52. /******************************************************************************/
  53.  
  54. static WSADATA                  wsaData = {0,0,"","",0,0,NULL};
  55.  
  56. /******************************************************************************/
  57. /* FUNCTIONS PRIVATE TO THIS FILE                                             */
  58. /******************************************************************************/
  59.  
  60. /* This section deliberately left blank */
  61.  
  62. /******************************************************************************/
  63. /* GLOBAL FUNCTIONS EXPORTED                                                  */
  64. /******************************************************************************/
  65.  
  66. /*
  67.  *  Return the fully-qualified name of the host, or else its IP address,
  68.  *  as a string.
  69.  */
  70. char *mygethostname(char *hostname,long len) {
  71. PHOSTENT phe;
  72. int err;
  73.  
  74.     err = gethostname(hostname,len);
  75.     if (err) return hostname;
  76.     phe = gethostbyname(hostname);
  77.     if (phe!=NULL) strncpy(hostname,phe->h_name,len);
  78.  
  79.     return hostname;
  80. }
  81.  
  82. void InitSockets(void) {
  83. int err;
  84.  
  85.     err = WSAStartup(MAKEWORD(1,1),&wsaData);
  86.     if (err) {
  87.         wsaData.wVersion = 0;
  88.     }
  89. }
  90.  
  91. void TermSockets(void) {
  92.     if (wsaData.wVersion!=0)    /* Infer a successful call to WSAStartup() */
  93.         WSACleanup();
  94. }
  95.