aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkraai <kraai@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-05-16 15:40:51 +0000
committerkraai <kraai@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-05-16 15:40:51 +0000
commit7ee6d7639da2e6f8ec5c282f2dab4e66fa359743 (patch)
tree03c1fca61c1b577b7c527d2b8482c5b7f6972bcd
parentbbb602f480533eb3bdc18187065b3b5616482f4a (diff)
downloadbusybox-w32-7ee6d7639da2e6f8ec5c282f2dab4e66fa359743.tar.gz
busybox-w32-7ee6d7639da2e6f8ec5c282f2dab4e66fa359743.tar.bz2
busybox-w32-7ee6d7639da2e6f8ec5c282f2dab4e66fa359743.zip
Add xgethostbyname and herror_msg* functions.
git-svn-id: svn://busybox.net/trunk/busybox@2654 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--Makefile5
-rw-r--r--hostname.c8
-rw-r--r--include/libbb.h7
-rw-r--r--libbb/herror_msg.c50
-rw-r--r--libbb/herror_msg_and_die.c51
-rw-r--r--libbb/libbb.h7
-rw-r--r--libbb/vherror_msg.c45
-rw-r--r--libbb/xgethostbyname.c35
-rw-r--r--nc.c3
-rw-r--r--networking/hostname.c8
-rw-r--r--networking/nc.c3
-rw-r--r--networking/ping.c19
-rw-r--r--networking/telnet.c11
-rw-r--r--networking/tftp.c7
-rw-r--r--networking/wget.c5
-rw-r--r--nfsmount.c4
-rw-r--r--ping.c19
-rw-r--r--rdate.c3
-rw-r--r--sysklogd/syslogd.c6
-rw-r--r--syslogd.c6
-rw-r--r--telnet.c11
-rw-r--r--tftp.c7
-rw-r--r--util-linux/nfsmount.c4
-rw-r--r--util-linux/rdate.c3
-rw-r--r--wget.c5
25 files changed, 236 insertions, 96 deletions
diff --git a/Makefile b/Makefile
index c52537a0c..866fe5b46 100644
--- 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 \
248process_escape_sequence.c read_package_field.c read_text_file_to_buffer.c \ 248process_escape_sequence.c read_package_field.c read_text_file_to_buffer.c \
249recursive_action.c safe_read.c safe_strncpy.c seek_ared_file.c syscalls.c \ 249recursive_action.c safe_read.c safe_strncpy.c seek_ared_file.c syscalls.c \
250syslog_msg_with_name.c time_string.c trim.c untar.c unzip.c vdprintf.c \ 250syslog_msg_with_name.c time_string.c trim.c untar.c unzip.c vdprintf.c \
251verror_msg.c vperror_msg.c wfopen.c xfuncs.c xgetcwd.c xreadlink.c\ 251verror_msg.c vperror_msg.c wfopen.c xfuncs.c xgetcwd.c xreadlink.c \
252xregcomp.c interface.c remove_file.c last_char_is.c copyfd.c 252xregcomp.c interface.c remove_file.c last_char_is.c copyfd.c \
253vherror_msg.c herror_msg.c herror_msg_and_die.c xgethostbyname.c
253LIBBB_OBJS=$(patsubst %.c,$(LIBBB)/%.o, $(LIBBB_CSRC)) 254LIBBB_OBJS=$(patsubst %.c,$(LIBBB)/%.o, $(LIBBB_CSRC))
254LIBBB_CFLAGS = -I$(LIBBB) 255LIBBB_CFLAGS = -I$(LIBBB)
255ifneq ($(strip $(BB_SRC_DIR)),) 256ifneq ($(strip $(BB_SRC_DIR)),)
diff --git a/hostname.c b/hostname.c
index f4118ea36..75e4d2e57 100644
--- a/hostname.c
+++ b/hostname.c
@@ -1,6 +1,6 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/* 2/*
3 * $Id: hostname.c,v 1.27 2001/05/16 14:21:09 kraai Exp $ 3 * $Id: hostname.c,v 1.28 2001/05/16 15:40:48 kraai Exp $
4 * Mini hostname implementation for busybox 4 * Mini hostname implementation for busybox
5 * 5 *
6 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> 6 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@@ -117,11 +117,7 @@ int hostname_main(int argc, char **argv)
117 s = strchr(buf, '.'); 117 s = strchr(buf, '.');
118 puts(s ? s + 1 : ""); 118 puts(s ? s + 1 : "");
119 } else if (opt_ip) { 119 } else if (opt_ip) {
120 h = gethostbyname(buf); 120 h = xgethostbyname(buf);
121 if (!h) {
122 printf("Host not found\n");
123 exit(1);
124 }
125 puts(inet_ntoa(*(struct in_addr *) (h->h_addr))); 121 puts(inet_ntoa(*(struct in_addr *) (h->h_addr)));
126 } else { 122 } else {
127 puts(buf); 123 puts(buf);
diff --git a/include/libbb.h b/include/libbb.h
index 7ab06388a..29a756b7f 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -29,6 +29,8 @@
29#include <sys/stat.h> 29#include <sys/stat.h>
30#include <sys/types.h> 30#include <sys/types.h>
31 31
32#include <netdb.h>
33
32#ifdef DMALLOC 34#ifdef DMALLOC
33#include "dmalloc.h" 35#include "dmalloc.h"
34#endif 36#endif
@@ -77,6 +79,9 @@ extern void error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))
77extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); 79extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
78extern void perror_msg(const char *s, ...); 80extern void perror_msg(const char *s, ...);
79extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn)); 81extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
82extern void vherror_msg(const char *s, va_list p);
83extern void herror_msg(const char *s, ...);
84extern void herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
80 85
81/* These two are used internally -- you shouldn't need to use them */ 86/* These two are used internally -- you shouldn't need to use them */
82extern void verror_msg(const char *s, va_list p); 87extern void verror_msg(const char *s, va_list p);
@@ -252,6 +257,8 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file);
252extern void gz_close(int gunzip_pid); 257extern void gz_close(int gunzip_pid);
253extern int gz_open(FILE *compressed_file, int *pid); 258extern int gz_open(FILE *compressed_file, int *pid);
254 259
260extern struct hostent *xgethostbyname(const char *name);
261
255#define CT_AUTO 0 262#define CT_AUTO 0
256#define CT_UNIX2DOS 1 263#define CT_UNIX2DOS 1
257#define CT_DOS2UNIX 2 264#define CT_DOS2UNIX 2
diff --git a/libbb/herror_msg.c b/libbb/herror_msg.c
new file mode 100644
index 000000000..f4210edad
--- /dev/null
+++ b/libbb/herror_msg.c
@@ -0,0 +1,50 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Utility routines.
4 *
5 * Copyright (C) tons of folks. Tracking down who wrote what
6 * isn't something I'm going to worry about... If you wrote something
7 * here, please feel free to acknowledge your work.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 * Based in part on code from sash, Copyright (c) 1999 by David I. Bell
24 * Permission has been granted to redistribute this code under the GPL.
25 *
26 */
27
28#include <stdarg.h>
29#include <stdlib.h>
30
31#include "libbb.h"
32
33extern void herror_msg(const char *s, ...)
34{
35 va_list p;
36
37 va_start(p, s);
38 vherror_msg(s, p);
39 va_end(p);
40}
41
42
43/* END CODE */
44/*
45Local Variables:
46c-file-style: "linux"
47c-basic-offset: 4
48tab-width: 4
49End:
50*/
diff --git a/libbb/herror_msg_and_die.c b/libbb/herror_msg_and_die.c
new file mode 100644
index 000000000..0df5ed016
--- /dev/null
+++ b/libbb/herror_msg_and_die.c
@@ -0,0 +1,51 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Utility routines.
4 *
5 * Copyright (C) tons of folks. Tracking down who wrote what
6 * isn't something I'm going to worry about... If you wrote something
7 * here, please feel free to acknowledge your work.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 * Based in part on code from sash, Copyright (c) 1999 by David I. Bell
24 * Permission has been granted to redistribute this code under the GPL.
25 *
26 */
27
28#include <stdarg.h>
29#include <stdlib.h>
30
31#include "libbb.h"
32
33extern void herror_msg_and_die(const char *s, ...)
34{
35 va_list p;
36
37 va_start(p, s);
38 vherror_msg(s, p);
39 va_end(p);
40 exit(EXIT_FAILURE);
41}
42
43
44/* END CODE */
45/*
46Local Variables:
47c-file-style: "linux"
48c-basic-offset: 4
49tab-width: 4
50End:
51*/
diff --git a/libbb/libbb.h b/libbb/libbb.h
index 7ab06388a..29a756b7f 100644
--- a/libbb/libbb.h
+++ b/libbb/libbb.h
@@ -29,6 +29,8 @@
29#include <sys/stat.h> 29#include <sys/stat.h>
30#include <sys/types.h> 30#include <sys/types.h>
31 31
32#include <netdb.h>
33
32#ifdef DMALLOC 34#ifdef DMALLOC
33#include "dmalloc.h" 35#include "dmalloc.h"
34#endif 36#endif
@@ -77,6 +79,9 @@ extern void error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))
77extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); 79extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
78extern void perror_msg(const char *s, ...); 80extern void perror_msg(const char *s, ...);
79extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn)); 81extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
82extern void vherror_msg(const char *s, va_list p);
83extern void herror_msg(const char *s, ...);
84extern void herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
80 85
81/* These two are used internally -- you shouldn't need to use them */ 86/* These two are used internally -- you shouldn't need to use them */
82extern void verror_msg(const char *s, va_list p); 87extern void verror_msg(const char *s, va_list p);
@@ -252,6 +257,8 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file);
252extern void gz_close(int gunzip_pid); 257extern void gz_close(int gunzip_pid);
253extern int gz_open(FILE *compressed_file, int *pid); 258extern int gz_open(FILE *compressed_file, int *pid);
254 259
260extern struct hostent *xgethostbyname(const char *name);
261
255#define CT_AUTO 0 262#define CT_AUTO 0
256#define CT_UNIX2DOS 1 263#define CT_UNIX2DOS 1
257#define CT_DOS2UNIX 2 264#define CT_DOS2UNIX 2
diff --git a/libbb/vherror_msg.c b/libbb/vherror_msg.c
new file mode 100644
index 000000000..9a06f3a38
--- /dev/null
+++ b/libbb/vherror_msg.c
@@ -0,0 +1,45 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Utility routines.
4 *
5 * Copyright (C) tons of folks. Tracking down who wrote what
6 * isn't something I'm going to worry about... If you wrote something
7 * here, please feel free to acknowledge your work.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 * Based in part on code from sash, Copyright (c) 1999 by David I. Bell
24 * Permission has been granted to redistribute this code under the GPL.
25 *
26 */
27
28#include <stdarg.h>
29#include <netdb.h>
30extern int h_errno;
31
32#include <stdio.h>
33
34#include "libbb.h"
35
36extern void vherror_msg(const char *s, va_list p)
37{
38 int err = h_errno;
39 if(s == 0)
40 s = "";
41 verror_msg(s, p);
42 if (*s)
43 s = ": ";
44 fprintf(stderr, "%s%s\n", s, hstrerror(err));
45}
diff --git a/libbb/xgethostbyname.c b/libbb/xgethostbyname.c
new file mode 100644
index 000000000..c722951cf
--- /dev/null
+++ b/libbb/xgethostbyname.c
@@ -0,0 +1,35 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini xgethostbyname implementation.
4 *
5 *
6 * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24#include <netdb.h>
25extern int h_errno;
26
27struct hostent *xgethostbyname(const char *name)
28{
29 struct hostent *retval;
30
31 if ((retval = gethostbyname(name)) == NULL)
32 herror_msg_and_die("%s", name);
33
34 return retval;
35}
diff --git a/nc.c b/nc.c
index b58bd6a12..5335872e5 100644
--- a/nc.c
+++ b/nc.c
@@ -91,8 +91,7 @@ int nc_main(int argc, char **argv)
91 close(sfd); 91 close(sfd);
92 sfd = tmpfd; 92 sfd = tmpfd;
93 } else { 93 } else {
94 if ((hostinfo = gethostbyname(argv[optind])) == NULL) 94 hostinfo = xgethostbyname(argv[optind]);
95 error_msg_and_die("cannot resolve %s\n", argv[optind]);
96 95
97 address.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list; 96 address.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list;
98 address.sin_port = htons(atoi(argv[optind+1])); 97 address.sin_port = htons(atoi(argv[optind+1]));
diff --git a/networking/hostname.c b/networking/hostname.c
index f4118ea36..75e4d2e57 100644
--- a/networking/hostname.c
+++ b/networking/hostname.c
@@ -1,6 +1,6 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/* 2/*
3 * $Id: hostname.c,v 1.27 2001/05/16 14:21:09 kraai Exp $ 3 * $Id: hostname.c,v 1.28 2001/05/16 15:40:48 kraai Exp $
4 * Mini hostname implementation for busybox 4 * Mini hostname implementation for busybox
5 * 5 *
6 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> 6 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@@ -117,11 +117,7 @@ int hostname_main(int argc, char **argv)
117 s = strchr(buf, '.'); 117 s = strchr(buf, '.');
118 puts(s ? s + 1 : ""); 118 puts(s ? s + 1 : "");
119 } else if (opt_ip) { 119 } else if (opt_ip) {
120 h = gethostbyname(buf); 120 h = xgethostbyname(buf);
121 if (!h) {
122 printf("Host not found\n");
123 exit(1);
124 }
125 puts(inet_ntoa(*(struct in_addr *) (h->h_addr))); 121 puts(inet_ntoa(*(struct in_addr *) (h->h_addr)));
126 } else { 122 } else {
127 puts(buf); 123 puts(buf);
diff --git a/networking/nc.c b/networking/nc.c
index b58bd6a12..5335872e5 100644
--- a/networking/nc.c
+++ b/networking/nc.c
@@ -91,8 +91,7 @@ int nc_main(int argc, char **argv)
91 close(sfd); 91 close(sfd);
92 sfd = tmpfd; 92 sfd = tmpfd;
93 } else { 93 } else {
94 if ((hostinfo = gethostbyname(argv[optind])) == NULL) 94 hostinfo = xgethostbyname(argv[optind]);
95 error_msg_and_die("cannot resolve %s\n", argv[optind]);
96 95
97 address.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list; 96 address.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list;
98 address.sin_port = htons(atoi(argv[optind+1])); 97 address.sin_port = htons(atoi(argv[optind+1]));
diff --git a/networking/ping.c b/networking/ping.c
index 8b82dcaac..0967999a9 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -1,6 +1,6 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/* 2/*
3 * $Id: ping.c,v 1.40 2001/04/09 23:52:18 andersen Exp $ 3 * $Id: ping.c,v 1.41 2001/05/16 15:40:48 kraai Exp $
4 * Mini ping implementation for busybox 4 * Mini ping implementation for busybox
5 * 5 *
6 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> 6 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@@ -200,10 +200,7 @@ static void ping(const char *host)
200 memset(&pingaddr, 0, sizeof(struct sockaddr_in)); 200 memset(&pingaddr, 0, sizeof(struct sockaddr_in));
201 201
202 pingaddr.sin_family = AF_INET; 202 pingaddr.sin_family = AF_INET;
203 if (!(h = gethostbyname(host))) { 203 h = xgethostbyname(host);
204 error_msg("unknown host %s", host);
205 exit(1);
206 }
207 memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr)); 204 memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
208 hostname = h->h_name; 205 hostname = h->h_name;
209 206
@@ -446,15 +443,9 @@ static void ping(const char *host)
446 memset(&pingaddr, 0, sizeof(struct sockaddr_in)); 443 memset(&pingaddr, 0, sizeof(struct sockaddr_in));
447 444
448 pingaddr.sin_family = AF_INET; 445 pingaddr.sin_family = AF_INET;
449 if (!(h = gethostbyname(host))) { 446 h = gethostbyname(host);
450 error_msg("unknown host %s", host); 447 if (h->h_addrtype != AF_INET)
451 exit(1); 448 error_msg_and_die("unknown address type; only AF_INET is currently supported.");
452 }
453
454 if (h->h_addrtype != AF_INET) {
455 error_msg("unknown address type; only AF_INET is currently supported.");
456 exit(1);
457 }
458 449
459 pingaddr.sin_family = AF_INET; /* h->h_addrtype */ 450 pingaddr.sin_family = AF_INET; /* h->h_addrtype */
460 memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr)); 451 memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
diff --git a/networking/telnet.c b/networking/telnet.c
index 207732b72..2587193e2 100644
--- a/networking/telnet.c
+++ b/networking/telnet.c
@@ -644,18 +644,15 @@ static int getport(char * p)
644static struct in_addr getserver(char * host) 644static struct in_addr getserver(char * host)
645{ 645{
646 struct in_addr addr; 646 struct in_addr addr;
647 647
648 struct hostent * he; 648 struct hostent * he;
649 if ((he = gethostbyname(host)) == NULL) 649 he = xgethostbyname(host);
650 {
651 error_msg_and_die("%s: Unknown host", host);
652 }
653 memcpy(&addr, he->h_addr, sizeof addr); 650 memcpy(&addr, he->h_addr, sizeof addr);
654 651
655 TRACE(1, ("addr: %s\n", inet_ntoa(addr))); 652 TRACE(1, ("addr: %s\n", inet_ntoa(addr)));
656 653
657 return addr; 654 return addr;
658} 655}
659 656
660static int create_socket() 657static int create_socket()
661{ 658{
diff --git a/networking/tftp.c b/networking/tftp.c
index 466851c1b..bb75c88ec 100644
--- a/networking/tftp.c
+++ b/networking/tftp.c
@@ -390,15 +390,10 @@ int tftp_main(int argc, char **argv)
390 s = xstrdup(serverstr); 390 s = xstrdup(serverstr);
391 s[cp - serverstr] = '\0'; 391 s[cp - serverstr] = '\0';
392 392
393 if ((host = gethostbyname(s))) { 393 host = xgethostbyname(s);
394 bad = 0;
395 }
396 394
397 free(s); 395 free(s);
398 } 396 }
399 if (bad) {
400 error_msg_and_die("bad \"server:file\" combination");
401 }
402 397
403 if (BB_TFTP_DEBUG) { 398 if (BB_TFTP_DEBUG) {
404 printf("using server \"%s\", serverfile \"%s\"," 399 printf("using server \"%s\", serverfile \"%s\","
diff --git a/networking/wget.c b/networking/wget.c
index 5fa918a19..6fd170d4d 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -556,8 +556,7 @@ FILE *open_socket(char *host, int port)
556 556
557 memset(&s_in, 0, sizeof(s_in)); 557 memset(&s_in, 0, sizeof(s_in));
558 s_in.sin_family = AF_INET; 558 s_in.sin_family = AF_INET;
559 if ((hp = (struct hostent *) gethostbyname(host)) == NULL) 559 hp = xgethostbyname(host);
560 error_msg_and_die("cannot resolve %s", host);
561 memcpy(&s_in.sin_addr, hp->h_addr_list[0], hp->h_length); 560 memcpy(&s_in.sin_addr, hp->h_addr_list[0], hp->h_length);
562 s_in.sin_port = htons(port); 561 s_in.sin_port = htons(port);
563 562
@@ -813,7 +812,7 @@ progressmeter(int flag)
813 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 812 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
814 * SUCH DAMAGE. 813 * SUCH DAMAGE.
815 * 814 *
816 * $Id: wget.c,v 1.40 2001/05/15 20:11:49 andersen Exp $ 815 * $Id: wget.c,v 1.41 2001/05/16 15:40:48 kraai Exp $
817 */ 816 */
818 817
819 818
diff --git a/nfsmount.c b/nfsmount.c
index a62df3272..90cf9fb1b 100644
--- a/nfsmount.c
+++ b/nfsmount.c
@@ -335,7 +335,7 @@ int nfsmount(const char *spec, const char *node, int *flags,
335#endif 335#endif
336 { 336 {
337 if ((hp = gethostbyname(hostname)) == NULL) { 337 if ((hp = gethostbyname(hostname)) == NULL) {
338 error_msg("can't get address for %s", hostname); 338 herror_msg("%s", hostname);
339 goto fail; 339 goto fail;
340 } else { 340 } else {
341 if (hp->h_length > sizeof(struct in_addr)) { 341 if (hp->h_length > sizeof(struct in_addr)) {
@@ -580,7 +580,7 @@ int nfsmount(const char *spec, const char *node, int *flags,
580 mount_server_addr.sin_addr.s_addr = inet_addr(hostname); 580 mount_server_addr.sin_addr.s_addr = inet_addr(hostname);
581 } else { 581 } else {
582 if ((hp = gethostbyname(mounthost)) == NULL) { 582 if ((hp = gethostbyname(mounthost)) == NULL) {
583 error_msg("can't get address for %s", hostname); 583 herror_msg("%s", mounthost);
584 goto fail; 584 goto fail;
585 } else { 585 } else {
586 if (hp->h_length > sizeof(struct in_addr)) { 586 if (hp->h_length > sizeof(struct in_addr)) {
diff --git a/ping.c b/ping.c
index 8b82dcaac..0967999a9 100644
--- a/ping.c
+++ b/ping.c
@@ -1,6 +1,6 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/* 2/*
3 * $Id: ping.c,v 1.40 2001/04/09 23:52:18 andersen Exp $ 3 * $Id: ping.c,v 1.41 2001/05/16 15:40:48 kraai Exp $
4 * Mini ping implementation for busybox 4 * Mini ping implementation for busybox
5 * 5 *
6 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> 6 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@@ -200,10 +200,7 @@ static void ping(const char *host)
200 memset(&pingaddr, 0, sizeof(struct sockaddr_in)); 200 memset(&pingaddr, 0, sizeof(struct sockaddr_in));
201 201
202 pingaddr.sin_family = AF_INET; 202 pingaddr.sin_family = AF_INET;
203 if (!(h = gethostbyname(host))) { 203 h = xgethostbyname(host);
204 error_msg("unknown host %s", host);
205 exit(1);
206 }
207 memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr)); 204 memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
208 hostname = h->h_name; 205 hostname = h->h_name;
209 206
@@ -446,15 +443,9 @@ static void ping(const char *host)
446 memset(&pingaddr, 0, sizeof(struct sockaddr_in)); 443 memset(&pingaddr, 0, sizeof(struct sockaddr_in));
447 444
448 pingaddr.sin_family = AF_INET; 445 pingaddr.sin_family = AF_INET;
449 if (!(h = gethostbyname(host))) { 446 h = gethostbyname(host);
450 error_msg("unknown host %s", host); 447 if (h->h_addrtype != AF_INET)
451 exit(1); 448 error_msg_and_die("unknown address type; only AF_INET is currently supported.");
452 }
453
454 if (h->h_addrtype != AF_INET) {
455 error_msg("unknown address type; only AF_INET is currently supported.");
456 exit(1);
457 }
458 449
459 pingaddr.sin_family = AF_INET; /* h->h_addrtype */ 450 pingaddr.sin_family = AF_INET; /* h->h_addrtype */
460 memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr)); 451 memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
diff --git a/rdate.c b/rdate.c
index ead1e7c7d..8deb35d14 100644
--- a/rdate.c
+++ b/rdate.c
@@ -45,8 +45,7 @@ static time_t askremotedate(const char *host)
45 unsigned long int nett, localt; 45 unsigned long int nett, localt;
46 int fd; 46 int fd;
47 47
48 if (!(h = gethostbyname(host))) /* get the IP addr */ 48 h = xgethostbyname(host); /* get the IP addr */
49 perror_msg_and_die("%s", host);
50 49
51 if ((tserv = getservbyname("time", "tcp")) == NULL) /* find port # */ 50 if ((tserv = getservbyname("time", "tcp")) == NULL) /* find port # */
52 perror_msg_and_die("%s", "time"); 51 perror_msg_and_die("%s", "time");
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index 9c7375852..6be51d7dc 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -450,11 +450,7 @@ static void init_RemoteLog (void){
450 error_msg_and_die("syslogd: cannot create socket"); 450 error_msg_and_die("syslogd: cannot create socket");
451 } 451 }
452 452
453 hostinfo = (struct hostent *) gethostbyname(RemoteHost); 453 hostinfo = xgethostbyname(RemoteHost);
454
455 if (!hostinfo) {
456 error_msg_and_die("syslogd: cannot resolve remote host name [%s]", RemoteHost);
457 }
458 454
459 remoteaddr.sin_family = AF_INET; 455 remoteaddr.sin_family = AF_INET;
460 remoteaddr.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list; 456 remoteaddr.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list;
diff --git a/syslogd.c b/syslogd.c
index 9c7375852..6be51d7dc 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -450,11 +450,7 @@ static void init_RemoteLog (void){
450 error_msg_and_die("syslogd: cannot create socket"); 450 error_msg_and_die("syslogd: cannot create socket");
451 } 451 }
452 452
453 hostinfo = (struct hostent *) gethostbyname(RemoteHost); 453 hostinfo = xgethostbyname(RemoteHost);
454
455 if (!hostinfo) {
456 error_msg_and_die("syslogd: cannot resolve remote host name [%s]", RemoteHost);
457 }
458 454
459 remoteaddr.sin_family = AF_INET; 455 remoteaddr.sin_family = AF_INET;
460 remoteaddr.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list; 456 remoteaddr.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list;
diff --git a/telnet.c b/telnet.c
index 207732b72..2587193e2 100644
--- a/telnet.c
+++ b/telnet.c
@@ -644,18 +644,15 @@ static int getport(char * p)
644static struct in_addr getserver(char * host) 644static struct in_addr getserver(char * host)
645{ 645{
646 struct in_addr addr; 646 struct in_addr addr;
647 647
648 struct hostent * he; 648 struct hostent * he;
649 if ((he = gethostbyname(host)) == NULL) 649 he = xgethostbyname(host);
650 {
651 error_msg_and_die("%s: Unknown host", host);
652 }
653 memcpy(&addr, he->h_addr, sizeof addr); 650 memcpy(&addr, he->h_addr, sizeof addr);
654 651
655 TRACE(1, ("addr: %s\n", inet_ntoa(addr))); 652 TRACE(1, ("addr: %s\n", inet_ntoa(addr)));
656 653
657 return addr; 654 return addr;
658} 655}
659 656
660static int create_socket() 657static int create_socket()
661{ 658{
diff --git a/tftp.c b/tftp.c
index 466851c1b..bb75c88ec 100644
--- a/tftp.c
+++ b/tftp.c
@@ -390,15 +390,10 @@ int tftp_main(int argc, char **argv)
390 s = xstrdup(serverstr); 390 s = xstrdup(serverstr);
391 s[cp - serverstr] = '\0'; 391 s[cp - serverstr] = '\0';
392 392
393 if ((host = gethostbyname(s))) { 393 host = xgethostbyname(s);
394 bad = 0;
395 }
396 394
397 free(s); 395 free(s);
398 } 396 }
399 if (bad) {
400 error_msg_and_die("bad \"server:file\" combination");
401 }
402 397
403 if (BB_TFTP_DEBUG) { 398 if (BB_TFTP_DEBUG) {
404 printf("using server \"%s\", serverfile \"%s\"," 399 printf("using server \"%s\", serverfile \"%s\","
diff --git a/util-linux/nfsmount.c b/util-linux/nfsmount.c
index a62df3272..90cf9fb1b 100644
--- a/util-linux/nfsmount.c
+++ b/util-linux/nfsmount.c
@@ -335,7 +335,7 @@ int nfsmount(const char *spec, const char *node, int *flags,
335#endif 335#endif
336 { 336 {
337 if ((hp = gethostbyname(hostname)) == NULL) { 337 if ((hp = gethostbyname(hostname)) == NULL) {
338 error_msg("can't get address for %s", hostname); 338 herror_msg("%s", hostname);
339 goto fail; 339 goto fail;
340 } else { 340 } else {
341 if (hp->h_length > sizeof(struct in_addr)) { 341 if (hp->h_length > sizeof(struct in_addr)) {
@@ -580,7 +580,7 @@ int nfsmount(const char *spec, const char *node, int *flags,
580 mount_server_addr.sin_addr.s_addr = inet_addr(hostname); 580 mount_server_addr.sin_addr.s_addr = inet_addr(hostname);
581 } else { 581 } else {
582 if ((hp = gethostbyname(mounthost)) == NULL) { 582 if ((hp = gethostbyname(mounthost)) == NULL) {
583 error_msg("can't get address for %s", hostname); 583 herror_msg("%s", mounthost);
584 goto fail; 584 goto fail;
585 } else { 585 } else {
586 if (hp->h_length > sizeof(struct in_addr)) { 586 if (hp->h_length > sizeof(struct in_addr)) {
diff --git a/util-linux/rdate.c b/util-linux/rdate.c
index ead1e7c7d..8deb35d14 100644
--- a/util-linux/rdate.c
+++ b/util-linux/rdate.c
@@ -45,8 +45,7 @@ static time_t askremotedate(const char *host)
45 unsigned long int nett, localt; 45 unsigned long int nett, localt;
46 int fd; 46 int fd;
47 47
48 if (!(h = gethostbyname(host))) /* get the IP addr */ 48 h = xgethostbyname(host); /* get the IP addr */
49 perror_msg_and_die("%s", host);
50 49
51 if ((tserv = getservbyname("time", "tcp")) == NULL) /* find port # */ 50 if ((tserv = getservbyname("time", "tcp")) == NULL) /* find port # */
52 perror_msg_and_die("%s", "time"); 51 perror_msg_and_die("%s", "time");
diff --git a/wget.c b/wget.c
index 5fa918a19..6fd170d4d 100644
--- a/wget.c
+++ b/wget.c
@@ -556,8 +556,7 @@ FILE *open_socket(char *host, int port)
556 556
557 memset(&s_in, 0, sizeof(s_in)); 557 memset(&s_in, 0, sizeof(s_in));
558 s_in.sin_family = AF_INET; 558 s_in.sin_family = AF_INET;
559 if ((hp = (struct hostent *) gethostbyname(host)) == NULL) 559 hp = xgethostbyname(host);
560 error_msg_and_die("cannot resolve %s", host);
561 memcpy(&s_in.sin_addr, hp->h_addr_list[0], hp->h_length); 560 memcpy(&s_in.sin_addr, hp->h_addr_list[0], hp->h_length);
562 s_in.sin_port = htons(port); 561 s_in.sin_port = htons(port);
563 562
@@ -813,7 +812,7 @@ progressmeter(int flag)
813 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 812 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
814 * SUCH DAMAGE. 813 * SUCH DAMAGE.
815 * 814 *
816 * $Id: wget.c,v 1.40 2001/05/15 20:11:49 andersen Exp $ 815 * $Id: wget.c,v 1.41 2001/05/16 15:40:48 kraai Exp $
817 */ 816 */
818 817
819 818