2 * Copyright (c) 1985, 1989, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 static char sccsid[] = "@(#)ftp.c 8.4 (Berkeley) 4/6/94";
38 #include <sys/param.h>
40 #include <sys/ioctl.h>
41 #include <sys/socket.h>
45 #include <netinet/in.h>
46 #include <netinet/in_systm.h>
47 #include <netinet/ip.h>
48 #include <arpa/inet.h>
50 #include <arpa/telnet.h>
69 struct sockaddr_in hisctladdr;
70 struct sockaddr_in data_addr;
76 struct sockaddr_in myctladdr;
77 off_t restart_point = 0;
87 struct hostent *hp = 0;
89 static char hostnamebuf[80];
91 memset((char *)&hisctladdr, 0, sizeof (hisctladdr));
92 hisctladdr.sin_addr.s_addr = inet_addr(host);
93 if (hisctladdr.sin_addr.s_addr != -1) {
94 hisctladdr.sin_family = AF_INET;
95 (void) strncpy(hostnamebuf, host, sizeof(hostnamebuf));
97 hp = gethostbyname(host);
99 warnx("%s: %s", host, hstrerror(h_errno));
103 hisctladdr.sin_family = hp->h_addrtype;
104 memmove((caddr_t)&hisctladdr.sin_addr,
105 hp->h_addr_list[0], hp->h_length);
106 (void) strncpy(hostnamebuf, hp->h_name, sizeof(hostnamebuf));
108 hostname = hostnamebuf;
109 s = socket(hisctladdr.sin_family, SOCK_STREAM, 0);
115 hisctladdr.sin_port = port;
116 while (connect(s, (struct sockaddr *)&hisctladdr, sizeof (hisctladdr)) < 0) {
117 if (hp && hp->h_addr_list[1]) {
121 ia = inet_ntoa(hisctladdr.sin_addr);
123 warn("connect to address %s", ia);
125 memmove((caddr_t)&hisctladdr.sin_addr,
126 hp->h_addr_list[0], hp->h_length);
127 fprintf(stdout, "Trying %s...\n",
128 inet_ntoa(hisctladdr.sin_addr));
130 s = socket(hisctladdr.sin_family, SOCK_STREAM, 0);
142 len = sizeof (myctladdr);
143 if (getsockname(s, (struct sockaddr *)&myctladdr, &len) < 0) {
149 tos = IPTOS_LOWDELAY;
150 if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(int)) < 0)
151 warn("setsockopt TOS (ignored)");
153 cin = fdopen(s, "r");
154 cout = fdopen(s, "w");
155 if (cin == NULL || cout == NULL) {
156 warnx("fdopen failed.");
165 printf("Connected to %s.\n", hostname);
166 if (getreply(0) > 2) { /* read startup message from server */
178 if (setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on))
183 #endif /* SO_OOBINLINE */
196 char *user, *pass, *acct;
199 user = pass = acct = 0;
200 if (ruserpass(host, &user, &pass, &acct) < 0) {
204 while (user == NULL) {
205 char *myname = getlogin();
207 if (myname == NULL) {
208 struct passwd *pp = getpwuid(getuid());
211 myname = pp->pw_name;
214 printf("Name (%s:%s): ", host, myname);
216 printf("Name (%s): ", host);
217 (void) fgets(tmp, sizeof(tmp) - 1, stdin);
218 tmp[strlen(tmp) - 1] = '\0';
224 n = command("USER %s", user);
227 pass = getpass("Password:");
228 n = command("PASS %s", pass);
232 acct = getpass("Account:");
233 n = command("ACCT %s", acct);
236 warnx("Login failed.");
239 if (!aflag && acct != NULL)
240 (void) command("ACCT %s", acct);
243 for (n = 0; n < macnum; ++n) {
244 if (!strcmp("init", macros[n].mac_name)) {
245 (void) strcpy(line, "$init");
247 domacro(margc, margv);
259 (void) fflush(stdout);
279 fmt = va_arg(ap, char *);
280 if (strncmp("PASS ", fmt, 5) == 0)
283 vfprintf(stdout, fmt, ap);
286 (void) fflush(stdout);
289 warn("No control connection for command");
293 oldintr = signal(SIGINT, cmdabort);
295 fmt = va_arg(ap, char *);
296 vfprintf(cout, fmt, ap);
298 fprintf(cout, "\r\n");
301 r = getreply(!strcmp(fmt, "QUIT"));
302 if (abrtflag && oldintr != SIG_IGN)
304 (void) signal(SIGINT, oldintr);
308 char reply_string[BUFSIZ]; /* last line of previous reply */
316 int originalcode = 0, continuation = 0;
319 char *cp, *pt = pasv;
321 oldintr = signal(SIGINT, cmdabort);
325 while ((c = getc(cin)) != '\n') {
326 if (c == IAC) { /* handle telnet commands */
327 switch (c = getc(cin)) {
331 fprintf(cout, "%c%c%c", IAC, DONT, c);
337 fprintf(cout, "%c%c%c", IAC, WONT, c);
348 (void) signal(SIGINT,oldintr);
354 printf("421 Service not available, remote server has closed connection\n");
355 (void) fflush(stdout);
360 if (c != '\r' && (verbose > 0 ||
361 (verbose > -1 && n == '5' && dig > 4))) {
363 (dig == 1 || dig == 5 && verbose == 0))
364 printf("%s:",hostname);
367 if (dig < 4 && isdigit(c))
368 code = code * 10 + (c - '0');
369 if (!pflag && code == 227)
371 if (dig > 4 && pflag == 1 && isdigit(c))
374 if (c != '\r' && c != ')')
381 if (dig == 4 && c == '-') {
388 if (cp < &reply_string[sizeof(reply_string) - 1])
391 if (verbose > 0 || verbose > -1 && n == '5') {
393 (void) fflush (stdout);
395 if (continuation && code != originalcode) {
396 if (originalcode == 0)
403 (void) signal(SIGINT,oldintr);
404 if (code == 421 || originalcode == 421)
406 if (abrtflag && oldintr != cmdabort && oldintr != SIG_IGN)
419 t.tv_sec = (long) sec;
421 return (select(32, mask, (struct fd_set *) 0, (struct fd_set *) 0, &t));
432 printf("\nsend aborted\nwaiting for remote to finish abort\n");
433 (void) fflush(stdout);
434 longjmp(sendabort, 1);
437 #define HASHBYTES 1024
440 sendrequest(cmd, local, remote, printnames)
441 char *cmd, *local, *remote;
445 struct timeval start, stop;
447 FILE *fin, *dout = 0, *popen();
448 int (*closefunc) __P((FILE *));
449 sig_t oldintr, oldintp;
450 long bytes = 0, hashbytes = HASHBYTES;
451 char *lmode, buf[BUFSIZ], *bufp;
453 if (verbose && printnames) {
454 if (local && *local != '-')
455 printf("local: %s ", local);
457 printf("remote: %s\n", remote);
460 proxtrans(cmd, local, remote);
469 if (setjmp(sendabort)) {
478 (void) signal(SIGINT,oldintr);
480 (void) signal(SIGPIPE,oldintp);
484 oldintr = signal(SIGINT, abortsend);
485 if (strcmp(local, "-") == 0)
487 else if (*local == '|') {
488 oldintp = signal(SIGPIPE,SIG_IGN);
489 fin = popen(local + 1, "r");
491 warn("%s", local + 1);
492 (void) signal(SIGINT, oldintr);
493 (void) signal(SIGPIPE, oldintp);
499 fin = fopen(local, "r");
501 warn("local: %s", local);
502 (void) signal(SIGINT, oldintr);
507 if (fstat(fileno(fin), &st) < 0 ||
508 (st.st_mode&S_IFMT) != S_IFREG) {
509 fprintf(stdout, "%s: not a plain file.\n", local);
510 (void) signal(SIGINT, oldintr);
517 (void) signal(SIGINT, oldintr);
519 (void) signal(SIGPIPE, oldintp);
521 if (closefunc != NULL)
525 if (setjmp(sendabort))
529 (strcmp(cmd, "STOR") == 0 || strcmp(cmd, "APPE") == 0)) {
534 rc = fseek(fin, (long) restart_point, SEEK_SET);
538 rc = lseek(fileno(fin), restart_point, SEEK_SET);
542 warn("local: %s", local);
544 if (closefunc != NULL)
548 if (command("REST %ld", (long) restart_point)
551 if (closefunc != NULL)
559 if (command("%s %s", cmd, remote) != PRELIM) {
560 (void) signal(SIGINT, oldintr);
562 (void) signal(SIGPIPE, oldintp);
563 if (closefunc != NULL)
568 if (command("%s", cmd) != PRELIM) {
569 (void) signal(SIGINT, oldintr);
571 (void) signal(SIGPIPE, oldintp);
572 if (closefunc != NULL)
576 dout = dataconn(lmode);
579 (void) gettimeofday(&start, (struct timezone *)0);
580 oldintp = signal(SIGPIPE, SIG_IGN);
586 while ((c = read(fileno(fin), buf, sizeof (buf))) > 0) {
588 for (bufp = buf; c > 0; c -= d, bufp += d)
589 if ((d = write(fileno(dout), bufp, c)) <= 0)
592 while (bytes >= hashbytes) {
594 hashbytes += HASHBYTES;
596 (void) fflush(stdout);
599 if (hash && bytes > 0) {
600 if (bytes < HASHBYTES)
602 (void) putchar('\n');
603 (void) fflush(stdout);
606 warn("local: %s", local);
615 while ((c = getc(fin)) != EOF) {
617 while (hash && (bytes >= hashbytes)) {
619 (void) fflush(stdout);
620 hashbytes += HASHBYTES;
624 (void) putc('\r', dout);
627 (void) putc(c, dout);
629 /* if (c == '\r') { */
630 /* (void) putc('\0', dout); // this violates rfc */
635 if (bytes < hashbytes)
637 (void) putchar('\n');
638 (void) fflush(stdout);
641 warn("local: %s", local);
649 (void) gettimeofday(&stop, (struct timezone *)0);
650 if (closefunc != NULL)
654 (void) signal(SIGINT, oldintr);
656 (void) signal(SIGPIPE, oldintp);
658 ptransfer("sent", bytes, &start, &stop);
661 (void) gettimeofday(&stop, (struct timezone *)0);
662 (void) signal(SIGINT, oldintr);
664 (void) signal(SIGPIPE, oldintp);
677 if (closefunc != NULL && fin != NULL)
680 ptransfer("sent", bytes, &start, &stop);
691 printf("\nreceive aborted\nwaiting for remote to finish abort\n");
692 (void) fflush(stdout);
693 longjmp(recvabort, 1);
697 recvrequest(cmd, local, remote, lmode, printnames)
698 char *cmd, *local, *remote, *lmode;
701 FILE *fout, *din = 0;
702 int (*closefunc) __P((FILE *));
703 sig_t oldintr, oldintp;
704 int c, d, is_retr, tcrflag, bare_lfs = 0;
707 long bytes = 0, hashbytes = HASHBYTES;
708 struct timeval start, stop;
711 is_retr = strcmp(cmd, "RETR") == 0;
712 if (is_retr && verbose && printnames) {
713 if (local && *local != '-')
714 printf("local: %s ", local);
716 printf("remote: %s\n", remote);
718 if (proxy && is_retr) {
719 proxtrans(cmd, local, remote);
725 tcrflag = !crflag && is_retr;
726 if (setjmp(recvabort)) {
735 (void) signal(SIGINT, oldintr);
739 oldintr = signal(SIGINT, abortrecv);
740 if (strcmp(local, "-") && *local != '|') {
741 if (access(local, 2) < 0) {
742 char *dir = strrchr(local, '/');
744 if (errno != ENOENT && errno != EACCES) {
745 warn("local: %s", local);
746 (void) signal(SIGINT, oldintr);
752 d = access(dir ? local : ".", 2);
756 warn("local: %s", local);
757 (void) signal(SIGINT, oldintr);
761 if (!runique && errno == EACCES &&
762 chmod(local, 0600) < 0) {
763 warn("local: %s", local);
764 (void) signal(SIGINT, oldintr);
765 (void) signal(SIGINT, oldintr);
769 if (runique && errno == EACCES &&
770 (local = gunique(local)) == NULL) {
771 (void) signal(SIGINT, oldintr);
776 else if (runique && (local = gunique(local)) == NULL) {
777 (void) signal(SIGINT, oldintr);
783 if (curtype != TYPE_A)
784 changetype(TYPE_A, 0);
785 } else if (curtype != type)
788 (void) signal(SIGINT, oldintr);
792 if (setjmp(recvabort))
794 if (is_retr && restart_point &&
795 command("REST %ld", (long) restart_point) != CONTINUE)
798 if (command("%s %s", cmd, remote) != PRELIM) {
799 (void) signal(SIGINT, oldintr);
803 if (command("%s", cmd) != PRELIM) {
804 (void) signal(SIGINT, oldintr);
811 if (strcmp(local, "-") == 0)
813 else if (*local == '|') {
814 oldintp = signal(SIGPIPE, SIG_IGN);
815 fout = popen(local + 1, "w");
822 fout = fopen(local, lmode);
824 warn("local: %s", local);
829 if (fstat(fileno(fout), &st) < 0 || st.st_blksize == 0)
830 st.st_blksize = BUFSIZ;
831 if (st.st_blksize > bufsize) {
834 buf = malloc((unsigned)st.st_blksize);
840 bufsize = st.st_blksize;
842 (void) gettimeofday(&start, (struct timezone *)0);
848 lseek(fileno(fout), restart_point, SEEK_SET) < 0) {
849 warn("local: %s", local);
850 if (closefunc != NULL)
855 while ((c = read(fileno(din), buf, bufsize)) > 0) {
856 if ((d = write(fileno(fout), buf, c)) != c)
860 while (bytes >= hashbytes) {
862 hashbytes += HASHBYTES;
864 (void) fflush(stdout);
867 if (hash && bytes > 0) {
868 if (bytes < HASHBYTES)
870 (void) putchar('\n');
871 (void) fflush(stdout);
880 warn("local: %s", local);
882 warnx("%s: short write", local);
890 if (fseek(fout, 0L, SEEK_SET) < 0)
893 for (i = 0; i++ < n;) {
894 if ((ch = getc(fout)) == EOF)
899 if (fseek(fout, 0L, SEEK_CUR) < 0) {
901 warn("local: %s", local);
902 if (closefunc != NULL)
907 while ((c = getc(din)) != EOF) {
911 while (hash && (bytes >= hashbytes)) {
913 (void) fflush(stdout);
914 hashbytes += HASHBYTES;
917 if ((c = getc(din)) != '\n' || tcrflag) {
920 (void) putc('\r', fout);
929 (void) putc(c, fout);
935 printf("WARNING! %d bare linefeeds received in ASCII mode\n", bare_lfs);
936 printf("File may not have transferred correctly.\n");
939 if (bytes < hashbytes)
941 (void) putchar('\n');
942 (void) fflush(stdout);
950 warn("local: %s", local);
953 if (closefunc != NULL)
955 (void) signal(SIGINT, oldintr);
957 (void) signal(SIGPIPE, oldintp);
958 (void) gettimeofday(&stop, (struct timezone *)0);
961 if (bytes > 0 && is_retr)
962 ptransfer("received", bytes, &start, &stop);
966 /* abort using RFC959 recommended IP,SYNC sequence */
968 (void) gettimeofday(&stop, (struct timezone *)0);
970 (void) signal(SIGPIPE, oldintr);
971 (void) signal(SIGINT, SIG_IGN);
974 (void) signal(SIGINT, oldintr);
984 if (closefunc != NULL && fout != NULL)
989 ptransfer("received", bytes, &start, &stop);
990 (void) signal(SIGINT, oldintr);
994 * Need to start a listen on the data channel before we send the command,
995 * otherwise the server's connect may fail.
1001 int result, len, tmpno = 0;
1005 data_addr = myctladdr;
1007 data_addr.sin_port = 0; /* let system pick one */
1010 data = socket(AF_INET, SOCK_STREAM, 0);
1018 if (setsockopt(data, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof (on)) < 0) {
1019 warn("setsockopt (reuse address)");
1022 if (bind(data, (struct sockaddr *)&data_addr, sizeof (data_addr)) < 0) {
1026 if (options & SO_DEBUG &&
1027 setsockopt(data, SOL_SOCKET, SO_DEBUG, (char *)&on, sizeof (on)) < 0)
1028 warn("setsockopt (ignored)");
1029 len = sizeof (data_addr);
1030 if (getsockname(data, (struct sockaddr *)&data_addr, &len) < 0) {
1031 warn("getsockname");
1034 if (listen(data, 1) < 0)
1037 a = (char *)&data_addr.sin_addr;
1038 p = (char *)&data_addr.sin_port;
1039 #define UC(b) (((int)b)&0xff)
1041 command("PORT %d,%d,%d,%d,%d,%d",
1042 UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]),
1043 UC(p[0]), UC(p[1]));
1044 if (result == ERROR && sendport == -1) {
1049 return (result != COMPLETE);
1054 on = IPTOS_THROUGHPUT;
1055 if (setsockopt(data, IPPROTO_IP, IP_TOS, (char *)&on, sizeof(int)) < 0)
1056 warn("setsockopt TOS (ignored)");
1060 (void) close(data), data = -1;
1070 struct sockaddr_in from;
1071 int s, fromlen = sizeof (from), tos;
1073 s = accept(data, (struct sockaddr *) &from, &fromlen);
1076 (void) close(data), data = -1;
1082 tos = IPTOS_THROUGHPUT;
1083 if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(int)) < 0)
1084 warn("setsockopt TOS (ignored)");
1086 return (fdopen(data, lmode));
1090 ptransfer(direction, bytes, t0, t1)
1093 struct timeval *t0, *t1;
1100 s = td.tv_sec + (td.tv_usec / 1000000.);
1101 #define nz(x) ((x) == 0 ? 1 : (x))
1103 printf("%ld bytes %s in %.2g seconds (%.2g Kbytes/s)\n",
1104 bytes, direction, s, bs / 1024.);
1111 struct timeval *tsum, *t0;
1114 tsum->tv_sec += t0->tv_sec;
1115 tsum->tv_usec += t0->tv_usec;
1116 if (tsum->tv_usec > 1000000)
1117 tsum->tv_sec++, tsum->tv_usec -= 1000000;
1122 tvsub(tdiff, t1, t0)
1123 struct timeval *tdiff, *t1, *t0;
1126 tdiff->tv_sec = t1->tv_sec - t0->tv_sec;
1127 tdiff->tv_usec = t1->tv_usec - t0->tv_usec;
1128 if (tdiff->tv_usec < 0)
1129 tdiff->tv_sec--, tdiff->tv_usec += 1000000;
1144 static struct comvars {
1146 char name[MAXHOSTNAMELEN];
1147 struct sockaddr_in mctl;
1148 struct sockaddr_in hctl;
1161 char mi[MAXPATHLEN];
1162 char mo[MAXPATHLEN];
1163 } proxstruct, tmpstruct;
1164 struct comvars *ip, *op;
1167 oldintr = signal(SIGINT, psabort);
1181 ip->connect = connected;
1182 connected = op->connect;
1184 (void) strncpy(ip->name, hostname, sizeof(ip->name) - 1);
1185 ip->name[strlen(ip->name)] = '\0';
1188 hostname = op->name;
1189 ip->hctl = hisctladdr;
1190 hisctladdr = op->hctl;
1191 ip->mctl = myctladdr;
1192 myctladdr = op->mctl;
1199 ip->curtpe = curtype;
1200 curtype = op->curtpe;
1203 ip->sunqe = sunique;
1204 sunique = op->sunqe;
1205 ip->runqe = runique;
1206 runique = op->runqe;
1211 (void) strncpy(ip->nti, ntin, 16);
1212 (ip->nti)[strlen(ip->nti)] = '\0';
1213 (void) strcpy(ntin, op->nti);
1214 (void) strncpy(ip->nto, ntout, 16);
1215 (ip->nto)[strlen(ip->nto)] = '\0';
1216 (void) strcpy(ntout, op->nto);
1217 ip->mapflg = mapflag;
1218 mapflag = op->mapflg;
1219 (void) strncpy(ip->mi, mapin, MAXPATHLEN - 1);
1220 (ip->mi)[strlen(ip->mi)] = '\0';
1221 (void) strcpy(mapin, op->mi);
1222 (void) strncpy(ip->mo, mapout, MAXPATHLEN - 1);
1223 (ip->mo)[strlen(ip->mo)] = '\0';
1224 (void) strcpy(mapout, op->mo);
1225 (void) signal(SIGINT, oldintr);
1237 (void) fflush(stdout);
1241 longjmp(ptabort, 1);
1245 proxtrans(cmd, local, remote)
1246 char *cmd, *local, *remote;
1249 int secndflag = 0, prox_type, nfnd;
1253 if (strcmp(cmd, "RETR"))
1256 cmd2 = runique ? "STOU" : "STOR";
1257 if ((prox_type = type) == 0) {
1258 if (unix_server && unix_proxy)
1263 if (curtype != prox_type)
1264 changetype(prox_type, 1);
1265 if (command("PASV") != COMPLETE) {
1266 printf("proxy server does not support third party transfers.\n");
1271 printf("No primary connection\n");
1276 if (curtype != prox_type)
1277 changetype(prox_type, 1);
1278 if (command("PORT %s", pasv) != COMPLETE) {
1282 if (setjmp(ptabort))
1284 oldintr = signal(SIGINT, abortpt);
1285 if (command("%s %s", cmd, remote) != PRELIM) {
1286 (void) signal(SIGINT, oldintr);
1293 if (command("%s %s", cmd2, local) != PRELIM)
1299 (void) signal(SIGINT, oldintr);
1302 printf("local: %s remote: %s\n", local, remote);
1305 (void) signal(SIGINT, SIG_IGN);
1307 if (strcmp(cmd, "RETR") && !proxy)
1309 else if (!strcmp(cmd, "RETR") && proxy)
1311 if (!cpend && !secndflag) { /* only here if cmd = "STOR" (proxy=1) */
1312 if (command("%s %s", cmd2, local) != PRELIM) {
1315 abort_remote((FILE *) NULL);
1320 (void) signal(SIGINT, oldintr);
1324 abort_remote((FILE *) NULL);
1326 if (!cpend && !secndflag) { /* only if cmd = "RETR" (proxy=1) */
1327 if (command("%s %s", cmd2, local) != PRELIM) {
1330 abort_remote((FILE *) NULL);
1334 (void) signal(SIGINT, oldintr);
1339 abort_remote((FILE *) NULL);
1343 FD_SET(fileno(cin), &mask);
1344 if ((nfnd = empty(&mask, 10)) <= 0) {
1360 (void) signal(SIGINT, oldintr);
1373 FD_SET(fileno(cin), &mask);
1374 if ((nfnd = empty(&mask,0)) < 0) {
1389 static char new[MAXPATHLEN];
1390 char *cp = strrchr(local, '/');
1396 d = access(cp ? local : ".", 2);
1400 warn("local: %s", local);
1401 return ((char *) 0);
1403 (void) strcpy(new, local);
1404 cp = new + strlen(new);
1407 if (++count == 100) {
1408 printf("runique: can't find unique file name.\n");
1409 return ((char *) 0);
1417 if ((d = access(new, 0)) < 0)
1421 else if (*(cp - 2) == '.')
1424 *(cp - 2) = *(cp - 2) + 1;
1440 * send IAC in urgent mode instead of DM because 4.3BSD places oob mark
1441 * after urgent byte rather than before as is protocol now
1443 sprintf(buf, "%c%c%c", IAC, IP, IAC);
1444 if (send(fileno(cout), buf, 3, MSG_OOB) != 3)
1446 fprintf(cout,"%cABOR\r\n", DM);
1447 (void) fflush(cout);
1449 FD_SET(fileno(cin), &mask);
1451 FD_SET(fileno(din), &mask);
1453 if ((nfnd = empty(&mask, 10)) <= 0) {
1461 if (din && FD_ISSET(fileno(din), &mask)) {
1462 while (read(fileno(din), buf, BUFSIZ) > 0)
1465 if (getreply(0) == ERROR && code == 552) {
1466 /* 552 needed for nic style abort */