ERRMSG.C
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:4k
源码类别:

Windows编程

开发平台:

Visual C++

  1. /****************************************************************************
  2. *  errmsg.c -- sample program demonstrating NWLink.
  3. *
  4. *       Original code from Micro Computer Systems, Inc.
  5. *       Copyright(c) 1992  All Rights Reserved.
  6. *       Microsoft Developer Support
  7. *       Copyright (c) 1992-1997 Microsoft Corporation
  8. *
  9. *  Demonstrates basic sockets programming with the Windows Sockets API
  10. *  using the NWLink transport.
  11. ****************************************************************************/
  12. #include <windows.h>
  13. #include "externs.h"
  14. /*
  15. *   Messages we return if there was no error or we didn't have it
  16. *   in our list.
  17. */
  18. char msg_no_error[19] =      "No error occurred!";
  19. char msg_unknown_error[14] = "Unknown error";
  20. /*
  21. *   Error structures - Windows error number (from winsock header) and
  22. *   the corresponding description string.
  23. */
  24. ERROR_STRUCT errlist[] = {
  25.     {WSAEINTR,           "WSAEINTR - Interrupted"},
  26.     {WSAEBADF,  "WSAEBADF - Bad file number"},            
  27.     {WSAEFAULT,    "WSAEFAULT - Bad address"},          
  28.     {WSAEINVAL,          "WSAEINVAL - Invalid argument"},          
  29.     {WSAEMFILE,          "WSAEMFILE - Too many open files"},          
  30. /*
  31. *    Windows Sockets definitions of regular Berkeley error constants
  32. */
  33.     {WSAEWOULDBLOCK,    "WSAEWOULDBLOCK - Socket marked as non-blocking"},
  34.     {WSAEINPROGRESS,     "WSAEINPROGRESS - Blocking call in progress"},
  35.     {WSAEALREADY,        "WSAEALREADY - Command already completed"},
  36.     {WSAENOTSOCK,        "WSAENOTSOCK - Descriptor is not a socket"},
  37.     {WSAEDESTADDRREQ,    "WSAEDESTADDRREQ - Destination address required"},  
  38.     {WSAEMSGSIZE,        "WSAEMSGSIZE - Data size too large"},     
  39.     {WSAEPROTOTYPE,      "WSAEPROTOTYPE - Protocol is of wrong type for this socket"},   
  40.     {WSAENOPROTOOPT,     "WSAENOPROTOOPT - Protocol option not supported for this socket type"},  
  41.     {WSAEPROTONOSUPPORT, "WSAEPROTONOSUPPORT - Protocol is not supported"},
  42.     {WSAESOCKTNOSUPPORT, "WSAESOCKTNOSUPPORT - Socket type not supported by this address family"},
  43.     {WSAEOPNOTSUPP,      "WSAEOPNOTSUPP - Option not supported"},   
  44.     {WSAEPFNOSUPPORT,    "WSAEPFNOSUPPORT - "}, 
  45.     {WSAEAFNOSUPPORT,    "WSAEAFNOSUPPORT - Address family not supported by this protocol"},
  46.     {WSAEADDRINUSE,      "WSAEADDRINUSE - Address is in use"},   
  47.     {WSAEADDRNOTAVAIL,   "WSAEADDRNOTAVAIL - Address not available from local machine"},
  48.     {WSAENETDOWN,        "WSAENETDOWN - Network subsystem is down"},     
  49.     {WSAENETUNREACH,     "WSAENETUNREACH - Network cannot be reached"},  
  50.     {WSAENETRESET,       "WSAENETRESET - Connection has been dropped"},    
  51.     {WSAECONNABORTED,    "WSAECONNABORTED - "}, 
  52.     {WSAECONNRESET,      "WSAECONNRESET - "},   
  53.     {WSAENOBUFS,         "WSAENOBUFS - No buffer space available"},      
  54.     {WSAEISCONN,         "WSAEISCONN - Socket is already connected"},      
  55.     {WSAENOTCONN,        "WSAENOTCONN - Socket is not connected"},     
  56.     {WSAESHUTDOWN,       "WSAESHUTDOWN - Socket has been shut down"},    
  57.     {WSAETOOMANYREFS,    "WSAETOOMANYREFS - "}, 
  58.     {WSAETIMEDOUT,       "WSAETIMEDOUT - Command timed out"},    
  59.     {WSAECONNREFUSED,    "WSAECONNREFUSED - Connection refused"}, 
  60.     {WSAELOOP,           "WSAELOOP - "},        
  61.     {WSAENAMETOOLONG,    "WSAENAMETOOLONG - "}, 
  62.     {WSAEHOSTDOWN,       "WSAEHOSTDOWN - "},    
  63.     {WSAEHOSTUNREACH,    "WSAEHOSTUNREACH - "}, 
  64.     {WSAENOTEMPTY,       "WSAENOTEMPTY - "},    
  65.     {WSAEPROCLIM,        "WSAEPROCLIM - "},     
  66.     {WSAEUSERS,          "WSAEUSERS - "},       
  67.     {WSAEDQUOT,          "WSAEDQUOT - "},       
  68.     {WSAESTALE,          "WSAESTALE - "},       
  69.     {WSAEREMOTE,         "WSAEREMOTE - "},      
  70.                         
  71. /*
  72. *    Extended Windows Sockets error constant definitions
  73. */
  74.     {WSASYSNOTREADY,     "WSASYSNOTREADY - Network subsystem not ready"},  
  75.     {WSAVERNOTSUPPORTED, "WSAVERNOTSUPPORTED - Version not supported"},
  76.     {WSANOTINITIALISED,  "WSANOTINITIALISED - WSAStartup() has not been successfully called"},
  77. /*
  78. *    Other error constants.
  79. */
  80.  
  81.     {WSAHOST_NOT_FOUND,  "WSAHOST_NOT_FOUND - Host not found"},
  82.     {WSATRY_AGAIN,       "WSATRY_AGAIN - Host not found or SERVERFAIL"},
  83.     {WSANO_RECOVERY,     "WSANO_RECOVERY - Non-recoverable error"},
  84.     {WSANO_DATA,         "WSANO_DATA - (or WSANO_ADDRESS) - No data record of requested type"},
  85.     {-1,  NULL}
  86. };