summaryrefslogtreecommitdiff
path: root/src/network/core/core.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/core/core.cpp')
-rw-r--r--src/network/core/core.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/network/core/core.cpp b/src/network/core/core.cpp
index 0aeb9c65c..8c5c5c229 100644
--- a/src/network/core/core.cpp
+++ b/src/network/core/core.cpp
@@ -13,6 +13,7 @@
#include "../../debug.h"
#include "os_abstraction.h"
#include "packet.h"
+#include "../../string_func.h"
#include "../../safeguards.h"
@@ -48,6 +49,22 @@ void NetworkCoreShutdown()
#endif
}
+#if defined(_WIN32)
+/**
+ * Return the string representation of the given error from the OS's network functions.
+ * @param error The error number (from \c NetworkGetLastError()).
+ * @return The error message, potentially an empty string but never \c nullptr.
+ */
+const char *NetworkGetErrorString(int error)
+{
+ static char buffer[512];
+ if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, sizeof(buffer), NULL) == 0) {
+ seprintf(buffer, lastof(buffer), "Unknown error %d", error);
+ }
+ return buffer;
+}
+#endif /* defined(_WIN32) */
/**
* Serializes the GRFIdentifier (GRF ID and MD5 checksum) to the packet