process_escape_sequence.c read_package_field.c read_text_file_to_buffer.c \
recursive_action.c safe_read.c safe_strncpy.c seek_ared_file.c syscalls.c \
syslog_msg_with_name.c time_string.c trim.c untar.c unzip.c vdprintf.c \
-verror_msg.c vperror_msg.c wfopen.c xfuncs.c xgetcwd.c xreadlink.c\
-xregcomp.c interface.c remove_file.c last_char_is.c copyfd.c
+verror_msg.c vperror_msg.c wfopen.c xfuncs.c xgetcwd.c xreadlink.c \
+xregcomp.c interface.c remove_file.c last_char_is.c copyfd.c \
+vherror_msg.c herror_msg.c herror_msg_and_die.c xgethostbyname.c
LIBBB_OBJS=$(patsubst %.c,$(LIBBB)/%.o, $(LIBBB_CSRC))
LIBBB_CFLAGS = -I$(LIBBB)
ifneq ($(strip $(BB_SRC_DIR)),)
/* vi: set sw=4 ts=4: */
/*
- * $Id: hostname.c,v 1.27 2001/05/16 14:21:09 kraai Exp $
+ * $Id: hostname.c,v 1.28 2001/05/16 15:40:48 kraai Exp $
* Mini hostname implementation for busybox
*
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
s = strchr(buf, '.');
puts(s ? s + 1 : "");
} else if (opt_ip) {
- h = gethostbyname(buf);
- if (!h) {
- printf("Host not found\n");
- exit(1);
- }
+ h = xgethostbyname(buf);
puts(inet_ntoa(*(struct in_addr *) (h->h_addr)));
} else {
puts(buf);
#include <sys/stat.h>
#include <sys/types.h>
+#include <netdb.h>
+
#ifdef DMALLOC
#include "dmalloc.h"
#endif
extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
extern void perror_msg(const char *s, ...);
extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
+extern void vherror_msg(const char *s, va_list p);
+extern void herror_msg(const char *s, ...);
+extern void herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
/* These two are used internally -- you shouldn't need to use them */
extern void verror_msg(const char *s, va_list p);
extern void gz_close(int gunzip_pid);
extern int gz_open(FILE *compressed_file, int *pid);
+extern struct hostent *xgethostbyname(const char *name);
+
#define CT_AUTO 0
#define CT_UNIX2DOS 1
#define CT_DOS2UNIX 2
--- /dev/null
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) tons of folks. Tracking down who wrote what
+ * isn't something I'm going to worry about... If you wrote something
+ * here, please feel free to acknowledge your work.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Based in part on code from sash, Copyright (c) 1999 by David I. Bell
+ * Permission has been granted to redistribute this code under the GPL.
+ *
+ */
+
+#include <stdarg.h>
+#include <stdlib.h>
+
+#include "libbb.h"
+
+extern void herror_msg(const char *s, ...)
+{
+ va_list p;
+
+ va_start(p, s);
+ vherror_msg(s, p);
+ va_end(p);
+}
+
+
+/* END CODE */
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
--- /dev/null
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) tons of folks. Tracking down who wrote what
+ * isn't something I'm going to worry about... If you wrote something
+ * here, please feel free to acknowledge your work.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Based in part on code from sash, Copyright (c) 1999 by David I. Bell
+ * Permission has been granted to redistribute this code under the GPL.
+ *
+ */
+
+#include <stdarg.h>
+#include <stdlib.h>
+
+#include "libbb.h"
+
+extern void herror_msg_and_die(const char *s, ...)
+{
+ va_list p;
+
+ va_start(p, s);
+ vherror_msg(s, p);
+ va_end(p);
+ exit(EXIT_FAILURE);
+}
+
+
+/* END CODE */
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
#include <sys/stat.h>
#include <sys/types.h>
+#include <netdb.h>
+
#ifdef DMALLOC
#include "dmalloc.h"
#endif
extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
extern void perror_msg(const char *s, ...);
extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
+extern void vherror_msg(const char *s, va_list p);
+extern void herror_msg(const char *s, ...);
+extern void herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
/* These two are used internally -- you shouldn't need to use them */
extern void verror_msg(const char *s, va_list p);
extern void gz_close(int gunzip_pid);
extern int gz_open(FILE *compressed_file, int *pid);
+extern struct hostent *xgethostbyname(const char *name);
+
#define CT_AUTO 0
#define CT_UNIX2DOS 1
#define CT_DOS2UNIX 2
--- /dev/null
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) tons of folks. Tracking down who wrote what
+ * isn't something I'm going to worry about... If you wrote something
+ * here, please feel free to acknowledge your work.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Based in part on code from sash, Copyright (c) 1999 by David I. Bell
+ * Permission has been granted to redistribute this code under the GPL.
+ *
+ */
+
+#include <stdarg.h>
+#include <netdb.h>
+extern int h_errno;
+
+#include <stdio.h>
+
+#include "libbb.h"
+
+extern void vherror_msg(const char *s, va_list p)
+{
+ int err = h_errno;
+ if(s == 0)
+ s = "";
+ verror_msg(s, p);
+ if (*s)
+ s = ": ";
+ fprintf(stderr, "%s%s\n", s, hstrerror(err));
+}
--- /dev/null
+/* vi: set sw=4 ts=4: */
+/*
+ * Mini xgethostbyname implementation.
+ *
+ *
+ * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <netdb.h>
+extern int h_errno;
+
+struct hostent *xgethostbyname(const char *name)
+{
+ struct hostent *retval;
+
+ if ((retval = gethostbyname(name)) == NULL)
+ herror_msg_and_die("%s", name);
+
+ return retval;
+}
close(sfd);
sfd = tmpfd;
} else {
- if ((hostinfo = gethostbyname(argv[optind])) == NULL)
- error_msg_and_die("cannot resolve %s\n", argv[optind]);
+ hostinfo = xgethostbyname(argv[optind]);
address.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list;
address.sin_port = htons(atoi(argv[optind+1]));
/* vi: set sw=4 ts=4: */
/*
- * $Id: hostname.c,v 1.27 2001/05/16 14:21:09 kraai Exp $
+ * $Id: hostname.c,v 1.28 2001/05/16 15:40:48 kraai Exp $
* Mini hostname implementation for busybox
*
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
s = strchr(buf, '.');
puts(s ? s + 1 : "");
} else if (opt_ip) {
- h = gethostbyname(buf);
- if (!h) {
- printf("Host not found\n");
- exit(1);
- }
+ h = xgethostbyname(buf);
puts(inet_ntoa(*(struct in_addr *) (h->h_addr)));
} else {
puts(buf);
close(sfd);
sfd = tmpfd;
} else {
- if ((hostinfo = gethostbyname(argv[optind])) == NULL)
- error_msg_and_die("cannot resolve %s\n", argv[optind]);
+ hostinfo = xgethostbyname(argv[optind]);
address.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list;
address.sin_port = htons(atoi(argv[optind+1]));
/* vi: set sw=4 ts=4: */
/*
- * $Id: ping.c,v 1.40 2001/04/09 23:52:18 andersen Exp $
+ * $Id: ping.c,v 1.41 2001/05/16 15:40:48 kraai Exp $
* Mini ping implementation for busybox
*
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
memset(&pingaddr, 0, sizeof(struct sockaddr_in));
pingaddr.sin_family = AF_INET;
- if (!(h = gethostbyname(host))) {
- error_msg("unknown host %s", host);
- exit(1);
- }
+ h = xgethostbyname(host);
memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
hostname = h->h_name;
memset(&pingaddr, 0, sizeof(struct sockaddr_in));
pingaddr.sin_family = AF_INET;
- if (!(h = gethostbyname(host))) {
- error_msg("unknown host %s", host);
- exit(1);
- }
-
- if (h->h_addrtype != AF_INET) {
- error_msg("unknown address type; only AF_INET is currently supported.");
- exit(1);
- }
+ h = gethostbyname(host);
+ if (h->h_addrtype != AF_INET)
+ error_msg_and_die("unknown address type; only AF_INET is currently supported.");
pingaddr.sin_family = AF_INET; /* h->h_addrtype */
memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
static struct in_addr getserver(char * host)
{
struct in_addr addr;
-
+
struct hostent * he;
- if ((he = gethostbyname(host)) == NULL)
- {
- error_msg_and_die("%s: Unknown host", host);
- }
+ he = xgethostbyname(host);
memcpy(&addr, he->h_addr, sizeof addr);
TRACE(1, ("addr: %s\n", inet_ntoa(addr)));
-
+
return addr;
-}
+}
static int create_socket()
{
s = xstrdup(serverstr);
s[cp - serverstr] = '\0';
- if ((host = gethostbyname(s))) {
- bad = 0;
- }
+ host = xgethostbyname(s);
free(s);
}
- if (bad) {
- error_msg_and_die("bad \"server:file\" combination");
- }
if (BB_TFTP_DEBUG) {
printf("using server \"%s\", serverfile \"%s\","
memset(&s_in, 0, sizeof(s_in));
s_in.sin_family = AF_INET;
- if ((hp = (struct hostent *) gethostbyname(host)) == NULL)
- error_msg_and_die("cannot resolve %s", host);
+ hp = xgethostbyname(host);
memcpy(&s_in.sin_addr, hp->h_addr_list[0], hp->h_length);
s_in.sin_port = htons(port);
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: wget.c,v 1.40 2001/05/15 20:11:49 andersen Exp $
+ * $Id: wget.c,v 1.41 2001/05/16 15:40:48 kraai Exp $
*/
#endif
{
if ((hp = gethostbyname(hostname)) == NULL) {
- error_msg("can't get address for %s", hostname);
+ herror_msg("%s", hostname);
goto fail;
} else {
if (hp->h_length > sizeof(struct in_addr)) {
mount_server_addr.sin_addr.s_addr = inet_addr(hostname);
} else {
if ((hp = gethostbyname(mounthost)) == NULL) {
- error_msg("can't get address for %s", hostname);
+ herror_msg("%s", mounthost);
goto fail;
} else {
if (hp->h_length > sizeof(struct in_addr)) {
/* vi: set sw=4 ts=4: */
/*
- * $Id: ping.c,v 1.40 2001/04/09 23:52:18 andersen Exp $
+ * $Id: ping.c,v 1.41 2001/05/16 15:40:48 kraai Exp $
* Mini ping implementation for busybox
*
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
memset(&pingaddr, 0, sizeof(struct sockaddr_in));
pingaddr.sin_family = AF_INET;
- if (!(h = gethostbyname(host))) {
- error_msg("unknown host %s", host);
- exit(1);
- }
+ h = xgethostbyname(host);
memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
hostname = h->h_name;
memset(&pingaddr, 0, sizeof(struct sockaddr_in));
pingaddr.sin_family = AF_INET;
- if (!(h = gethostbyname(host))) {
- error_msg("unknown host %s", host);
- exit(1);
- }
-
- if (h->h_addrtype != AF_INET) {
- error_msg("unknown address type; only AF_INET is currently supported.");
- exit(1);
- }
+ h = gethostbyname(host);
+ if (h->h_addrtype != AF_INET)
+ error_msg_and_die("unknown address type; only AF_INET is currently supported.");
pingaddr.sin_family = AF_INET; /* h->h_addrtype */
memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
unsigned long int nett, localt;
int fd;
- if (!(h = gethostbyname(host))) /* get the IP addr */
- perror_msg_and_die("%s", host);
+ h = xgethostbyname(host); /* get the IP addr */
if ((tserv = getservbyname("time", "tcp")) == NULL) /* find port # */
perror_msg_and_die("%s", "time");
error_msg_and_die("syslogd: cannot create socket");
}
- hostinfo = (struct hostent *) gethostbyname(RemoteHost);
-
- if (!hostinfo) {
- error_msg_and_die("syslogd: cannot resolve remote host name [%s]", RemoteHost);
- }
+ hostinfo = xgethostbyname(RemoteHost);
remoteaddr.sin_family = AF_INET;
remoteaddr.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list;
error_msg_and_die("syslogd: cannot create socket");
}
- hostinfo = (struct hostent *) gethostbyname(RemoteHost);
-
- if (!hostinfo) {
- error_msg_and_die("syslogd: cannot resolve remote host name [%s]", RemoteHost);
- }
+ hostinfo = xgethostbyname(RemoteHost);
remoteaddr.sin_family = AF_INET;
remoteaddr.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list;
static struct in_addr getserver(char * host)
{
struct in_addr addr;
-
+
struct hostent * he;
- if ((he = gethostbyname(host)) == NULL)
- {
- error_msg_and_die("%s: Unknown host", host);
- }
+ he = xgethostbyname(host);
memcpy(&addr, he->h_addr, sizeof addr);
TRACE(1, ("addr: %s\n", inet_ntoa(addr)));
-
+
return addr;
-}
+}
static int create_socket()
{
s = xstrdup(serverstr);
s[cp - serverstr] = '\0';
- if ((host = gethostbyname(s))) {
- bad = 0;
- }
+ host = xgethostbyname(s);
free(s);
}
- if (bad) {
- error_msg_and_die("bad \"server:file\" combination");
- }
if (BB_TFTP_DEBUG) {
printf("using server \"%s\", serverfile \"%s\","
#endif
{
if ((hp = gethostbyname(hostname)) == NULL) {
- error_msg("can't get address for %s", hostname);
+ herror_msg("%s", hostname);
goto fail;
} else {
if (hp->h_length > sizeof(struct in_addr)) {
mount_server_addr.sin_addr.s_addr = inet_addr(hostname);
} else {
if ((hp = gethostbyname(mounthost)) == NULL) {
- error_msg("can't get address for %s", hostname);
+ herror_msg("%s", mounthost);
goto fail;
} else {
if (hp->h_length > sizeof(struct in_addr)) {
unsigned long int nett, localt;
int fd;
- if (!(h = gethostbyname(host))) /* get the IP addr */
- perror_msg_and_die("%s", host);
+ h = xgethostbyname(host); /* get the IP addr */
if ((tserv = getservbyname("time", "tcp")) == NULL) /* find port # */
perror_msg_and_die("%s", "time");
memset(&s_in, 0, sizeof(s_in));
s_in.sin_family = AF_INET;
- if ((hp = (struct hostent *) gethostbyname(host)) == NULL)
- error_msg_and_die("cannot resolve %s", host);
+ hp = xgethostbyname(host);
memcpy(&s_in.sin_addr, hp->h_addr_list[0], hp->h_length);
s_in.sin_port = htons(port);
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: wget.c,v 1.40 2001/05/15 20:11:49 andersen Exp $
+ * $Id: wget.c,v 1.41 2001/05/16 15:40:48 kraai Exp $
*/