diff options
author | Matt Kraai | 2001-05-16 15:40:51 +0000 |
---|---|---|
committer | Matt Kraai | 2001-05-16 15:40:51 +0000 |
commit | c55b8d41c15640fa1637f919b3f6eca6e781047a (patch) | |
tree | 03c1fca61c1b577b7c527d2b8482c5b7f6972bcd /networking | |
parent | 59df6f73988b103f0dcfffeaec10642527336c5e (diff) | |
download | busybox-c55b8d41c15640fa1637f919b3f6eca6e781047a.zip busybox-c55b8d41c15640fa1637f919b3f6eca6e781047a.tar.gz |
Add xgethostbyname and herror_msg* functions.
Diffstat (limited to 'networking')
-rw-r--r-- | networking/hostname.c | 8 | ||||
-rw-r--r-- | networking/nc.c | 3 | ||||
-rw-r--r-- | networking/ping.c | 19 | ||||
-rw-r--r-- | networking/telnet.c | 11 | ||||
-rw-r--r-- | networking/tftp.c | 7 | ||||
-rw-r--r-- | networking/wget.c | 5 |
6 files changed, 15 insertions, 38 deletions
diff --git a/networking/hostname.c b/networking/hostname.c index f4118ea..75e4d2e 100644 --- a/networking/hostname.c +++ b/networking/hostname.c @@ -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); diff --git a/networking/nc.c b/networking/nc.c index b58bd6a..5335872 100644 --- a/networking/nc.c +++ b/networking/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])); diff --git a/networking/ping.c b/networking/ping.c index 8b82dca..0967999 100644 --- a/networking/ping.c +++ b/networking/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/networking/telnet.c b/networking/telnet.c index 207732b..2587193 100644 --- a/networking/telnet.c +++ b/networking/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/networking/tftp.c b/networking/tftp.c index 466851c..bb75c88 100644 --- a/networking/tftp.c +++ b/networking/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\"," diff --git a/networking/wget.c b/networking/wget.c index 5fa918a..6fd170d 100644 --- a/networking/wget.c +++ b/networking/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 $ */ |