/*
  Windows Sockets FTP Application

  Written by: John A. Junod            Internet: <junodj@gordon-emh2.army.mil>
              267 Hillwood Street                <zj8549@trotter.usma.edu>
              Martinez, GA 30907     Compuserve: 72321,366 

  This program executable and all source code is released into the public
  domain.

  MODULE: WS_ERROR.C  (error display routines)

  Based on code in either WINTEL or FINGER ???
*/

#include "ws_glob.h"
#include "ws_ftp.h"

typedef struct                      // associates an error code with text
{
  UINT err;
  char *sztext;
} ERRENTRY;

#define NUMwsErrs 27
ERRENTRY wsErrs[] =    // error text for windows sockets errors
{
   WSAVERNOTSUPPORTED, "version of WinSock not supported",
   WSASYSNOTREADY,     "WinSock not present or not responding",
   WSAEINVAL,          "app version not supported by DLL",
   WSAHOST_NOT_FOUND,  "Authoritive: Host not found",
   WSATRY_AGAIN,       "Non-authoritive: host not found or server failure",
   WSANO_RECOVERY,     "Non-recoverable: refused or not implemented",
   WSANO_DATA,         "Valid name, no data record for type",
   WSANO_ADDRESS,      "Valid name, no MX record",
   WSANOTINITIALISED,  "WSA Startup not initialized",
   WSAENETDOWN,        "Network subsystem failed",
   WSAEINPROGRESS,     "Blocking operation in progress",
   WSAEINTR,           "Blocking call cancelled",

   WSAEAFNOSUPPORT,    "address family not supported",
   WSAEMFILE,          "no file descriptors available",
   WSAENOBUFS,         "no buffer space available",
   WSAEPROTONOSUPPORT, "specified protocol not supported",
   WSAEPROTOTYPE,      "protocol wrong type for this socket",
   WSAESOCKTNOSUPPORT, "socket type not supported for address family",
   WSAENOTSOCK,        "descriptor is not a socket",
   WSAEWOULDBLOCK,     "socket marked as non-blocking and SO_LINGER set not 0",

   WSAEADDRINUSE,      "address already in use", //48

   WSAECONNABORTED,    "connection aborted",// 53
   WSAECONNRESET,      "connection reset",// 54
   WSAENOTCONN,        "not connected", //57
   WSAETIMEDOUT,       "connection timed out", // 60
   WSAECONNREFUSED,    "connection refused",  // 61
   WSAEHOSTDOWN,       "host down", // 64
   WSAEHOSTUNREACH,    "host unreachable", // 65
};

LPSTR ReturnWSError(UINT Err,LPSTR szBuf)
{
   int i;
   static char szErrMsg[128];

   if(szBuf==NULL) szBuf=szErrMsg;
   for (i = 0; i < NUMwsErrs; i++)
   {
      if (Err == wsErrs[i].err)
      {
         wsprintf((LPSTR)szBuf,(LPSTR)"%s",wsErrs[i].sztext);
         return(szBuf);
      }
   }
   wsprintf((LPSTR)szBuf, (LPSTR)"WS error %04x", Err);
   return(szBuf);
}

// ReportWSError -- prompt user with a windows sockets error message.
VOID ReportWSError(UINT Err)
{
   DoAddLine(ReturnWSError(Err,NULL));
}
