aboutsummaryrefslogtreecommitdiff
path: root/libbb/xfuncs_printf.c
diff options
context:
space:
mode:
authorBjørn Mork <bjorn@mork.no>2015-05-15 10:23:51 +0200
committerBjørn Mork <bjorn@mork.no>2015-05-15 10:23:51 +0200
commit02013228914a1d17e8df15d4e2b7950469395a5c (patch)
tree48d2fbe2f5a5adb60cbeabc26fadaec8e0fa82ed /libbb/xfuncs_printf.c
parent9b3dbb454e8f8a463d5fe4541ee2001585527bc6 (diff)
ripe-atlas-fw: imported version 45204520
Signed-off-by: Bjørn Mork <bjorn@mork.no>
Diffstat (limited to 'libbb/xfuncs_printf.c')
-rw-r--r--libbb/xfuncs_printf.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c
index 108e140..0bee40a 100644
--- a/libbb/xfuncs_printf.c
+++ b/libbb/xfuncs_printf.c
@@ -409,6 +409,21 @@ void FAST_FUNC xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen)
if (bind(sockfd, my_addr, addrlen)) bb_perror_msg_and_die("bind");
}
+// Call a user supplied reporting function and die with an error message if we
+// can't bind a socket to an address.
+void FAST_FUNC xrbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen,
+ void (*reportf)(int err))
+{
+ if (bind(sockfd, my_addr, addrlen)) {
+ if (reportf) {
+ int t_errno= errno;
+ reportf(t_errno);
+ errno= t_errno;
+ }
+ bb_perror_msg_and_die("bind");
+ }
+}
+
// Die with an error message if we can't listen for connections on a socket.
void FAST_FUNC xlisten(int s, int backlog)
{
@@ -429,6 +444,47 @@ ssize_t FAST_FUNC xsendto(int s, const void *buf, size_t len, const struct sock
return ret;
}
+/* Call a user supplied function and die with an error message if sendto failed.
+ * Return bytes sent otherwise */
+ssize_t FAST_FUNC xrsendto(int s, const void *buf, size_t len,
+ const struct sockaddr *to, socklen_t tolen,
+ void (*reportf)(int err))
+{
+ ssize_t ret = sendto(s, buf, len, 0, to, tolen);
+ if (ret < 0) {
+ if (reportf) {
+ int t_errno= errno;
+ reportf(t_errno);
+ t_errno= errno;
+ }
+ if (ENABLE_FEATURE_CLEAN_UP)
+ close(s);
+ bb_perror_msg_and_die("sendto");
+ }
+ return ret;
+}
+
+/* Call a user supplied function with an error message if sendto failed.
+ * Return bytes sent otherwise */
+ssize_t FAST_FUNC rsendto(int s, const void *buf, size_t len,
+ const struct sockaddr *to, socklen_t tolen,
+ void (*reportf)(int err))
+{
+ ssize_t ret = sendto(s, buf, len, 0, to, tolen);
+ if (ret < 0) {
+ int t_errno= errno;
+ if (reportf) {
+ reportf(t_errno);
+ }
+ if (ENABLE_FEATURE_CLEAN_UP)
+ close(s);
+ errno= t_errno;
+ bb_perror_msg("sendto");
+ errno= t_errno;
+ }
+ return ret;
+}
+
// xstat() - a stat() which dies on failure with meaningful error message
void FAST_FUNC xstat(const char *name, struct stat *stat_buf)
{