home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / EXTRAS / UUCODE / UUPC / TEST / UPC12ES2.ZIP / UUCICO / pwserr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-30  |  8.8 KB  |  204 lines

  1. /*--------------------------------------------------------------------*/
  2. /*       p w s e r r . c                                              */
  3. /*                                                                    */
  4. /*       Report error message from Windows sockets error list         */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*       Changes Copyright (c) 1989-1993 by Kendra Electronic         */
  9. /*       Wonderworks.                                                 */
  10. /*                                                                    */
  11. /*       All rights reserved except those explicitly granted by       */
  12. /*       the UUPC/extended license agreement.                         */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*--------------------------------------------------------------------*/
  16. /*                          RCS Information                           */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*
  20.  *    $Id: pwserr.c 1.5 1993/10/30 22:07:19 dmwatt Exp $
  21.  *
  22.  *    Revision history:
  23.  *    $Log: pwserr.c $
  24.  * Revision 1.5  1993/10/30  22:07:19  dmwatt
  25.  * Host byte ordering and far/near pointer corrections
  26.  *
  27.  * Revision 1.4  1993/10/12  01:32:08  ahd
  28.  * Normalize comments to PL/I style
  29.  *
  30.  * Revision 1.3  1993/10/03  20:37:34  ahd
  31.  * Correct FAR pointer references
  32.  *
  33.  * Revision 1.2  1993/10/02  23:45:16  ahd
  34.  * Delete unneeded function
  35.  *
  36.  * Revision 1.1  1993/10/02  23:12:35  dmwatt
  37.  * Initial revision
  38.  *
  39.  */
  40.  
  41. /*--------------------------------------------------------------------*/
  42. /*                        System include files                        */
  43. /*--------------------------------------------------------------------*/
  44.  
  45. #include <stdio.h>
  46. #include <io.h>
  47.  
  48. #include "winsock.h"       /* So we search local directories           */
  49.  
  50. /*--------------------------------------------------------------------*/
  51. /*                    UUPC/extended include files                     */
  52. /*--------------------------------------------------------------------*/
  53.  
  54. #include "lib.h"           /* Cause we always include it!              */
  55.  
  56. /*--------------------------------------------------------------------*/
  57. /*                     Local function prototypes                      */
  58. /*--------------------------------------------------------------------*/
  59.  
  60. const char UUFAR *LookupWSError(int err);
  61.  
  62. /*--------------------------------------------------------------------*/
  63. /*                          Local variables                           */
  64. /*--------------------------------------------------------------------*/
  65.  
  66. typedef struct wserr {
  67.         int errno;
  68.         const char UUFAR *str;
  69. } WSERR;
  70.  
  71. static WSERR wsErrors[] = {
  72.   { WSABASEERR,         "[0] No Error" },
  73.   { WSAEINTR,           "[10004] Interrupted system call" },
  74.   { WSAEBADF,           "[10009] Bad file number" },
  75.   { WSAEACCES,          "[10013] Permission denied" },
  76.   { WSAEFAULT,          "[10014] Bad address" },
  77.   { WSAEINVAL,          "[10022] Invalid argument" },
  78.   { WSAEMFILE,          "[10024] Too many open files" },
  79.   { WSAEWOULDBLOCK,     "[10035] Operation would block" },
  80.   { WSAEINPROGRESS,     "[10036] Operation now in progress" },
  81.   { WSAEALREADY,        "[10037] Operation already in progress" },
  82.   { WSAENOTSOCK,        "[10038] Socket operation on non-socket" },
  83.   { WSAEDESTADDRREQ,    "[10039] Destination address required" },
  84.   { WSAEMSGSIZE,        "[10040] Message too long" },
  85.   { WSAEPROTOTYPE,      "[10041] Protocol wrong type for socket" },
  86.   { WSAENOPROTOOPT,     "[10042] Bad protocol option" },
  87.   { WSAEPROTONOSUPPORT, "[10043] Protocol not supported" },
  88.   { WSAESOCKTNOSUPPORT, "[10044] Socket type not supported" },
  89.   { WSAEOPNOTSUPP,      "[10045] Operation not supported on socket" },
  90.   { WSAEPFNOSUPPORT,    "[10046] Protocol family not supported" },
  91.   { WSAEAFNOSUPPORT,    "[10047] Address family not supported by protocol family" },
  92.   { WSAEADDRINUSE,      "[10048] Address already in use" },
  93.   { WSAEADDRNOTAVAIL,   "[10049] Can't assign requested address" },
  94.   { WSAENETDOWN,        "[10050] Network is down" },
  95.   { WSAENETUNREACH,     "[10051] Network is unreachable" },
  96.   { WSAENETRESET,       "[10052] Net dropped connection or reset" },
  97.   { WSAECONNABORTED,    "[10053] Software caused connection abort" },
  98.   { WSAECONNRESET,      "[10054] Connection reset by peer" },
  99.   { WSAENOBUFS,         "[10055] No buffer space available" },
  100.   { WSAEISCONN,         "[10056] Socket is already connected" },
  101.   { WSAENOTCONN,        "[10057] Socket is not connected" },
  102.   { WSAESHUTDOWN,       "[10058] Can't send after socket shutdown" },
  103.   { WSAETOOMANYREFS,    "[10059] Too many references, can't splice" },
  104.   { WSAETIMEDOUT,       "[10060] Connection timed out" },
  105.   { WSAECONNREFUSED,    "[10061] Connection refused" },
  106.   { WSAELOOP,           "[10062] Too many levels of symbolic links" },
  107.   { WSAENAMETOOLONG,    "[10063] File name too long" },
  108.   { WSAEHOSTDOWN,       "[10064] Host is down" },
  109.   { WSAEHOSTUNREACH,    "[10065] No Route to Host" },
  110.   { WSAENOTEMPTY,       "[10066] Directory not empty" },
  111.   { WSAEPROCLIM,        "[10067] Too many processes" },
  112.   { WSAEUSERS,          "[10068] Too many users" },
  113.   { WSAEDQUOT,          "[10069] Disc Quota Exceeded" },
  114.   { WSAESTALE,          "[10070] Stale NFS file handle" },
  115.   { WSAEREMOTE,         "[10071] Too many levels of remote in path" },
  116.   { WSASYSNOTREADY,     "[10091] Network SubSystem is unavailable" },
  117.   { WSAVERNOTSUPPORTED, "[10092] WINSOCK DLL Version out of range" },
  118.   { WSANOTINITIALISED,  "[10093] Successful WSASTARTUP not yet performed" },
  119.   { WSAHOST_NOT_FOUND,  "[11001] Host not found" },
  120.   { WSATRY_AGAIN,       "[11002] Non-Authoritative Host not found" },
  121.   { WSANO_RECOVERY,     "[11003] Non-Recoverable errors: FORMERR, REFUSED, NOTIMP" },
  122.   { WSANO_DATA,         "[11004] Valid name, no data record of requested type" },
  123.   { -1,                                 NULL }
  124. };
  125.  
  126. /* Copies string corresponding to the error code provided    */
  127. /* into buf, maximum length len. Returns length actually     */
  128. /* copied to buffer, or zero if error code is unknown.       */
  129. /* String resources should be present for each error code    */
  130. /* using the value of the code as the string ID (except for  */
  131. /* error = 0, which is mapped to WSABASEERR to keep it with  */
  132. /* the others). The DLL is free to use any string IDs that   */
  133. /* are less than WSABASEERR for its own use. The LibMain     */
  134. /* procedure of the DLL is presumed to have saved its        */
  135. /* HINSTANCE in the global variable hInst.                   */
  136.  
  137. /*--------------------------------------------------------------------*/
  138. /*                    UUPC/extended include files                     */
  139. /*--------------------------------------------------------------------*/
  140.  
  141. #include "lib.h"
  142. #include "pwserr.h"
  143.  
  144. /*--------------------------------------------------------------------*/
  145. /*    p W S e r r                                                     */
  146. /*                                                                    */
  147. /*    Perform a perror() with logging                                 */
  148. /*--------------------------------------------------------------------*/
  149.  
  150. void pWSErr(const size_t lineno,
  151.              const char *fname,
  152.              const char *prefix,
  153.              int rc)
  154. {
  155.    boolean redirect = ((logfile != stdout) && !isatty(fileno(stdout)));
  156.  
  157.    const char UUFAR *msg;
  158.  
  159.    msg = LookupWSError(rc);
  160.  
  161.    if (msg == NULL) {
  162.       printmsg(0, "Invalid error sent to pWSErr: %d", rc);
  163.       return;
  164.    }
  165.  
  166. /*--------------------------------------------------------------------*/
  167. /*           Display the message with option file location            */
  168. /*--------------------------------------------------------------------*/
  169.  
  170.    printmsg(2,"Windows sockets error %d in %s at line %d ...",
  171.             (int) rc, fname, lineno );
  172.  
  173. #ifdef _Windows
  174.    printmsg(0,"%s: %Fs", prefix, msg);
  175. #else
  176.    printmsg(0,"%s: %s", prefix, msg);
  177. #endif
  178.  
  179.    if ( redirect )
  180. #ifdef _Windows
  181.      fprintf(stdout,"%s: %Fs\n", prefix, msg);
  182. #else
  183.      fprintf(stdout,"%s: %s\n", prefix, msg);
  184. #endif
  185.  
  186. } /* pWSErr */
  187.  
  188. /*--------------------------------------------------------------------*/
  189. /*       L o o k u p W S E r r o r                                    */
  190. /*                                                                    */
  191. /*       Look up an error in our list of strings                      */
  192. /*--------------------------------------------------------------------*/
  193.  
  194. const char UUFAR *LookupWSError(int err)
  195. {
  196.    WSERR *pwsErr = wsErrors;
  197.  
  198.    while (pwsErr->errno != -1 && pwsErr->errno != err)
  199.       pwsErr++;
  200.  
  201.    return pwsErr->str;
  202.  
  203. } /* LookupWSError */
  204.