Set SO_REUSEADDR on TFTP socket
This commit is contained in:
parent
f316c2d2b5
commit
7b398453db
1 changed files with 15 additions and 3 deletions
18
tftp.c
18
tftp.c
|
@ -331,6 +331,11 @@ int tftp_put(struct nmrpd_args *args)
|
||||||
bool rollover;
|
bool rollover;
|
||||||
const unsigned rx_timeout = MAX(args->rx_timeout / (args->blind ? 50 : 5), 2000);
|
const unsigned rx_timeout = MAX(args->rx_timeout / (args->blind ? 50 : 5), 2000);
|
||||||
const unsigned max_timeouts = args->blind ? 3 : 5;
|
const unsigned max_timeouts = args->blind ? 3 : 5;
|
||||||
|
#ifndef NMRPFLASH_WINDOWS
|
||||||
|
int enabled = 1;
|
||||||
|
#else
|
||||||
|
BOOL enabled = TRUE;
|
||||||
|
#endif
|
||||||
|
|
||||||
sock = -1;
|
sock = -1;
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
@ -361,27 +366,34 @@ int tftp_put(struct nmrpd_args *args)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NMRPFLASH_FUZZ_TFTP
|
#ifndef NMRPFLASH_FUZZ_TFTP
|
||||||
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
if (sock < 0) {
|
if (sock < 0) {
|
||||||
sock_perror("socket");
|
sock_perror("socket");
|
||||||
ret = sock;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &enabled, sizeof(enabled)) != 0) {
|
||||||
|
sock_perror("setsockopt");
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
sock = STDIN_FILENO;
|
sock = STDIN_FILENO;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
memset(&addr, 0, sizeof(addr));
|
memset(&addr, 0, sizeof(addr));
|
||||||
|
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
|
|
||||||
|
// check if we have an interface address, and bind to it if we do
|
||||||
if (args->ipaddr_intf) {
|
if (args->ipaddr_intf) {
|
||||||
|
addr.sin_addr.s_addr = inet_addr(args->ipaddr_intf);
|
||||||
if ((addr.sin_addr.s_addr = inet_addr(args->ipaddr_intf)) == INADDR_NONE) {
|
if ((addr.sin_addr.s_addr = inet_addr(args->ipaddr_intf)) == INADDR_NONE) {
|
||||||
xperror("inet_addr");
|
xperror("inet_addr");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bind(sock, (struct sockaddr*)&addr, sizeof(addr)) != 0) {
|
if (bind(sock, (struct sockaddr*)&addr, sizeof(addr)) != 0) {
|
||||||
|
printf("errno=%d\n", errno);
|
||||||
sock_perror("bind");
|
sock_perror("bind");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue