version 1.104, 2019/05/16 12:44:17 |
version 1.105, 2019/06/28 13:35:01 |
|
|
fprintf(ttyout, "Trying %s...\n", hbuf); |
fprintf(ttyout, "Trying %s...\n", hbuf); |
} |
} |
s = socket(res->ai_family, res->ai_socktype, res->ai_protocol); |
s = socket(res->ai_family, res->ai_socktype, res->ai_protocol); |
if (s < 0) { |
if (s == -1) { |
cause = "socket"; |
cause = "socket"; |
continue; |
continue; |
} |
} |
|
|
cause = "bind"; |
cause = "bind"; |
continue; |
continue; |
} |
} |
if (bind(s, ares->ai_addr, ares->ai_addrlen) < 0) { |
if (bind(s, ares->ai_addr, ares->ai_addrlen) == -1) { |
cause = "bind"; |
cause = "bind"; |
error = errno; |
error = errno; |
close(s); |
close(s); |
|
|
/* finally we got one */ |
/* finally we got one */ |
break; |
break; |
} |
} |
if (s < 0) { |
if (s == -1) { |
warn("%s", cause); |
warn("%s", cause); |
code = -1; |
code = -1; |
freeaddrinfo(res0); |
freeaddrinfo(res0); |
|
|
ares = NULL; |
ares = NULL; |
} |
} |
#endif /* !SMALL */ |
#endif /* !SMALL */ |
if (getsockname(s, &myctladdr.sa, &namelen) < 0) { |
if (getsockname(s, &myctladdr.sa, &namelen) == -1) { |
warn("getsockname"); |
warn("getsockname"); |
code = -1; |
code = -1; |
goto bad; |
goto bad; |
} |
} |
if (hisctladdr.sa.sa_family == AF_INET) { |
if (hisctladdr.sa.sa_family == AF_INET) { |
tos = IPTOS_LOWDELAY; |
tos = IPTOS_LOWDELAY; |
if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(int)) < 0) |
if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(int)) == -1) |
warn("setsockopt TOS (ignored)"); |
warn("setsockopt TOS (ignored)"); |
} |
} |
cin = fdopen(s, "r"); |
cin = fdopen(s, "r"); |
|
|
|
|
ret = setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on)); |
ret = setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on)); |
#ifndef SMALL |
#ifndef SMALL |
if (ret < 0 && debug) |
if (ret == -1 && debug) |
warn("setsockopt"); |
warn("setsockopt"); |
#endif /* !SMALL */ |
#endif /* !SMALL */ |
} |
} |
|
|
return; |
return; |
} |
} |
closefunc = fclose; |
closefunc = fclose; |
if (fstat(fileno(fin), &st) < 0 || |
if (fstat(fileno(fin), &st) == -1 || |
(st.st_mode & S_IFMT) != S_IFREG) { |
(st.st_mode & S_IFMT) != S_IFREG) { |
fprintf(ttyout, "%s: not a plain file.\n", local); |
fprintf(ttyout, "%s: not a plain file.\n", local); |
(void)signal(SIGINT, oldintr); |
(void)signal(SIGINT, oldintr); |
|
|
oldintr = signal(SIGINT, abortrecv); |
oldintr = signal(SIGINT, abortrecv); |
oldinti = signal(SIGINFO, psummary); |
oldinti = signal(SIGINFO, psummary); |
if (ignorespecial || (strcmp(local, "-") && *local != '|')) { |
if (ignorespecial || (strcmp(local, "-") && *local != '|')) { |
if (access(local, W_OK) < 0) { |
if (access(local, W_OK) == -1) { |
char *dir; |
char *dir; |
|
|
if (errno != ENOENT && errno != EACCES) { |
if (errno != ENOENT && errno != EACCES) { |
|
|
d = access(dir == local ? "/" : dir ? local : ".", W_OK); |
d = access(dir == local ? "/" : dir ? local : ".", W_OK); |
if (dir != NULL) |
if (dir != NULL) |
*dir = '/'; |
*dir = '/'; |
if (d < 0) { |
if (d == -1) { |
warn("local: %s", local); |
warn("local: %s", local); |
(void)signal(SIGINT, oldintr); |
(void)signal(SIGINT, oldintr); |
(void)signal(SIGINFO, oldinti); |
(void)signal(SIGINFO, oldinti); |
|
|
return; |
return; |
} |
} |
if (!runique && errno == EACCES && |
if (!runique && errno == EACCES && |
chmod(local, (S_IRUSR|S_IWUSR)) < 0) { |
chmod(local, (S_IRUSR|S_IWUSR)) == -1) { |
warn("local: %s", local); |
warn("local: %s", local); |
(void)signal(SIGINT, oldintr); |
(void)signal(SIGINT, oldintr); |
(void)signal(SIGINFO, oldinti); |
(void)signal(SIGINFO, oldinti); |
|
|
} |
} |
closefunc = fclose; |
closefunc = fclose; |
} |
} |
if (fstat(fileno(fout), &st) < 0 || st.st_blksize == 0) |
if (fstat(fileno(fout), &st) == -1 || st.st_blksize == 0) |
st.st_blksize = BUFSIZ; |
st.st_blksize = BUFSIZ; |
if (st.st_blksize > bufsize) { |
if (st.st_blksize > bufsize) { |
(void)free(buf); |
(void)free(buf); |
|
|
|
|
case TYPE_I: |
case TYPE_I: |
if (restart_point && |
if (restart_point && |
lseek(fileno(fout), restart_point, SEEK_SET) < 0) { |
lseek(fileno(fout), restart_point, SEEK_SET) == -1) { |
warn("local: %s", local); |
warn("local: %s", local); |
progress = oprogress; |
progress = oprogress; |
preserve = opreserve; |
preserve = opreserve; |
|
|
if (restart_point) { |
if (restart_point) { |
int i, n, ch; |
int i, n, ch; |
|
|
if (fseek(fout, 0L, SEEK_SET) < 0) |
if (fseek(fout, 0L, SEEK_SET) == -1) |
goto done; |
goto done; |
n = restart_point; |
n = restart_point; |
for (i = 0; i++ < n;) { |
for (i = 0; i++ < n;) { |
|
|
if (ch == '\n') |
if (ch == '\n') |
i++; |
i++; |
} |
} |
if (fseek(fout, 0L, SEEK_CUR) < 0) { |
if (fseek(fout, 0L, SEEK_CUR) == -1) { |
done: |
done: |
if (errno) |
if (errno) |
warn("local: %s", local); |
warn("local: %s", local); |
|
|
if (passivemode) { |
if (passivemode) { |
data_addr = myctladdr; |
data_addr = myctladdr; |
data = socket(data_addr.sa.sa_family, SOCK_STREAM, 0); |
data = socket(data_addr.sa.sa_family, SOCK_STREAM, 0); |
if (data < 0) { |
if (data == -1) { |
warn("socket"); |
warn("socket"); |
return (1); |
return (1); |
} |
} |
#ifndef SMALL |
#ifndef SMALL |
if (srcaddr) { |
if (srcaddr) { |
if (bind(data, ares->ai_addr, ares->ai_addrlen) < 0) { |
if (bind(data, ares->ai_addr, ares->ai_addrlen) == -1) { |
warn("bind"); |
warn("bind"); |
close(data); |
close(data); |
return (1); |
return (1); |
|
|
} |
} |
if ((options & SO_DEBUG) && |
if ((options & SO_DEBUG) && |
setsockopt(data, SOL_SOCKET, SO_DEBUG, (char *)&on, |
setsockopt(data, SOL_SOCKET, SO_DEBUG, (char *)&on, |
sizeof(on)) < 0) |
sizeof(on)) == -1) |
warn("setsockopt (ignored)"); |
warn("setsockopt (ignored)"); |
#endif /* !SMALL */ |
#endif /* !SMALL */ |
switch (data_addr.sa.sa_family) { |
switch (data_addr.sa.sa_family) { |
|
|
if (data_addr.sa.sa_family == AF_INET) { |
if (data_addr.sa.sa_family == AF_INET) { |
on = IPTOS_THROUGHPUT; |
on = IPTOS_THROUGHPUT; |
if (setsockopt(data, IPPROTO_IP, IP_TOS, (char *)&on, |
if (setsockopt(data, IPPROTO_IP, IP_TOS, (char *)&on, |
sizeof(int)) < 0) |
sizeof(int)) == -1) |
warn("setsockopt TOS (ignored)"); |
warn("setsockopt TOS (ignored)"); |
} |
} |
return (0); |
return (0); |
|
|
if (data != -1) |
if (data != -1) |
(void)close(data); |
(void)close(data); |
data = socket(data_addr.sa.sa_family, SOCK_STREAM, 0); |
data = socket(data_addr.sa.sa_family, SOCK_STREAM, 0); |
if (data < 0) { |
if (data == -1) { |
warn("socket"); |
warn("socket"); |
if (tmpno) |
if (tmpno) |
sendport = 1; |
sendport = 1; |
|
|
} |
} |
if (!sendport) |
if (!sendport) |
if (setsockopt(data, SOL_SOCKET, SO_REUSEADDR, (char *)&on, |
if (setsockopt(data, SOL_SOCKET, SO_REUSEADDR, (char *)&on, |
sizeof(on)) < 0) { |
sizeof(on)) == -1) { |
warn("setsockopt (reuse address)"); |
warn("setsockopt (reuse address)"); |
goto bad; |
goto bad; |
} |
} |
|
|
case AF_INET: |
case AF_INET: |
on = IP_PORTRANGE_HIGH; |
on = IP_PORTRANGE_HIGH; |
if (setsockopt(data, IPPROTO_IP, IP_PORTRANGE, |
if (setsockopt(data, IPPROTO_IP, IP_PORTRANGE, |
(char *)&on, sizeof(on)) < 0) |
(char *)&on, sizeof(on)) == -1) |
warn("setsockopt IP_PORTRANGE (ignored)"); |
warn("setsockopt IP_PORTRANGE (ignored)"); |
break; |
break; |
case AF_INET6: |
case AF_INET6: |
on = IPV6_PORTRANGE_HIGH; |
on = IPV6_PORTRANGE_HIGH; |
if (setsockopt(data, IPPROTO_IPV6, IPV6_PORTRANGE, |
if (setsockopt(data, IPPROTO_IPV6, IPV6_PORTRANGE, |
(char *)&on, sizeof(on)) < 0) |
(char *)&on, sizeof(on)) == -1) |
warn("setsockopt IPV6_PORTRANGE (ignored)"); |
warn("setsockopt IPV6_PORTRANGE (ignored)"); |
break; |
break; |
} |
} |
if (bind(data, &data_addr.sa, data_addr.sa.sa_len) < 0) { |
if (bind(data, &data_addr.sa, data_addr.sa.sa_len) == -1) { |
warn("bind"); |
warn("bind"); |
goto bad; |
goto bad; |
} |
} |
#ifndef SMALL |
#ifndef SMALL |
if (options & SO_DEBUG && |
if (options & SO_DEBUG && |
setsockopt(data, SOL_SOCKET, SO_DEBUG, (char *)&on, |
setsockopt(data, SOL_SOCKET, SO_DEBUG, (char *)&on, |
sizeof(on)) < 0) |
sizeof(on)) == -1) |
warn("setsockopt (ignored)"); |
warn("setsockopt (ignored)"); |
#endif /* !SMALL */ |
#endif /* !SMALL */ |
namelen = sizeof(data_addr); |
namelen = sizeof(data_addr); |
if (getsockname(data, &data_addr.sa, &namelen) < 0) { |
if (getsockname(data, &data_addr.sa, &namelen) == -1) { |
warn("getsockname"); |
warn("getsockname"); |
goto bad; |
goto bad; |
} |
} |
if (listen(data, 1) < 0) |
if (listen(data, 1) == -1) |
warn("listen"); |
warn("listen"); |
|
|
#define UC(b) (((int)b)&0xff) |
#define UC(b) (((int)b)&0xff) |
|
|
if (data_addr.sa.sa_family == AF_INET) { |
if (data_addr.sa.sa_family == AF_INET) { |
on = IPTOS_THROUGHPUT; |
on = IPTOS_THROUGHPUT; |
if (setsockopt(data, IPPROTO_IP, IP_TOS, (char *)&on, |
if (setsockopt(data, IPPROTO_IP, IP_TOS, (char *)&on, |
sizeof(int)) < 0) |
sizeof(int)) == -1) |
warn("setsockopt TOS (ignored)"); |
warn("setsockopt TOS (ignored)"); |
} |
} |
return (0); |
return (0); |
|
|
return (fdopen(data, lmode)); |
return (fdopen(data, lmode)); |
|
|
s = accept(data, &from.sa, &fromlen); |
s = accept(data, &from.sa, &fromlen); |
if (s < 0) { |
if (s == -1) { |
warn("accept"); |
warn("accept"); |
(void)close(data), data = -1; |
(void)close(data), data = -1; |
return (NULL); |
return (NULL); |
|
|
if (from.sa.sa_family == AF_INET) { |
if (from.sa.sa_family == AF_INET) { |
int tos = IPTOS_THROUGHPUT; |
int tos = IPTOS_THROUGHPUT; |
if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos, |
if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos, |
sizeof(int)) < 0) { |
sizeof(int)) == -1) { |
warn("setsockopt TOS (ignored)"); |
warn("setsockopt TOS (ignored)"); |
} |
} |
} |
} |
|
|
pfd[0].fd = fileno(cin); |
pfd[0].fd = fileno(cin); |
pfd[0].events = POLLIN; |
pfd[0].events = POLLIN; |
if ((nfnd = poll(pfd, 1, 10 * 1000)) <= 0) { |
if ((nfnd = poll(pfd, 1, 10 * 1000)) <= 0) { |
if (nfnd < 0) |
if (nfnd == -1) |
warn("abort"); |
warn("abort"); |
if (ptabflg) |
if (ptabflg) |
code = -1; |
code = -1; |
|
|
pfd[0].fd = fileno(cin); |
pfd[0].fd = fileno(cin); |
pfd[0].events = POLLIN; |
pfd[0].events = POLLIN; |
while (nfnd > 0) { |
while (nfnd > 0) { |
if ((nfnd = poll(pfd, 1, 0)) < 0) { |
if ((nfnd = poll(pfd, 1, 0)) == -1) { |
warn("reset"); |
warn("reset"); |
code = -1; |
code = -1; |
lostpeer(); |
lostpeer(); |
|
|
d = access(cp == local ? "/" : cp ? local : ".", W_OK); |
d = access(cp == local ? "/" : cp ? local : ".", W_OK); |
if (cp) |
if (cp) |
*cp = '/'; |
*cp = '/'; |
if (d < 0) { |
if (d == -1) { |
warn("local: %s", local); |
warn("local: %s", local); |
return ((char *) 0); |
return ((char *) 0); |
} |
} |
|
|
ext = '0'; |
ext = '0'; |
else |
else |
ext++; |
ext++; |
if ((d = access(new, F_OK)) < 0) |
if ((d = access(new, F_OK)) == -1) |
break; |
break; |
if (ext != '0') |
if (ext != '0') |
cp--; |
cp--; |
|
|
nfds++; |
nfds++; |
} |
} |
if ((nfnd = poll(pfd, nfds, 10 * 1000)) <= 0) { |
if ((nfnd = poll(pfd, nfds, 10 * 1000)) <= 0) { |
if (nfnd < 0) |
if (nfnd == -1) |
warn("abort"); |
warn("abort"); |
if (ptabflg) |
if (ptabflg) |
code = -1; |
code = -1; |