diff options
author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2006-04-12 18:24:37 +0000 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2006-04-12 18:24:37 +0000 |
commit | 67f641e75b685abe1588b634b409c1ee2ff68c22 (patch) | |
tree | 74b3e38f1b7caef23bbf06a92b6e5d05530d50a6 | |
parent | 2c99851181a652358aa3ca58ef38c57e46ae02e4 (diff) | |
download | busybox-w32-67f641e75b685abe1588b634b409c1ee2ff68c22.tar.gz busybox-w32-67f641e75b685abe1588b634b409c1ee2ff68c22.tar.bz2 busybox-w32-67f641e75b685abe1588b634b409c1ee2ff68c22.zip |
- patch from Denis Vlasenko to add bb_xbind() and bb_xlisten()
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | libbb/Makefile.in | 2 | ||||
-rw-r--r-- | libbb/bb_xbind.c | 18 | ||||
-rw-r--r-- | libbb/bb_xlisten.c | 17 | ||||
-rw-r--r-- | networking/dnsd.c | 5 | ||||
-rw-r--r-- | networking/fakeidentd.c | 4 | ||||
-rw-r--r-- | networking/httpd.c | 9 | ||||
-rw-r--r-- | networking/nc.c | 7 | ||||
-rw-r--r-- | networking/telnetd.c | 10 | ||||
-rw-r--r-- | networking/traceroute.c | 4 |
10 files changed, 50 insertions, 28 deletions
diff --git a/include/libbb.h b/include/libbb.h index 650002b7b..d70c71cc0 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -147,6 +147,8 @@ extern void bb_fflush_stdout_and_exit(int retval) ATTRIBUTE_NORETURN; | |||
147 | extern void xstat(const char *filename, struct stat *buf); | 147 | extern void xstat(const char *filename, struct stat *buf); |
148 | extern int bb_xsocket(int domain, int type, int protocol); | 148 | extern int bb_xsocket(int domain, int type, int protocol); |
149 | extern void bb_xdaemon(int nochdir, int noclose); | 149 | extern void bb_xdaemon(int nochdir, int noclose); |
150 | extern void bb_xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen); | ||
151 | extern void bb_xlisten(int s, int backlog); | ||
150 | 152 | ||
151 | #define BB_GETOPT_ERROR 0x80000000UL | 153 | #define BB_GETOPT_ERROR 0x80000000UL |
152 | extern const char *bb_opt_complementally; | 154 | extern const char *bb_opt_complementally; |
diff --git a/libbb/Makefile.in b/libbb/Makefile.in index 3fb945e31..f05bf80ed 100644 --- a/libbb/Makefile.in +++ b/libbb/Makefile.in | |||
@@ -30,7 +30,7 @@ LIBBB-y:= \ | |||
30 | trim.c u_signal_names.c vdprintf.c verror_msg.c \ | 30 | trim.c u_signal_names.c vdprintf.c verror_msg.c \ |
31 | vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \ | 31 | vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \ |
32 | xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \ | 32 | xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \ |
33 | bb_xsocket.c bb_xdaemon.c \ | 33 | bb_xsocket.c bb_xdaemon.c bb_xbind.c bb_xlisten.c \ |
34 | get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \ | 34 | get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \ |
35 | getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \ | 35 | getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \ |
36 | perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \ | 36 | perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \ |
diff --git a/libbb/bb_xbind.c b/libbb/bb_xbind.c new file mode 100644 index 000000000..8a45af3bb --- /dev/null +++ b/libbb/bb_xbind.c | |||
@@ -0,0 +1,18 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * bb_xbind.c - a bind() which dies on failure with error message | ||
4 | * | ||
5 | * Copyright (C) 2006 Denis Vlasenko | ||
6 | * | ||
7 | * Licensed under LGPL, see file docs/lesser.txt in this tarball for details. | ||
8 | */ | ||
9 | #include <sys/types.h> | ||
10 | #include <sys/socket.h> | ||
11 | #include "libbb.h" | ||
12 | |||
13 | void bb_xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) | ||
14 | { | ||
15 | if (bind(sockfd, my_addr, addrlen)) | ||
16 | bb_perror_msg_and_die("bind"); | ||
17 | } | ||
18 | |||
diff --git a/libbb/bb_xlisten.c b/libbb/bb_xlisten.c new file mode 100644 index 000000000..a42d61a33 --- /dev/null +++ b/libbb/bb_xlisten.c | |||
@@ -0,0 +1,17 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * bb_xlisten.c - a listen() which dies on failure with error message | ||
4 | * | ||
5 | * Copyright (C) 2006 Denis Vlasenko | ||
6 | * | ||
7 | * Licensed under LGPL, see file docs/lesser.txt in this tarball for details. | ||
8 | */ | ||
9 | #include <sys/socket.h> | ||
10 | #include "libbb.h" | ||
11 | |||
12 | void bb_xlisten(int s, int backlog) | ||
13 | { | ||
14 | if (listen(s, backlog)) | ||
15 | bb_perror_msg_and_die("listen"); | ||
16 | } | ||
17 | |||
diff --git a/networking/dnsd.c b/networking/dnsd.c index d78ea04c0..b9d022170 100644 --- a/networking/dnsd.c +++ b/networking/dnsd.c | |||
@@ -216,9 +216,8 @@ listen_socket(char *iface_addr, int listen_port) | |||
216 | a.sin_family = AF_INET; | 216 | a.sin_family = AF_INET; |
217 | if (!inet_aton(iface_addr, &a.sin_addr)) | 217 | if (!inet_aton(iface_addr, &a.sin_addr)) |
218 | bb_perror_msg_and_die("bad iface address"); | 218 | bb_perror_msg_and_die("bad iface address"); |
219 | if (bind(s, (struct sockaddr *)&a, sizeof(a)) < 0) | 219 | bb_xbind(s, (struct sockaddr *)&a, sizeof(a)); |
220 | bb_perror_msg_and_die("bind() failed"); | 220 | listen(s, 50); /* bb_xlisten? */ |
221 | listen(s, 50); | ||
222 | sprintf(msg, "accepting UDP packets on addr:port %s:%d\n", | 221 | sprintf(msg, "accepting UDP packets on addr:port %s:%d\n", |
223 | iface_addr, (int)listen_port); | 222 | iface_addr, (int)listen_port); |
224 | log_message(LOG_FILE, msg); | 223 | log_message(LOG_FILE, msg); |
diff --git a/networking/fakeidentd.c b/networking/fakeidentd.c index 26efdcb34..cae6b8138 100644 --- a/networking/fakeidentd.c +++ b/networking/fakeidentd.c | |||
@@ -113,10 +113,10 @@ static void inetbind(void) | |||
113 | addr.sin_family = AF_INET; | 113 | addr.sin_family = AF_INET; |
114 | addr.sin_port = htons(port); | 114 | addr.sin_port = htons(port); |
115 | 115 | ||
116 | if (bind(s, (struct sockaddr *)&addr, len) < 0) | 116 | if (bind(s, (struct sockaddr *)&addr, len) < 0) /* bb_xbind? */ |
117 | bb_perror_msg_and_die("Cannot bind() port %i", IDENT_PORT); | 117 | bb_perror_msg_and_die("Cannot bind() port %i", IDENT_PORT); |
118 | 118 | ||
119 | if (listen(s, 5) < 0) | 119 | if (listen(s, 5) < 0) /* bb_xlisten? */ |
120 | bb_perror_msg_and_die("Cannot listen() on port %i", IDENT_PORT); | 120 | bb_perror_msg_and_die("Cannot listen() on port %i", IDENT_PORT); |
121 | 121 | ||
122 | movefd(s, 0); | 122 | movefd(s, 0); |
diff --git a/networking/httpd.c b/networking/httpd.c index 354c199e7..0f6174140 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -958,12 +958,9 @@ static int openServer(void) | |||
958 | #else | 958 | #else |
959 | setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)) ; | 959 | setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)) ; |
960 | #endif | 960 | #endif |
961 | if (bind(fd, (struct sockaddr *)&lsocket, sizeof(lsocket)) == 0) { | 961 | bb_xbind(fd, (struct sockaddr *)&lsocket, sizeof(lsocket)); |
962 | listen(fd, 9); | 962 | listen(fd, 9); /* bb_xlisten? */ |
963 | signal(SIGCHLD, SIG_IGN); /* prevent zombie (defunct) processes */ | 963 | signal(SIGCHLD, SIG_IGN); /* prevent zombie (defunct) processes */ |
964 | } else { | ||
965 | bb_perror_msg_and_die("bind"); | ||
966 | } | ||
967 | return fd; | 964 | return fd; |
968 | } | 965 | } |
969 | #endif /* CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY */ | 966 | #endif /* CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY */ |
diff --git a/networking/nc.c b/networking/nc.c index 86f0b99df..57b091744 100644 --- a/networking/nc.c +++ b/networking/nc.c | |||
@@ -90,16 +90,13 @@ int nc_main(int argc, char **argv) | |||
90 | memset(&address.sin_addr, 0, sizeof(address.sin_addr)); | 90 | memset(&address.sin_addr, 0, sizeof(address.sin_addr)); |
91 | address.sin_port = lport; | 91 | address.sin_port = lport; |
92 | 92 | ||
93 | if (bind(sfd, (struct sockaddr *) &address, sizeof(address)) < 0) | 93 | bb_xbind(sfd, (struct sockaddr *) &address, sizeof(address)); |
94 | bb_perror_msg_and_die("bind"); | ||
95 | } | 94 | } |
96 | 95 | ||
97 | if (do_listen) { | 96 | if (do_listen) { |
98 | socklen_t addrlen = sizeof(address); | 97 | socklen_t addrlen = sizeof(address); |
99 | 98 | ||
100 | if (listen(sfd, 1) < 0) | 99 | bb_xlisten(sfd, 1); |
101 | bb_perror_msg_and_die("listen"); | ||
102 | |||
103 | if ((tmpfd = accept(sfd, (struct sockaddr *) &address, &addrlen)) < 0) | 100 | if ((tmpfd = accept(sfd, (struct sockaddr *) &address, &addrlen)) < 0) |
104 | bb_perror_msg_and_die("accept"); | 101 | bb_perror_msg_and_die("accept"); |
105 | 102 | ||
diff --git a/networking/telnetd.c b/networking/telnetd.c index d53f56b14..1a53c0c0c 100644 --- a/networking/telnetd.c +++ b/networking/telnetd.c | |||
@@ -461,14 +461,8 @@ telnetd_main(int argc, char **argv) | |||
461 | sa.sin_addr = bind_addr; | 461 | sa.sin_addr = bind_addr; |
462 | #endif | 462 | #endif |
463 | 463 | ||
464 | if (bind(master_fd, (struct sockaddr *) &sa, sizeof(sa)) < 0) { | 464 | bb_xbind(master_fd, (struct sockaddr *) &sa, sizeof(sa)); |
465 | bb_perror_msg_and_die("bind"); | 465 | bb_xlisten(master_fd, 1); |
466 | } | ||
467 | |||
468 | if (listen(master_fd, 1) < 0) { | ||
469 | bb_perror_msg_and_die("listen"); | ||
470 | } | ||
471 | |||
472 | bb_xdaemon(0, 0); | 466 | bb_xdaemon(0, 0); |
473 | 467 | ||
474 | maxfd = master_fd; | 468 | maxfd = master_fd; |
diff --git a/networking/traceroute.c b/networking/traceroute.c index 0abd9047d..4f7ebf176 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c | |||
@@ -1253,9 +1253,7 @@ traceroute_main(int argc, char *argv[]) | |||
1253 | 1253 | ||
1254 | outip->ip_src = from->sin_addr; | 1254 | outip->ip_src = from->sin_addr; |
1255 | #ifndef IP_HDRINCL | 1255 | #ifndef IP_HDRINCL |
1256 | if (bind(sndsock, (struct sockaddr *)from, sizeof(*from)) < 0) { | 1256 | bb_xbind(sndsock, (struct sockaddr *)from, sizeof(*from)); |
1257 | bb_perror_msg_and_die("bind"); | ||
1258 | } | ||
1259 | #endif | 1257 | #endif |
1260 | 1258 | ||
1261 | fprintf(stderr, "traceroute to %s (%s)", hostname, inet_ntoa(to->sin_addr)); | 1259 | fprintf(stderr, "traceroute to %s (%s)", hostname, inet_ntoa(to->sin_addr)); |