]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
Cygwin32 compatibility; reindent; add routine for printing WinSock errors
authorTed Lemon <source@isc.org>
Fri, 9 May 1997 08:03:44 +0000 (08:03 +0000)
committerTed Lemon <source@isc.org>
Fri, 9 May 1997 08:03:44 +0000 (08:03 +0000)
common/errwarn.c

index 34e0d81e51ff45d2a901b3f62bf0b6d069085aaf..078ae4172246090da75a2bea57d4e342313552b3 100644 (file)
@@ -42,7 +42,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: errwarn.c,v 1.14 1997/02/22 12:26:12 mellon Exp $ Copyright (c) 1996 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: errwarn.c,v 1.15 1997/05/09 08:03:44 mellon Exp $ Copyright (c) 1996 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -173,32 +173,40 @@ static void do_percentm (obuf, ibuf)
      char *obuf;
      char *ibuf;
 {
-  char *s = ibuf;
-  char *p = obuf;
-  int infmt = 0;
+       char *s = ibuf;
+       char *p = obuf;
+       int infmt = 0;
+       char *m;
 
-  while (*s)
-    {
-      if (infmt)
-       {
-         if (*s == 'm')
-           {
-             strcpy (p - 1, strerror (errno));
-             p += strlen (p);
-             ++s;
-           }
-         else
-           *p++ = *s++;
-         infmt = 0;
-       }
-      else
+       while (*s)
        {
-         if (*s == '%')
-           infmt = 1;
-         *p++ = *s++;
+               if (infmt)
+               {
+                       if (*s == 'm')
+                       {
+#ifndef __CYGWIN32__
+                               m = strerror (errno);
+#else
+                               m = pWSAError ();
+#endif
+                               if (!m)
+                                       m = "<unknown error>";
+                               strcpy (p - 1, m);
+                               p += strlen (p);
+                               ++s;
+                       }
+                       else
+                               *p++ = *s++;
+                       infmt = 0;
+               }
+               else
+               {
+                       if (*s == '%')
+                               infmt = 1;
+                       *p++ = *s++;
+               }
        }
-    }
-  *p = 0;
+       *p = 0;
 }
 
 
@@ -259,3 +267,125 @@ char *strerror (err)
        return sys_errlist [err];
 }
 #endif /* NO_STRERROR */
+
+#ifdef _WIN32
+char *pWSAError ()
+{
+  int err = WSAGetLastError ();
+
+  switch (err)
+    {
+    case WSAEACCES:
+      return "Permission denied";
+    case WSAEADDRINUSE:
+      return "Address already in use";
+    case WSAEADDRNOTAVAIL:
+      return "Cannot assign requested address";
+    case WSAEAFNOSUPPORT:
+      return "Address family not supported by protocol family";
+    case WSAEALREADY:
+      return "Operation already in progress";
+    case WSAECONNABORTED:
+      return "Software caused connection abort";
+    case WSAECONNREFUSED:
+      return "Connection refused";
+    case WSAECONNRESET:
+      return "Connection reset by peer";
+    case WSAEDESTADDRREQ:
+      return "Destination address required";
+    case WSAEFAULT:
+      return "Bad address";
+    case WSAEHOSTDOWN:
+      return "Host is down";
+    case WSAEHOSTUNREACH:
+      return "No route to host";
+    case WSAEINPROGRESS:
+      return "Operation now in progress";
+    case WSAEINTR:
+      return "Interrupted function call";
+    case WSAEINVAL:
+      return "Invalid argument";
+    case WSAEISCONN:
+      return "Socket is already connected";
+    case WSAEMFILE:
+      return "Too many open files";
+    case WSAEMSGSIZE:
+      return "Message too long";
+    case WSAENETDOWN:
+      return "Network is down";
+    case WSAENETRESET:
+      return "Network dropped connection on reset";
+    case WSAENETUNREACH:
+      return "Network is unreachable";
+    case WSAENOBUFS:
+      return "No buffer space available";
+    case WSAENOPROTOOPT:
+      return "Bad protocol option";
+    case WSAENOTCONN:
+      return "Socket is not connected";
+    case WSAENOTSOCK:
+      return "Socket operation on non-socket";
+    case WSAEOPNOTSUPP:
+      return "Operation not supported";
+    case WSAEPFNOSUPPORT:
+      return "Protocol family not supported";
+    case WSAEPROCLIM:
+      return "Too many processes";
+    case WSAEPROTONOSUPPORT:
+      return "Protocol not supported";
+    case WSAEPROTOTYPE:
+      return "Protocol wrong type for socket";
+    case WSAESHUTDOWN:
+      return "Cannot send after socket shutdown";
+    case WSAESOCKTNOSUPPORT:
+      return "Socket type not supported";
+    case WSAETIMEDOUT:
+      return "Connection timed out";
+    case WSAEWOULDBLOCK:
+      return "Resource temporarily unavailable";
+    case WSAHOST_NOT_FOUND:
+      return "Host not found";
+#if 0
+    case WSA_INVALID_HANDLE:
+      return "Specified event object handle is invalid";
+    case WSA_INVALID_PARAMETER:
+      return "One or more parameters are invalid";
+    case WSAINVALIDPROCTABLE:
+      return "Invalid procedure table from service provider";
+    case WSAINVALIDPROVIDER:
+      return "Invalid service provider version number";
+    case WSA_IO_PENDING:
+      return "Overlapped operations will complete later";
+    case WSA_IO_INCOMPLETE:
+      return "Overlapped I/O event object not in signaled state";
+    case WSA_NOT_ENOUGH_MEMORY:
+      return "Insufficient memory available";
+#endif
+    case WSANOTINITIALISED:
+      return "Successful WSAStartup not yet performer";
+    case WSANO_DATA:
+      return "Valid name, no data record of requested type";
+    case WSANO_RECOVERY:
+      return "This is a non-recoverable error";
+#if 0
+    case WSAPROVIDERFAILEDINIT:
+      return "Unable to initialize a service provider";
+    case WSASYSCALLFAILURE:
+      return "System call failure";
+#endif
+    case WSASYSNOTREADY:
+      return "Network subsystem is unavailable";
+    case WSATRY_AGAIN:
+      return "Non-authoritative host not found";
+    case WSAVERNOTSUPPORTED:
+      return "WINSOCK.DLL version out of range";
+    case WSAEDISCON:
+      return "Graceful shutdown in progress";
+#if 0
+    case WSA_OPERATION_ABORTED:
+      return "Overlapped operation aborted";
+#endif
+    }
+  return "Unknown WinSock error";
+}
+#endif /* _WIN32 */