summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2000-05-03 19:50:42 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2000-05-03 19:50:42 +0000
commitaee84542907987b7d5f11e05b731a4e9b597e42c (patch)
tree89e4a8dc7c900e2661c1bf42819658ce4590c531
parent4839e8a70c1211b97f2304c09e56a754077d6629 (diff)
if no /etc/services file, use defaults. found by millert, fixed by itojun
-rw-r--r--usr.bin/ftp/fetch.c14
-rw-r--r--usr.bin/ftp/ftp.c21
2 files changed, 31 insertions, 4 deletions
diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c
index 66eb3567b6c..164678e867c 100644
--- a/usr.bin/ftp/fetch.c
+++ b/usr.bin/ftp/fetch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fetch.c,v 1.29 2000/05/02 00:54:53 itojun Exp $ */
+/* $OpenBSD: fetch.c,v 1.30 2000/05/03 19:50:41 deraadt Exp $ */
/* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */
/*-
@@ -38,7 +38,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: fetch.c,v 1.29 2000/05/02 00:54:53 itojun Exp $";
+static char rcsid[] = "$OpenBSD: fetch.c,v 1.30 2000/05/03 19:50:41 deraadt Exp $";
#endif /* not lint */
/*
@@ -290,6 +290,16 @@ url_get(origline, proxyenv, outfile)
hints.ai_socktype = SOCK_STREAM;
port = portnum ? portnum : httpport;
error = getaddrinfo(host, port, &hints, &res0);
+ if (error == EAI_SERVICE && port == httpport) {
+ /*
+ * If the services file is corrupt/missing, fall back
+ * on our hard-coded defines.
+ */
+ char pbuf[NI_MAXSERV];
+
+ snprintf(pbuf, sizeof(pbuf), "%d", HTTP_PORT);
+ error = getaddrinfo(host, pbuf, &hints, &res0);
+ }
if (error) {
warnx("%s: %s", gai_strerror(error), host);
goto cleanup_url_get;
diff --git a/usr.bin/ftp/ftp.c b/usr.bin/ftp/ftp.c
index b4f81b67d92..ff7d41394d4 100644
--- a/usr.bin/ftp/ftp.c
+++ b/usr.bin/ftp/ftp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ftp.c,v 1.34 1999/12/08 12:57:06 itojun Exp $ */
+/* $OpenBSD: ftp.c,v 1.35 2000/05/03 19:50:41 deraadt Exp $ */
/* $NetBSD: ftp.c,v 1.27 1997/08/18 10:20:23 lukem Exp $ */
/*
@@ -67,7 +67,7 @@
#if 0
static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94";
#else
-static char rcsid[] = "$OpenBSD: ftp.c,v 1.34 1999/12/08 12:57:06 itojun Exp $";
+static char rcsid[] = "$OpenBSD: ftp.c,v 1.35 2000/05/03 19:50:41 deraadt Exp $";
#endif
#endif /* not lint */
@@ -145,6 +145,23 @@ hookup(host, port)
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = 0;
error = getaddrinfo(host, port, &hints, &res0);
+ if (error == EAI_SERVICE) {
+ /*
+ * If the services file is corrupt/missing, fall back
+ * on our hard-coded defines.
+ */
+ char pbuf[NI_MAXSERV];
+
+ pbuf[0] = '\0';
+ if (strcmp(port, "ftp") == 0)
+ snprintf(pbuf, sizeof(pbuf), "%d", FTP_PORT);
+ else if (strcmp(port, "ftpgate") == 0)
+ snprintf(pbuf, sizeof(pbuf), "%d", GATE_PORT);
+ else if (strcmp(port, "http") == 0)
+ snprintf(pbuf, sizeof(pbuf), "%d", HTTP_PORT);
+ if (pbuf[0])
+ error = getaddrinfo(host, pbuf, &hints, &res0);
+ }
if (error) {
warn(gai_strerror(error));
code = -1;