Implement carrier detection on BSD/macOS

This commit is contained in:
Joseph C. Lehner 2020-12-13 12:09:37 +01:00
parent 0e81ef5fb5
commit d6e2c0c4ac
3 changed files with 19 additions and 3 deletions

View file

@ -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
View file

@ -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;
}
}