mirror of
https://github.com/wiiu-env/ftpiiu_plugin.git
synced 2024-11-18 02:39:21 +01:00
Retry creating passive_socket of error
This commit is contained in:
parent
0968810796
commit
5da7be81b7
23
src/ftp.c
23
src/ftp.c
@ -325,18 +325,33 @@ static int32_t ftp_SIZE(client_t *client, char *path) {
|
|||||||
|
|
||||||
static int32_t ftp_PASV(client_t *client, char *rest UNUSED) {
|
static int32_t ftp_PASV(client_t *client, char *rest UNUSED) {
|
||||||
close_passive_socket(client);
|
close_passive_socket(client);
|
||||||
|
|
||||||
|
int32_t result;
|
||||||
|
struct sockaddr_in bindAddress;
|
||||||
|
while (passive_port < 5000) {
|
||||||
client->passive_socket = network_socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
|
client->passive_socket = network_socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
|
||||||
if (client->passive_socket < 0) {
|
if (client->passive_socket < 0) {
|
||||||
return write_reply(client, 520, "Unable to create listening socket.");
|
return write_reply(client, 520, "Unable to create listening socket.");
|
||||||
}
|
}
|
||||||
set_blocking(client->passive_socket, false);
|
set_blocking(client->passive_socket, false);
|
||||||
struct sockaddr_in bindAddress;
|
|
||||||
memset(&bindAddress, 0, sizeof(bindAddress));
|
memset(&bindAddress, 0, sizeof(bindAddress));
|
||||||
bindAddress.sin_family = AF_INET;
|
bindAddress.sin_family = AF_INET;
|
||||||
bindAddress.sin_port = htons(passive_port++); // XXX: BUG: This will overflow eventually, with interesting results...
|
bindAddress.sin_port = htons(passive_port); // XXX: BUG: This will overflow eventually, with interesting results...
|
||||||
bindAddress.sin_addr.s_addr = htonl(INADDR_ANY);
|
bindAddress.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||||
int32_t result;
|
|
||||||
if ((result = network_bind(client->passive_socket, (struct sockaddr *) &bindAddress, sizeof(bindAddress))) < 0) {
|
passive_port++;
|
||||||
|
|
||||||
|
if ((result = network_bind(client->passive_socket, (struct sockaddr *) &bindAddress, sizeof(bindAddress))) >= 0) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
close_passive_socket(client);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (passive_port >= 5000) {
|
||||||
|
passive_port = 1024;
|
||||||
|
}
|
||||||
|
if (result < 0) {
|
||||||
close_passive_socket(client);
|
close_passive_socket(client);
|
||||||
return write_reply(client, 520, "Unable to bind listening socket.");
|
return write_reply(client, 520, "Unable to bind listening socket.");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user