diff options
author | gpalmer <gpalmer@FreeBSD.org> | 1995-05-24 11:19:11 +0000 |
---|---|---|
committer | gpalmer <gpalmer@FreeBSD.org> | 1995-05-24 11:19:11 +0000 |
commit | 50dca2ce42c02340a5499e4c514d10775dc1a2f9 (patch) | |
tree | bbf3e2f073e839c469f7c39b03ece7724ce8e6d0 /release/sysinstall/ftp.c | |
parent | 4f1713431729b21fea46062a8e124fd15ef17498 (diff) | |
download | FreeBSD-src-50dca2ce42c02340a5499e4c514d10775dc1a2f9.zip FreeBSD-src-50dca2ce42c02340a5499e4c514d10775dc1a2f9.tar.gz |
Makefile:
Add testftp: target
ftp.c:
add more debugging output and fix a few more problems
media_strategy:
make the ftp system actually do something resembling common sense.
it now works after a fashion, although it soon falls over for some
reason.
Diffstat (limited to 'release/sysinstall/ftp.c')
-rw-r--r-- | release/sysinstall/ftp.c | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/release/sysinstall/ftp.c b/release/sysinstall/ftp.c index 278afa1..d21e34d 100644 --- a/release/sysinstall/ftp.c +++ b/release/sysinstall/ftp.c @@ -6,7 +6,7 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id$ + * $Id: ftp.c,v 1.3 1995/05/24 09:00:19 jkh Exp $ * */ @@ -23,6 +23,10 @@ #include <errno.h> #include <ctype.h> #include "ftp.h" +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> + #ifndef STANDALONE_FTP #include "sysinstall.h" #endif /*STANDALONE_FTP*/ @@ -66,7 +70,7 @@ get_a_line(FTP_t ftp) if (!i) continue; buf[i] = '\0'; - debug(ftp,"LIBFTP: received <%s>\n",buf); + debug(ftp, "LIBFTP: received <%s>\n",buf); return buf; } i++; @@ -104,7 +108,7 @@ get_a_number(FTP_t ftp, char **q) static int botch(FTP_t ftp, char *func, char *state) { - debug(ftp,"LIBFTP: Botch: %s called outside state %s\n",func,state); + debug(ftp, "LIBFTP: Botch: %s called outside state %s\n",func,state); writes(ftp->fd_ctrl,"QUIT\r\n"); close(ftp->fd_ctrl); ftp->fd_ctrl = -1; close(ftp->fd_xfer); ftp->fd_xfer = -1; @@ -123,7 +127,7 @@ cmd(FTP_t ftp, const char *fmt, ...) (void) vsnprintf(p, sizeof p, fmt, ap); va_end(ap); - debug(ftp,"LIBFTP: send <%s>\n",p); + debug(ftp, "LIBFTP: send <%s>\n",p); strcat(p,"\r\n"); if (writes(ftp->fd_ctrl,p)) return -1; @@ -162,7 +166,6 @@ FtpOpen(FTP_t ftp, char *host, char *user, char *passwd) struct sockaddr_in sin; int s; unsigned long temp; - extern unsigned long inet_addr(char *); int i; if (ftp->state != init) @@ -174,20 +177,20 @@ FtpOpen(FTP_t ftp, char *host, char *user, char *passwd) if (!passwd) passwd = "??@??(FreeBSD:libftp)"; /* XXX */ - debug(ftp,"FtpOpen(ftp, %s, %s, %s)\n", host, user, passwd); + debug(ftp, "FtpOpen(ftp, %s, %s, %s)\n", host, user, passwd); temp = inet_addr(host); if (temp != INADDR_NONE) { - debug(ftp,"Using dotted IP address `%s'\n", host); + debug(ftp, "Using dotted IP address `%s'\n", host); ftp->addrtype = sin.sin_family = AF_INET; sin.sin_addr.s_addr = temp; } else { - debug(ftp,"Trying to resolve `%s'\n", host); + debug(ftp, "Trying to resolve `%s'\n", host); he = gethostbyname(host); if (!he) { - debug(ftp,"Lookup of `%s' failed!\n", host); + debug(ftp, "Lookup of `%s' failed!\n", host); return ENOENT; } ftp->addrtype = sin.sin_family = he->h_addrtype; @@ -198,12 +201,12 @@ FtpOpen(FTP_t ftp, char *host, char *user, char *passwd) if ((s = socket(ftp->addrtype, SOCK_STREAM, 0)) < 0) { - debug("Socket open failed: %s (%i)\n", strerror(errno), errno); + debug(ftp, "Socket open failed: %s (%i)\n", strerror(errno), errno); return s; } if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { - debug("Connection failed: %s (%i)\n", strerror(errno), errno); + debug(ftp,"Connection failed: %s (%i)\n", strerror(errno), errno); (void)close(s); return -1; } @@ -262,9 +265,10 @@ FtpGet(FTP_t ftp, char *file) } else { return -1; } - if(ftp->passive) { + if (ftp->passive) { + debug(ftp, "LIBFTP: send <%s>\n","PASV"); if (writes(ftp->fd_ctrl,"PASV\r\n")) - return -1; + return -1;*/ i = get_a_number(ftp,&q); if (i != 227) return -1; @@ -281,12 +285,15 @@ FtpGet(FTP_t ftp, char *file) sin.sin_family = ftp->addrtype; bcopy(addr, (char *)&sin.sin_addr, 4); bcopy(addr+4, (char *)&sin.sin_port, 2); + debug(ftp, "Opening active socket to %s : %u\n", inet_ntoa(sin.sin_addr), htons(sin.sin_port)); + if ((s = socket(ftp->addrtype, SOCK_STREAM, 0)) < 0) return -1; - + + debug(ftp, "Connecting to %s:%u\n", inet_ntoa(sin.sin_addr), htons(sin.sin_port)); if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { (void)close(s); - debug(ftp,"connect, errno = %d\n",errno); + debug(ftp, "connect: %s (%d)\n", strerror(errno), errno); return -1; } @@ -328,9 +335,9 @@ main(int argc, char **argv) if (i) err(1,"FtpOpen(%d)",i); FtpBinary(ftp,1); FtpPassive(ftp,1); - FtpChdir(ftp,"/pub"); + FtpChdir(ftp,"/"); FtpChdir(ftp,"CTM"); - i = FtpGet(ftp,"README_CTM_MOVED"); + i = FtpGet(ftp,"README"); while(1 == read(i,&c,1)) putchar(c); FtpEOF(ftp); |