return err < 0 ? EAI_SYSTEM : 0;
}
+/* 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)
+ strerror_r(errno, buf, len);
+ else
+ snprintf(buf, len, gai_strerror(errnum));
+ return buf;
+}
+
/* Create and bind a new listener socket: */
int net_open_server(const char *addr, const char *svc, int st, int af) {
int err, sock = -1;
int err;
err = shutdown(sock, SHUT_RDWR);
if (err < 0) {
- /* This "error" is never reported back to caller! */
+ /* This error is not forwarded to caller! */
NETLOG_DBG("shutdown(%d): %s", sock, strerror(errno));
}
err = close(sock);
return r;
}
-/* 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)
- strerror_r(errno, buf, len);
- else
- snprintf(buf, len, gai_strerror(errnum));
- return buf;
-}
-
/* Read from socket or file descriptor: */
ssize_t recvfrom_tm(int fd, void *buf, size_t len, int flags,
struct sockaddr *addr, socklen_t *alen, int timeout) {
*
* net_strerror - get textual error message
*
- * recvfrom_tm, recv_tm, read_tm
- * - functions and macros to read with timeout
+ * recvfrom_tm
+ * recv_tm
+ * read_tm - functions and macros to read with timeout
*
- * sendto_tm, send_tm, write_tm
- * - functions and macros to write with timeout
+ * sendto_tm
+ * send_tm
+ * write_tm - functions and macros to write with timeout
*
*/
#include <sys/socket.h>
+/*
+ * Copy textual description of last error to user supplied buffer.
+ *
+ * Returns a pointer to the buffer.
+ *
+ * errnum - <int> error code returned by any of the above functions
+ * buf - <char*> user supplied buffer to store the error message
+ * len - <size_t> maximum number of characters buf can hold
+ *
+ * Note: Depending on the actual value of errnum this function will
+ * return a message based on either strerror_r() or gai_strerror().
+ */
+extern char *net_strerror(int errnum, char *buf, size_t len);
+
+
/*
* Create a new socket with the specified characteristics, bind it to
* the local node address and, in case of SOCK_STREAM, start listening
*
* Returns 0 on success, or a negative value on error.
*
+ * Note: Errors returned by shutdown() are silently ignored and not
+ * forwarded.
+ *
* sock - <int> socket to close
*/
extern int net_close(int sock);
extern int tcp_accept(int sock, int timeout);
-/*
- * Copy textual description of last error to user supplied buffer.
- *
- * Returns a pointer to the buffer.
- *
- * errnum - <int> error code returned by any of the above functions
- * buf - <char*> user supplied buffer to store the error message
- * len - <size_t> maximum number of characters buf can hold
- *
- * Note: Depending on the actual value of errnum this function will
- * return a message based on either strerror_r() or gai_strerror().
- */
-extern char *net_strerror(int errnum, char *buf, size_t len);
-
-
/*
* Read from file or socket descriptor with timeout.
*