Don't continue in blind mode if Ethernet cable is disconnected
This commit is contained in:
parent
90f28cbffd
commit
8681520963
1 changed files with 15 additions and 4 deletions
19
nmrp.c
19
nmrp.c
|
|
@ -398,6 +398,7 @@ int nmrp_do(struct nmrpd_args *args)
|
||||||
char *filename;
|
char *filename;
|
||||||
time_t beg;
|
time_t beg;
|
||||||
int i, timeout, status, ulreqs, expect, upload_ok, autoip, ka_reqs;
|
int i, timeout, status, ulreqs, expect, upload_ok, autoip, ka_reqs;
|
||||||
|
bool was_plugged_in;
|
||||||
ssize_t bytes;
|
ssize_t bytes;
|
||||||
struct ethsock *sock;
|
struct ethsock *sock;
|
||||||
struct ethsock_ip_undo *ip_undo = NULL;
|
struct ethsock_ip_undo *ip_undo = NULL;
|
||||||
|
|
@ -481,7 +482,9 @@ int nmrp_do(struct nmrpd_args *args)
|
||||||
|
|
||||||
sigh_orig = signal(SIGINT, sigh);
|
sigh_orig = signal(SIGINT, sigh);
|
||||||
|
|
||||||
if (ethsock_is_unplugged(sock)) {
|
was_plugged_in = !ethsock_is_unplugged(sock);
|
||||||
|
|
||||||
|
if (!was_plugged_in) {
|
||||||
if (ethsock_is_wifi(sock)) {
|
if (ethsock_is_wifi(sock)) {
|
||||||
fprintf(stderr, "Error: Wi-Fi not connected.\n");
|
fprintf(stderr, "Error: Wi-Fi not connected.\n");
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -499,6 +502,8 @@ int nmrp_do(struct nmrpd_args *args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
was_plugged_in = !unplugged;
|
||||||
|
|
||||||
if (unplugged) {
|
if (unplugged) {
|
||||||
if (!g_interrupted) {
|
if (!g_interrupted) {
|
||||||
fprintf(stderr, "Error: Ethernet cable is unplugged.\n");
|
fprintf(stderr, "Error: Ethernet cable is unplugged.\n");
|
||||||
|
|
@ -555,6 +560,8 @@ int nmrp_do(struct nmrpd_args *args)
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
i = (i + 1) & 3;
|
i = (i + 1) & 3;
|
||||||
|
|
||||||
|
was_plugged_in |= !ethsock_is_unplugged(sock);
|
||||||
|
|
||||||
if (pkt_send(sock, &tx) < 0) {
|
if (pkt_send(sock, &tx) < 0) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
@ -576,9 +583,13 @@ int nmrp_do(struct nmrpd_args *args)
|
||||||
/* because we don't want nmrpflash's exit status to be zero */
|
/* because we don't want nmrpflash's exit status to be zero */
|
||||||
status = 1;
|
status = 1;
|
||||||
if ((time_monotonic() - beg) >= timeout) {
|
if ((time_monotonic() - beg) >= timeout) {
|
||||||
printf("\nNo response after %d seconds. ", timeout);
|
printf("\nNo response after %d seconds.\n", timeout);
|
||||||
if (!args->blind) {
|
if (!args->blind || !was_plugged_in) {
|
||||||
printf("Bailing out.\n");
|
printf("Bailing out");
|
||||||
|
if (!was_plugged_in) {
|
||||||
|
printf(" (Ethernet cable still unplugged)");
|
||||||
|
}
|
||||||
|
printf(".\n");
|
||||||
goto out;
|
goto out;
|
||||||
} else {
|
} else {
|
||||||
// we're blind, so fake a response from the MAC specified by -m
|
// we're blind, so fake a response from the MAC specified by -m
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue