Implement carrier detection on BSD/macOS
This commit is contained in:
parent
0e81ef5fb5
commit
d6e2c0c4ac
3 changed files with 19 additions and 3 deletions
14
ethsock.c
14
ethsock.c
|
@ -553,6 +553,20 @@ bool ethsock_is_unplugged(struct ethsock *sock)
|
|||
}
|
||||
|
||||
return false;
|
||||
#elif defined(NMRPFLASH_BSD)
|
||||
struct ifmediareq ifmr;
|
||||
|
||||
memset(&ifmr, 0, sizeof(ifmr));
|
||||
strncpy(ifmr.ifr_name, name, sizeof(ifmr.ifr_name));
|
||||
|
||||
if (ioctl(fd, SIOCGIFMEDIA, &ifmr) < 0) {
|
||||
if (verbosity > 1) {
|
||||
perror("ioctl(SIOCGIFMEDIA)");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return (ifmr.ifm_status & IFM_AVALID) && !(ifmr.ifm_status & IFM_ACTIVE);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
|
|
4
nmrp.c
4
nmrp.c
|
@ -447,7 +447,7 @@ int nmrp_do(struct nmrpd_args *args)
|
|||
sigh_orig = signal(SIGINT, sigh);
|
||||
|
||||
if (ethsock_is_unplugged(sock)) {
|
||||
printf("Waiting for Ethernet cable to be plugged in.\n");
|
||||
printf("Waiting for phyiscal connection.\n");
|
||||
|
||||
bool unplugged = true;
|
||||
time_t beg = time_monotonic();
|
||||
|
@ -460,7 +460,9 @@ int nmrp_do(struct nmrpd_args *args)
|
|||
}
|
||||
|
||||
if (unplugged) {
|
||||
if (!g_interrupted) {
|
||||
fprintf(stderr, "Error: Ethernet cable is unplugged.");
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue