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));
*
* 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
#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.
*