summaryrefslogtreecommitdiffstats
path: root/lib/errno_names.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/errno_names.c')
-rw-r--r--lib/errno_names.c60
1 files changed, 59 insertions, 1 deletions
diff --git a/lib/errno_names.c b/lib/errno_names.c
index 51f430a9..791f8001 100644
--- a/lib/errno_names.c
+++ b/lib/errno_names.c
@@ -21,6 +21,8 @@
#include <stddef.h>
#include <errno.h>
+#include <netdb.h>
+
#include "errno_names.h"
/*==============================================================================
@@ -291,7 +293,7 @@ static const char* errno_name_table[] =
enum { errno_last = (sizeof(errno_name_table) / sizeof(char*)) - 1 } ;
-/*==============================================================================
+/*------------------------------------------------------------------------------
* Lookup the name for given error number.
*
* Returns: address of string, or NULL if not known
@@ -308,4 +310,60 @@ errno_name_lookup(int err)
return errno_name_table[err] ;
} ;
+/*==============================================================================
+ * Table to map EAI error number to its name -- the errors generated by
+ * getaddrinfo() and getnameinfo().
+ *
+ * At least one system uses -ve numbers for these... so the following will
+ * support either +ve or -ve values, provided that all have the same sign.
+ */
+#if EAI_AGAIN < 0
+enum { eai_sgn = -1 } ;
+#else
+enum { eai_sgn = +1 } ;
+#endif
+
+#define EAINO(eai) [eai * eai_sgn] = #eai
+
+static const char* eaino_name_table[] =
+{
+ /* Error number for no error
+ *
+ * (123456789012345), /-- no name is more than 15 characters
+ */
+ EAINO(EAI_OK), /* No error */
+ /* POSIX Error Numbers -- taken Open Group Base Specifications Issue 7
+ * IEEE Std 1003.1-2008
+ */
+ EAINO(EAI_AGAIN), /* Temporary failure in name resolution. */
+ EAINO(EAI_BADFLAGS), /* Invalid value for 'ai_flags' field. */
+ EAINO(EAI_FAIL), /* Non-recoverable failure in name res. */
+ EAINO(EAI_FAMILY), /* 'ai_family' not supported. */
+ EAINO(EAI_MEMORY), /* Memory allocation failure. */
+ EAINO(EAI_NONAME), /* NAME or SERVICE is unknown. */
+ EAINO(EAI_OVERFLOW), /* Argument buffer overflow. */
+ EAINO(EAI_SERVICE), /* SERVICE not supported for 'ai_socktype'. */
+ EAINO(EAI_SOCKTYPE), /* 'ai_socktype' not supported. */
+ EAINO(EAI_SYSTEM), /* System error returned in 'errno'. */
+} ;
+
+enum { eaino_last = (sizeof(eaino_name_table) / sizeof(char*)) - 1 } ;
+
+/*------------------------------------------------------------------------------
+ * Lookup the name for given error number.
+ *
+ * Returns: address of string, or NULL if not known
+ *
+ * NB: for 0 returns "EOK".
+ *
+ * NB: async-signal-safe and thread-safe !
+ */
+extern const char*
+eaino_name_lookup(int eai)
+{
+ eai *= eai_sgn ;
+ if ((eai < 0) || (eai > eaino_last))
+ return NULL ;
+ return eaino_name_table[eai] ;
+} ;