OSDN Git Service

Add xgethostbyname and herror_msg* functions.
authorMatt Kraai <kraai@debian.org>
Wed, 16 May 2001 15:40:51 +0000 (15:40 -0000)
committerMatt Kraai <kraai@debian.org>
Wed, 16 May 2001 15:40:51 +0000 (15:40 -0000)
25 files changed:
Makefile
hostname.c
include/libbb.h
libbb/herror_msg.c [new file with mode: 0644]
libbb/herror_msg_and_die.c [new file with mode: 0644]
libbb/libbb.h
libbb/vherror_msg.c [new file with mode: 0644]
libbb/xgethostbyname.c [new file with mode: 0644]
nc.c
networking/hostname.c
networking/nc.c
networking/ping.c
networking/telnet.c
networking/tftp.c
networking/wget.c
nfsmount.c
ping.c
rdate.c
sysklogd/syslogd.c
syslogd.c
telnet.c
tftp.c
util-linux/nfsmount.c
util-linux/rdate.c
wget.c

index c52537a..866fe5b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -248,8 +248,9 @@ parse_mode.c parse_number.c perror_msg.c perror_msg_and_die.c print_file.c \
 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)),)
index f4118ea..75e4d2e 100644 (file)
@@ -1,6 +1,6 @@
 /* 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>
@@ -117,11 +117,7 @@ int hostname_main(int argc, char **argv)
                        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);
index 7ab0638..29a756b 100644 (file)
@@ -29,6 +29,8 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
+#include <netdb.h>
+
 #ifdef DMALLOC
 #include "dmalloc.h"
 #endif
@@ -77,6 +79,9 @@ extern void error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))
 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);
@@ -252,6 +257,8 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file);
 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
diff --git a/libbb/herror_msg.c b/libbb/herror_msg.c
new file mode 100644 (file)
index 0000000..f4210ed
--- /dev/null
@@ -0,0 +1,50 @@
+/* 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:
+*/
diff --git a/libbb/herror_msg_and_die.c b/libbb/herror_msg_and_die.c
new file mode 100644 (file)
index 0000000..0df5ed0
--- /dev/null
@@ -0,0 +1,51 @@
+/* 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:
+*/
index 7ab0638..29a756b 100644 (file)
@@ -29,6 +29,8 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
+#include <netdb.h>
+
 #ifdef DMALLOC
 #include "dmalloc.h"
 #endif
@@ -77,6 +79,9 @@ extern void error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))
 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);
@@ -252,6 +257,8 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file);
 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
diff --git a/libbb/vherror_msg.c b/libbb/vherror_msg.c
new file mode 100644 (file)
index 0000000..9a06f3a
--- /dev/null
@@ -0,0 +1,45 @@
+/* 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));
+}
diff --git a/libbb/xgethostbyname.c b/libbb/xgethostbyname.c
new file mode 100644 (file)
index 0000000..c722951
--- /dev/null
@@ -0,0 +1,35 @@
+/* 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;
+}
diff --git a/nc.c b/nc.c
index b58bd6a..5335872 100644 (file)
--- a/nc.c
+++ b/nc.c
@@ -91,8 +91,7 @@ int nc_main(int argc, char **argv)
                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]));
index f4118ea..75e4d2e 100644 (file)
@@ -1,6 +1,6 @@
 /* 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>
@@ -117,11 +117,7 @@ int hostname_main(int argc, char **argv)
                        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);
index b58bd6a..5335872 100644 (file)
@@ -91,8 +91,7 @@ int nc_main(int argc, char **argv)
                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]));
index 8b82dca..0967999 100644 (file)
@@ -1,6 +1,6 @@
 /* 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>
@@ -200,10 +200,7 @@ static void ping(const char *host)
        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;
 
@@ -446,15 +443,9 @@ static void ping(const char *host)
        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));
index 207732b..2587193 100644 (file)
@@ -644,18 +644,15 @@ static int getport(char * p)
 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()
 {
index 466851c..bb75c88 100644 (file)
@@ -390,15 +390,10 @@ int tftp_main(int argc, char **argv)
                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\","
index 5fa918a..6fd170d 100644 (file)
@@ -556,8 +556,7 @@ FILE *open_socket(char *host, int port)
 
        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);
 
@@ -813,7 +812,7 @@ progressmeter(int flag)
  * 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 $
  */
 
 
index a62df32..90cf9fb 100644 (file)
@@ -335,7 +335,7 @@ int nfsmount(const char *spec, const char *node, int *flags,
 #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)) {
@@ -580,7 +580,7 @@ int nfsmount(const char *spec, const char *node, int *flags,
            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)) {
diff --git a/ping.c b/ping.c
index 8b82dca..0967999 100644 (file)
--- a/ping.c
+++ b/ping.c
@@ -1,6 +1,6 @@
 /* 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>
@@ -200,10 +200,7 @@ static void ping(const char *host)
        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;
 
@@ -446,15 +443,9 @@ static void ping(const char *host)
        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));
diff --git a/rdate.c b/rdate.c
index ead1e7c..8deb35d 100644 (file)
--- a/rdate.c
+++ b/rdate.c
@@ -45,8 +45,7 @@ static time_t askremotedate(const char *host)
        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");
index 9c73758..6be51d7 100644 (file)
@@ -450,11 +450,7 @@ static void init_RemoteLog (void){
     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;
index 9c73758..6be51d7 100644 (file)
--- a/syslogd.c
+++ b/syslogd.c
@@ -450,11 +450,7 @@ static void init_RemoteLog (void){
     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;
index 207732b..2587193 100644 (file)
--- a/telnet.c
+++ b/telnet.c
@@ -644,18 +644,15 @@ static int getport(char * p)
 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()
 {
diff --git a/tftp.c b/tftp.c
index 466851c..bb75c88 100644 (file)
--- a/tftp.c
+++ b/tftp.c
@@ -390,15 +390,10 @@ int tftp_main(int argc, char **argv)
                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\","
index a62df32..90cf9fb 100644 (file)
@@ -335,7 +335,7 @@ int nfsmount(const char *spec, const char *node, int *flags,
 #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)) {
@@ -580,7 +580,7 @@ int nfsmount(const char *spec, const char *node, int *flags,
            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)) {
index ead1e7c..8deb35d 100644 (file)
@@ -45,8 +45,7 @@ static time_t askremotedate(const char *host)
        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");
diff --git a/wget.c b/wget.c
index 5fa918a..6fd170d 100644 (file)
--- a/wget.c
+++ b/wget.c
@@ -556,8 +556,7 @@ FILE *open_socket(char *host, int port)
 
        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);
 
@@ -813,7 +812,7 @@ progressmeter(int flag)
  * 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 $
  */