diff options
author | Chris Hall <GMCH@hestia.halldom.com> | 2010-04-11 11:17:37 +0100 |
---|---|---|
committer | Chris Hall <GMCH@hestia.halldom.com> | 2010-04-11 11:17:37 +0100 |
commit | b878aa88eb8bb7ab74e24314e87c88586f15598d (patch) | |
tree | b51690eff9070c419dbe99602b9a974d82f8aaed /lib/errno_names.c | |
parent | 83447a051fbcc88b33fcea6670520687668d3ba1 (diff) | |
download | quagga-b878aa88eb8bb7ab74e24314e87c88586f15598d.tar.bz2 quagga-b878aa88eb8bb7ab74e24314e87c88586f15598d.tar.xz |
Support gai_strerror() and tidy bgp_listener code.
Added support for EAI_XXX error names and gai_strerror() error
messages.
Tidied up bgp_listener set up to remove #if skips around the
"old" way -- so that the older code doesn't simply rot away.
Diffstat (limited to 'lib/errno_names.c')
-rw-r--r-- | lib/errno_names.c | 60 |
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] ; +} ; |