From e96db86593fd874ae1e1c18171e0048c268f9076 Mon Sep 17 00:00:00 2001 From: Urban Wallasch Date: Thu, 24 Oct 2019 17:46:32 +0200 Subject: [PATCH] * net: added net_issyserr() --- net/net.c | 7 ++++++- net/net.h | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/net/net.c b/net/net.c index 8a1c2d4..2d52de5 100644 --- a/net/net.c +++ b/net/net.c @@ -108,11 +108,16 @@ static int net_bind_local(int sock, const char *addr, int st, int af ) { return err < 0 ? EAI_SYSTEM : 0; } +/* Check, if an error return code indicates system error: */ +int net_issyserr(int errnum) { + return (errnum == EAI_SYSTEM); +} + /* Copy textual description of last error to user supplied buffer: */ char *net_strerror(int errnum, char *buf, size_t len) { if (errnum >= 0) snprintf(buf, len, "Success"); - else if (errnum == EAI_SYSTEM) + else if (net_issyserr(errnum)) strerror_r(errno, buf, len); else snprintf(buf, len, gai_strerror(errnum)); diff --git a/net/net.h b/net/net.h index 5116176..f1a8454 100644 --- a/net/net.h +++ b/net/net.h @@ -15,6 +15,8 @@ * * tcp_accept - accept a TCP connection request on listener socket * + * net_issyserr - determine, if return code indicates system error + * * net_strerror - get textual error message * * recvfrom_tm @@ -36,6 +38,27 @@ extern "C" { #include + +/* + * Test if an error return code indicates a system level error. + * + * Returns either 1, in which case the actual error code can be found + * in errno, or 0, which means errnum should be checked against the + * list of EAI_XXX constants defined in netdb.h. + * + * errnum - a negative value returned by any function from net.h + * + * Note: So far the only functions which may return non-system errors + * are those of the XXX_open_server() and XXX_open_client() varieties. + * In other words, it is safe to assume that all other functions + * declared in net.h in case of failure store their error codes in + * errno. + * + * See also: net_strerror. + */ +extern int net_issyserr(int errnum); + + /* * Copy textual description of last error to user supplied buffer. * -- 2.30.2