ObjFW  Check-in [285c76be40]

Overview
Comment:OFSystemInfo: Get MAC address on BSD-like systems
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 285c76be409f575b506578c9ec4e007e7bb1b255facb2be5f5e52a0422be9536
User & Date: js on 2023-04-24 17:21:46
Other Links: manifest | tags
Context
2023-04-24
17:43
configure: Better includes for sockaddr_dl check check-in: 40169c71ae user: js tags: trunk
17:21
OFSystemInfo: Get MAC address on BSD-like systems check-in: 285c76be40 user: js tags: trunk
2023-04-23
19:49
tests: Print network interface addresses check-in: f902c447ed user: js tags: trunk
Changes

Modified configure.ac from [9cfe88cc27] to [fdec0da095].

1759
1760
1761
1762
1763
1764
1765
1766

1767
1768
1769






1770
1771
1772
1773
1774
1775
1776
				[Whether we have select() or similar])
			AC_SUBST(OF_SELECT_KERNEL_EVENT_OBSERVER_M,
				"OFSelectKernelEventObserver.m")
		])
		;;
	esac

	AC_CHECK_HEADERS(ifaddrs.h netpacket/packet.h)

	AC_CHECK_FUNC(getifaddrs, [
		AC_DEFINE(OF_SYSTEM_INFO_HAS_NETWORK_INTERFACES, 1,
			[Whether OFSystemInfo has network interfaces])






	])
	AC_CHECK_TYPES([struct sockaddr_ll], [], [], [
		#ifdef HAVE_NETPACKET_PACKET_H
		# include <netpacket/packet.h>
		#endif
	])








|
>



>
>
>
>
>
>







1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
				[Whether we have select() or similar])
			AC_SUBST(OF_SELECT_KERNEL_EVENT_OBSERVER_M,
				"OFSelectKernelEventObserver.m")
		])
		;;
	esac

	AC_CHECK_HEADERS(ifaddrs.h net/if_types.h net/if_dl.h)
	AC_CHECK_HEADERS(netpacket/packet.h)
	AC_CHECK_FUNC(getifaddrs, [
		AC_DEFINE(OF_SYSTEM_INFO_HAS_NETWORK_INTERFACES, 1,
			[Whether OFSystemInfo has network interfaces])
	])
	AC_CHECK_TYPES([struct sockaddr_dl], [], [], [
		#include <stdint.h>
		#ifdef HAVE_NET_IF_DL_H
		# include <net/if_dl.h>
		#endif
	])
	AC_CHECK_TYPES([struct sockaddr_ll], [], [], [
		#ifdef HAVE_NETPACKET_PACKET_H
		# include <netpacket/packet.h>
		#endif
	])

Modified src/OFSystemInfo.m from [88309917a4] to [91568c0543].

25
26
27
28
29
30
31













32
33
34
35
36
37
38

#ifdef HAVE_SYS_UTSNAME_H
# include <sys/utsname.h>
#endif
#if defined(OF_MACOS) || defined(OF_IOS) || defined(OF_NETBSD)
# include <sys/sysctl.h>
#endif














#ifdef OF_AMIGAOS
# define Class IntuitionClass
# include <exec/execbase.h>
# include <proto/exec.h>
# undef Class
#endif







>
>
>
>
>
>
>
>
>
>
>
>
>







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

#ifdef HAVE_SYS_UTSNAME_H
# include <sys/utsname.h>
#endif
#if defined(OF_MACOS) || defined(OF_IOS) || defined(OF_NETBSD)
# include <sys/sysctl.h>
#endif

#ifdef HAVE_IFADDRS_H
# include <ifaddrs.h>
#endif
#ifdef HAVE_NET_IF_TYPES_H
# include <net/if_types.h>
#endif
#ifdef HAVE_NET_IF_DL_H
# include <net/if_dl.h>
#endif
#ifdef HAVE_NETPACKET_PACKET_H
# include <netpacket/packet.h>
#endif

#ifdef OF_AMIGAOS
# define Class IntuitionClass
# include <exec/execbase.h>
# include <proto/exec.h>
# undef Class
#endif
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# include <sys/syspage.h>
#endif

#if !defined(PATH_MAX) && defined(MAX_PATH)
# define PATH_MAX MAX_PATH
#endif

#ifdef HAVE_IFADDRS_H
# include <ifaddrs.h>
#endif
#ifdef HAVE_NETPACKET_PACKET_H
# include <netpacket/packet.h>
#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
 * paths when using a new SDK while targeting iOS 9 or earlier. To work around
 * this, we define those manually, only to be used when the replacements are
 * not available at runtime.







<
<
<
<
<
<
<







94
95
96
97
98
99
100







101
102
103
104
105
106
107
# include <sys/syspage.h>
#endif

#if !defined(PATH_MAX) && defined(MAX_PATH)
# define PATH_MAX MAX_PATH
#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
 * paths when using a new SDK while targeting iOS 9 or earlier. To work around
 * this, we define those manually, only to be used when the replacements are
 * not available at runtime.
924
925
926
927
928
929
930


















931
932
933
934
935
936
937
					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
				    dataWithItemSize: sizeof(OFSocketAddress)];







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
					continue;

				addr = [OFData dataWithItems: sll->sll_addr
						       count: sll->sll_halen];
				[interface setObject: addr forKey: key];
				continue;
			}
# endif
# if defined(HAVE_STRUCT_SOCKADDR_DL) && defined(AF_LINK) && \
    defined(IFT_ETHER) && defined(LLADDR)
			if (iter->ifa_addr->sa_family == AF_LINK) {
				const OFNetworkInterfaceInfoKey key =
				    OFNetworkInterfaceEthernetAddress;
				struct sockaddr_dl *sdl = (struct sockaddr_dl *)
				    (void *)iter->ifa_addr;
				OFData *addr;

				if (sdl->sdl_type != IFT_ETHER)
					continue;

				addr = [OFData dataWithItems: LLADDR(sdl)
						       count: sdl->sdl_alen];
				[interface setObject: addr forKey: key];
				continue;
			}
# endif

			addresses = [interface
			    objectForKey: OFNetworkInterfaceAddresses];
			if (addresses == nil) {
				addresses = [OFMutableData
				    dataWithItemSize: sizeof(OFSocketAddress)];