diff options
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/Makefile.in | 1 | ||||
-rw-r--r-- | libbb/bb_xsocket.c | 18 | ||||
-rw-r--r-- | libbb/xconnect.c | 2 |
3 files changed, 20 insertions, 1 deletions
diff --git a/libbb/Makefile.in b/libbb/Makefile.in index de511fc..c699783 100644 --- a/libbb/Makefile.in +++ b/libbb/Makefile.in @@ -30,6 +30,7 @@ LIBBB-y:= \ trim.c u_signal_names.c vdprintf.c verror_msg.c \ vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \ xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \ + bb_xsocket.c \ get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \ getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \ perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \ diff --git a/libbb/bb_xsocket.c b/libbb/bb_xsocket.c new file mode 100644 index 0000000..839309a --- /dev/null +++ b/libbb/bb_xsocket.c @@ -0,0 +1,18 @@ +/* vi: set sw=4 ts=4: */ +/* + * bb_xsocket.c - a socket() which dies on failure with error message + * + * Copyright (C) 2006 Denis Vlasenko + * + * Licensed under LGPL, see file docs/lesser.txt in this tarball for details. + */ +#include <sys/socket.h> +#include "libbb.h" + +int bb_xsocket(int domain, int type, int protocol) +{ + int r = socket(domain, type, protocol); + if (r < 0) + bb_perror_msg_and_die("socket"); + return r; +} diff --git a/libbb/xconnect.c b/libbb/xconnect.c index ec99c58..39052b8 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c @@ -61,7 +61,7 @@ void bb_lookup_host(struct sockaddr_in *s_in, const char *host) int xconnect(struct sockaddr_in *s_addr) { - int s = socket(AF_INET, SOCK_STREAM, 0); + int s = bb_xsocket(AF_INET, SOCK_STREAM, 0); if (connect(s, (struct sockaddr *)s_addr, sizeof(struct sockaddr_in)) < 0) { if (ENABLE_FEATURE_CLEAN_UP) close(s); |