mirror of
https://github.com/sheumann/hush.git
synced 2025-01-18 07:31:34 +00:00
- patch from Denis Vlasenko to add bb_xbind() and bb_xlisten()
This commit is contained in:
parent
2c99851181
commit
67f641e75b
@ -147,6 +147,8 @@ extern void bb_fflush_stdout_and_exit(int retval) ATTRIBUTE_NORETURN;
|
|||||||
extern void xstat(const char *filename, struct stat *buf);
|
extern void xstat(const char *filename, struct stat *buf);
|
||||||
extern int bb_xsocket(int domain, int type, int protocol);
|
extern int bb_xsocket(int domain, int type, int protocol);
|
||||||
extern void bb_xdaemon(int nochdir, int noclose);
|
extern void bb_xdaemon(int nochdir, int noclose);
|
||||||
|
extern void bb_xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
|
||||||
|
extern void bb_xlisten(int s, int backlog);
|
||||||
|
|
||||||
#define BB_GETOPT_ERROR 0x80000000UL
|
#define BB_GETOPT_ERROR 0x80000000UL
|
||||||
extern const char *bb_opt_complementally;
|
extern const char *bb_opt_complementally;
|
||||||
|
@ -30,7 +30,7 @@ LIBBB-y:= \
|
|||||||
trim.c u_signal_names.c vdprintf.c verror_msg.c \
|
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 \
|
vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \
|
||||||
xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \
|
xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \
|
||||||
bb_xsocket.c bb_xdaemon.c \
|
bb_xsocket.c bb_xdaemon.c bb_xbind.c bb_xlisten.c \
|
||||||
get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.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 \
|
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 \
|
perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \
|
||||||
|
18
libbb/bb_xbind.c
Normal file
18
libbb/bb_xbind.c
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/* vi: set sw=4 ts=4: */
|
||||||
|
/*
|
||||||
|
* bb_xbind.c - a bind() 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/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include "libbb.h"
|
||||||
|
|
||||||
|
void bb_xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen)
|
||||||
|
{
|
||||||
|
if (bind(sockfd, my_addr, addrlen))
|
||||||
|
bb_perror_msg_and_die("bind");
|
||||||
|
}
|
||||||
|
|
17
libbb/bb_xlisten.c
Normal file
17
libbb/bb_xlisten.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/* vi: set sw=4 ts=4: */
|
||||||
|
/*
|
||||||
|
* bb_xlisten.c - a listen() 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"
|
||||||
|
|
||||||
|
void bb_xlisten(int s, int backlog)
|
||||||
|
{
|
||||||
|
if (listen(s, backlog))
|
||||||
|
bb_perror_msg_and_die("listen");
|
||||||
|
}
|
||||||
|
|
@ -216,9 +216,8 @@ listen_socket(char *iface_addr, int listen_port)
|
|||||||
a.sin_family = AF_INET;
|
a.sin_family = AF_INET;
|
||||||
if (!inet_aton(iface_addr, &a.sin_addr))
|
if (!inet_aton(iface_addr, &a.sin_addr))
|
||||||
bb_perror_msg_and_die("bad iface address");
|
bb_perror_msg_and_die("bad iface address");
|
||||||
if (bind(s, (struct sockaddr *)&a, sizeof(a)) < 0)
|
bb_xbind(s, (struct sockaddr *)&a, sizeof(a));
|
||||||
bb_perror_msg_and_die("bind() failed");
|
listen(s, 50); /* bb_xlisten? */
|
||||||
listen(s, 50);
|
|
||||||
sprintf(msg, "accepting UDP packets on addr:port %s:%d\n",
|
sprintf(msg, "accepting UDP packets on addr:port %s:%d\n",
|
||||||
iface_addr, (int)listen_port);
|
iface_addr, (int)listen_port);
|
||||||
log_message(LOG_FILE, msg);
|
log_message(LOG_FILE, msg);
|
||||||
|
@ -113,10 +113,10 @@ static void inetbind(void)
|
|||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_port = htons(port);
|
addr.sin_port = htons(port);
|
||||||
|
|
||||||
if (bind(s, (struct sockaddr *)&addr, len) < 0)
|
if (bind(s, (struct sockaddr *)&addr, len) < 0) /* bb_xbind? */
|
||||||
bb_perror_msg_and_die("Cannot bind() port %i", IDENT_PORT);
|
bb_perror_msg_and_die("Cannot bind() port %i", IDENT_PORT);
|
||||||
|
|
||||||
if (listen(s, 5) < 0)
|
if (listen(s, 5) < 0) /* bb_xlisten? */
|
||||||
bb_perror_msg_and_die("Cannot listen() on port %i", IDENT_PORT);
|
bb_perror_msg_and_die("Cannot listen() on port %i", IDENT_PORT);
|
||||||
|
|
||||||
movefd(s, 0);
|
movefd(s, 0);
|
||||||
|
@ -958,12 +958,9 @@ static int openServer(void)
|
|||||||
#else
|
#else
|
||||||
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)) ;
|
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)) ;
|
||||||
#endif
|
#endif
|
||||||
if (bind(fd, (struct sockaddr *)&lsocket, sizeof(lsocket)) == 0) {
|
bb_xbind(fd, (struct sockaddr *)&lsocket, sizeof(lsocket));
|
||||||
listen(fd, 9);
|
listen(fd, 9); /* bb_xlisten? */
|
||||||
signal(SIGCHLD, SIG_IGN); /* prevent zombie (defunct) processes */
|
signal(SIGCHLD, SIG_IGN); /* prevent zombie (defunct) processes */
|
||||||
} else {
|
|
||||||
bb_perror_msg_and_die("bind");
|
|
||||||
}
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY */
|
#endif /* CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY */
|
||||||
|
@ -90,16 +90,13 @@ int nc_main(int argc, char **argv)
|
|||||||
memset(&address.sin_addr, 0, sizeof(address.sin_addr));
|
memset(&address.sin_addr, 0, sizeof(address.sin_addr));
|
||||||
address.sin_port = lport;
|
address.sin_port = lport;
|
||||||
|
|
||||||
if (bind(sfd, (struct sockaddr *) &address, sizeof(address)) < 0)
|
bb_xbind(sfd, (struct sockaddr *) &address, sizeof(address));
|
||||||
bb_perror_msg_and_die("bind");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (do_listen) {
|
if (do_listen) {
|
||||||
socklen_t addrlen = sizeof(address);
|
socklen_t addrlen = sizeof(address);
|
||||||
|
|
||||||
if (listen(sfd, 1) < 0)
|
bb_xlisten(sfd, 1);
|
||||||
bb_perror_msg_and_die("listen");
|
|
||||||
|
|
||||||
if ((tmpfd = accept(sfd, (struct sockaddr *) &address, &addrlen)) < 0)
|
if ((tmpfd = accept(sfd, (struct sockaddr *) &address, &addrlen)) < 0)
|
||||||
bb_perror_msg_and_die("accept");
|
bb_perror_msg_and_die("accept");
|
||||||
|
|
||||||
|
@ -461,14 +461,8 @@ telnetd_main(int argc, char **argv)
|
|||||||
sa.sin_addr = bind_addr;
|
sa.sin_addr = bind_addr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (bind(master_fd, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
|
bb_xbind(master_fd, (struct sockaddr *) &sa, sizeof(sa));
|
||||||
bb_perror_msg_and_die("bind");
|
bb_xlisten(master_fd, 1);
|
||||||
}
|
|
||||||
|
|
||||||
if (listen(master_fd, 1) < 0) {
|
|
||||||
bb_perror_msg_and_die("listen");
|
|
||||||
}
|
|
||||||
|
|
||||||
bb_xdaemon(0, 0);
|
bb_xdaemon(0, 0);
|
||||||
|
|
||||||
maxfd = master_fd;
|
maxfd = master_fd;
|
||||||
|
@ -1253,9 +1253,7 @@ traceroute_main(int argc, char *argv[])
|
|||||||
|
|
||||||
outip->ip_src = from->sin_addr;
|
outip->ip_src = from->sin_addr;
|
||||||
#ifndef IP_HDRINCL
|
#ifndef IP_HDRINCL
|
||||||
if (bind(sndsock, (struct sockaddr *)from, sizeof(*from)) < 0) {
|
bb_xbind(sndsock, (struct sockaddr *)from, sizeof(*from));
|
||||||
bb_perror_msg_and_die("bind");
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fprintf(stderr, "traceroute to %s (%s)", hostname, inet_ntoa(to->sin_addr));
|
fprintf(stderr, "traceroute to %s (%s)", hostname, inet_ntoa(to->sin_addr));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user