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;
|
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
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
|
6
nmrp.c
6
nmrp.c
|
@ -447,7 +447,7 @@ int nmrp_do(struct nmrpd_args *args)
|
||||||
sigh_orig = signal(SIGINT, sigh);
|
sigh_orig = signal(SIGINT, sigh);
|
||||||
|
|
||||||
if (ethsock_is_unplugged(sock)) {
|
if (ethsock_is_unplugged(sock)) {
|
||||||
printf("Waiting for Ethernet cable to be plugged in.\n");
|
printf("Waiting for phyiscal connection.\n");
|
||||||
|
|
||||||
bool unplugged = true;
|
bool unplugged = true;
|
||||||
time_t beg = time_monotonic();
|
time_t beg = time_monotonic();
|
||||||
|
@ -460,7 +460,9 @@ int nmrp_do(struct nmrpd_args *args)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unplugged) {
|
if (unplugged) {
|
||||||
fprintf(stderr, "Error: Ethernet cable is unplugged.");
|
if (!g_interrupted) {
|
||||||
|
fprintf(stderr, "Error: Ethernet cable is unplugged.");
|
||||||
|
}
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
nmrpd.h
2
nmrpd.h
|
@ -34,7 +34,7 @@
|
||||||
# if defined(__linux__)
|
# if defined(__linux__)
|
||||||
# define NMRPFLASH_LINUX
|
# define NMRPFLASH_LINUX
|
||||||
# elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
|
# elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
|
||||||
# define NMRPFLASH_BSD
|
# define NMRPFLASH_BSD
|
||||||
# else
|
# else
|
||||||
# warning "nmrpflash is not fully supported on this platform"
|
# warning "nmrpflash is not fully supported on this platform"
|
||||||
# endif
|
# endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue