Add xgethostbyname and herror_msg* functions.

This commit is contained in:
Matt Kraai
2001-05-16 15:40:51 +00:00
parent 59df6f7398
commit c55b8d41c1
25 changed files with 236 additions and 96 deletions

View 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);

View 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]));

View 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));

View 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()
{

View 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\","

View 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 $
*/