diff options
| author | 2025-11-07 01:41:35 +0900 | |
|---|---|---|
| committer | 2026-10-04 00:28:58 +0200 | |
| commit | 6f6bfebce9f4a4f3d91aae0f6be67b45686126e8 (patch) | |
| tree | af2603941512f572330da9a32e36283909cc6de3 /src/socket.c | |
| parent | da770a7687f35fbb981db4d7b47b1b032cd5c2c7 (diff) | |
| download | libimobiledevice-glue-6f6bfebce9f4a4f3d91aae0f6be67b45686126e8.tar.gz libimobiledevice-glue-6f6bfebce9f4a4f3d91aae0f6be67b45686126e8.tar.bz2 | |
socket: Improve portability by replacing OS-specific macros with AC_CHECK_HEADERS
The primary purpose of this change is to support NetBSD.
No functional changes intended.
Diffstat (limited to 'src/socket.c')
| -rw-r--r-- | src/socket.c | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/src/socket.c b/src/socket.c index b107a7c..5d22d14 100644 --- a/src/socket.c +++ b/src/socket.c @@ -56,10 +56,10 @@ #ifdef AF_INET6 #include <net/if.h> #include <ifaddrs.h> -#if defined (__APPLE__) || defined (__FreeBSD__) || defined (__HAIKU__) +#if defined (HAVE_NET_IF_DL_H) #include <net/if_dl.h> #endif -#ifdef __linux__ +#if defined (HAVE_NETPACKET_PACKET_H) #include <netpacket/packet.h> #endif #endif @@ -907,28 +907,32 @@ int get_primary_mac_address(unsigned char mac_addr_buf[6]) if (ifa->ifa_flags & IFF_LOOPBACK) { continue; } -#if defined(__APPLE__) || defined (__FreeBSD__) || defined (__HAIKU__) +#if defined (HAVE_NET_IF_DL_H) + /* BSD, Darwin, and Haiku */ if (ifa->ifa_addr->sa_family != AF_LINK) { continue; } #if defined (__APPLE__) - if (!strcmp(ifa->ifa_name, "en0")) { -#elif defined (__FreeBSD__) || defined (__HAIKU__) - { -#endif - memcpy(mac_addr_buf, (unsigned char *)LLADDR((struct sockaddr_dl *)(ifa)->ifa_addr), 6); - result = 0; - break; + if (strcmp(ifa->ifa_name, "en0") != 0) { + continue; } -#elif defined (__linux__) +#endif + memcpy(mac_addr_buf, (unsigned char *)LLADDR((struct sockaddr_dl *)(ifa)->ifa_addr), 6); + result = 0; + break; +#elif defined (HAVE_NETPACKET_PACKET_H) + /* Linux */ if (ifa->ifa_addr->sa_family != AF_PACKET) { continue; } - if (strcmp(ifa->ifa_name, "lo") != 0) { - memcpy(mac_addr_buf, ((struct sockaddr_ll*)ifa->ifa_addr)->sll_addr, 6); - result = 0; - break; +#if defined (__linux__) + if (strcmp(ifa->ifa_name, "lo") == 0) { + continue; } +#endif + memcpy(mac_addr_buf, ((struct sockaddr_ll*)ifa->ifa_addr)->sll_addr, 6); + result = 0; + break; #elif defined (WIN32) if (ifa->ifa_data) { memcpy(mac_addr_buf, ifa->ifa_data, 6); |
