Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -1421,11 +1421,11 @@ AC_CHECK_HEADER(sys/socket.h, [ AC_DEFINE(OF_HAVE_SYS_SOCKET_H, 1, [Whether we have sys/socket.h]) ]) - AC_CHECK_MEMBER([struct sockaddr_storage.ss_family], [ + AC_CHECK_TYPE([struct sockaddr_storage], [ AC_DEFINE(OF_HAVE_SOCKADDR_STORAGE, 1, [Whether we have struct sockaddr_storage]) ], [], [ #ifdef OF_HAVE_SYS_TYPES_H # include @@ -1700,11 +1700,11 @@ ], [ AC_DEFINE(OF_HAVE_APPLETALK, 1, [Whether we have AppleTalk]) AC_SUBST(USE_SRCS_APPLETALK, '${SRCS_APPLETALK}') - AC_CHECK_MEMBERS([struct ifreq.ifr_name], [ + AC_CHECK_TYPE([struct ifreq], [ AC_DEFINE(OF_HAVE_APPLETALK_IFCONFIG, 1, m4_normalize([ Whether AppleTalk interfaces can be configured ])) @@ -1761,13 +1761,18 @@ "OFSelectKernelEventObserver.m") ]) ;; esac - AC_CHECK_HEADERS(ifaddrs.h) + AC_CHECK_HEADERS(ifaddrs.h netpacket/packet.h) AC_CHECK_FUNC(getifaddrs, [ AC_DEFINE(OF_HAVE_GETIFADDRS, 1, [Whether we have getifaddrs()]) + ]) + AC_CHECK_TYPES([struct sockaddr_ll], [], [], [ + #ifdef HAVE_NETPACKET_PACKET_H + # include + #endif ]) AC_ARG_WITH(tls, AS_HELP_STRING([--with-tls], [ enable TLS support using the specified library Index: src/OFSystemInfo.h ================================================================== --- src/OFSystemInfo.h +++ src/OFSystemInfo.h @@ -27,19 +27,27 @@ * @ref networkInterfaces. * * Possible keys are: * * * @ref OFNetworkInterfaceAddresses + * * @ref OFNetworkInterfaceEthernetAddress */ typedef OFConstantString *OFNetworkInterfaceInfoKey; /** * @brief The addresses of a network interface. * * This maps to an @ref OFData of @ref OFSocketAddress. */ extern OFConstantString *const OFNetworkInterfaceAddresses; + +/** + * @brief The Ethernet address of a network interface. + * + * This maps to an @ref OFData. + */ +extern OFConstantString *const OFNetworkInterfaceEthernetAddress; #endif /** * @class OFSystemInfo OFSystemInfo.h ObjFW/OFSystemInfo.h * Index: src/OFSystemInfo.m ================================================================== --- src/OFSystemInfo.m +++ src/OFSystemInfo.m @@ -86,10 +86,13 @@ #endif #ifdef HAVE_IFADDRS_H # include #endif +#ifdef HAVE_NETPACKET_PACKET_H +# include +#endif #if defined(OF_MACOS) || defined(OF_IOS) /* * These have been dropped from newer iOS SDKs, however, their replacements are * not available on iOS < 10. This means it's impossible to search for the @@ -122,10 +125,12 @@ #endif #if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_GETIFADDRS) OFConstantString *const OFNetworkInterfaceAddresses = @"OFNetworkInterfaceAddresses"; +OFConstantString *const OFNetworkInterfaceEthernetAddress = + @"OFNetworkInterfaceEthernetAddress"; #endif static size_t pageSize = 4096; static size_t numberOfCPUs = 1; static OFString *operatingSystemName = nil; @@ -903,10 +908,29 @@ forKey: interfaceName]; } if (iter->ifa_addr == NULL) continue; + +# if defined(HAVE_STRUCT_SOCKADDR_LL) && defined(AF_PACKET) + if (iter->ifa_addr->sa_family == AF_PACKET) { + const OFNetworkInterfaceInfoKey key = + OFNetworkInterfaceEthernetAddress; + struct sockaddr_ll *sll = (struct sockaddr_ll *) + (void *)iter->ifa_addr; + OFData *addr; + + /* ARP hardware address type 1 is Ethernet. */ + if (sll->sll_hatype != 1) + continue; + + addr = [OFData dataWithItems: sll->sll_addr + count: sll->sll_halen]; + [interface setObject: addr forKey: key]; + continue; + } +# endif addresses = [interface objectForKey: OFNetworkInterfaceAddresses]; if (addresses == nil) { addresses = [OFMutableData