* net: added net_issyserr()
authorUrban Wallasch <urban.wallasch@freenet.de>
Thu, 24 Oct 2019 15:46:32 +0000 (17:46 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Thu, 24 Oct 2019 15:46:32 +0000 (17:46 +0200)
net/net.c
net/net.h

index 8a1c2d4900d805fef24b3df8905e633c2da88295..2d52de5674c7ce5d0dd2871e9ababcd39972460d 100644 (file)
--- 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));
index 511617671ea22e206f811f962a3d5ad145911ce8..f1a84543a438f0da0a122fc0279814ab1a32f7eb 100644 (file)
--- 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 <sys/socket.h>
 
+
+/*
+ * 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 - <int> 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.
  *