ObjFW  Check-in [43c80a7593]

Overview
Comment:Change how +[OFSystemInfo networkInterfaces] works

This removes functionality which will be restored later.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 43c80a7593063fdb233b8910856771a0bab8b0e9406bf880bc373adf9ae3321c
User & Date: js on 2023-05-21 17:47:10
Other Links: manifest | tags
Context
2023-05-27
10:54
GitHub Actions: Restore devkitPPC builds check-in: c294e5877d user: js tags: trunk
2023-05-21
17:47
Change how +[OFSystemInfo networkInterfaces] works check-in: 43c80a7593 user: js tags: trunk
13:10
Remove support for configuring AppleTalk check-in: 550bd1b7bb user: js tags: trunk
Changes

Modified Doxyfile from [864bba86b9] to [f1f5fc12ae].

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
33
34
35
36
37
38
39

40
41
42
43
44
45
46
47







-








	     OF_NULL_RESETTABLE_PROPERTY(...)=			\
	     OF_REQUIRES_SUPER=					\
	     OF_RETURNS_INNER_POINTER=				\
	     OF_RETURNS_NOT_RETAINED=				\
	     OF_RETURNS_RETAINED=				\
	     OF_ROOT_CLASS=					\
	     OF_SENTINEL=					\
	     OF_SYSTEM_INFO_HAS_NETWORK_INTERFACES		\
	     OF_WARN_UNUSED_RESULT=				\
	     OF_WEAK_UNAVAILABLE=				\
	     SIGHUP						\
	     SIGUSR1						\
	     SIGUSR2
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = YES
IGNORE_PREFIX = OF of_

Modified configure.ac from [579103d61e] to [b1471bd183].

1765
1766
1767
1768
1769
1770
1771
1772

1773
1774

1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1765
1766
1767
1768
1769
1770
1771

1772
1773

1774



1775
1776
1777
1778
1779
1780
1781







-
+

-
+
-
-
-







				[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(net/if.h net/if_types.h net/if_dl.h)
	AC_CHECK_HEADERS(netpacket/packet.h)
	AC_CHECK_FUNC(getifaddrs, [
	AC_CHECK_FUNCS(if_nameindex)
		AC_DEFINE(OF_SYSTEM_INFO_HAS_NETWORK_INTERFACES, 1,
			[Whether OFSystemInfo has network interfaces])
	])
	AC_CHECK_TYPES([struct sockaddr_dl], [], [], [
		#ifdef HAVE_SYS_TYPES_H
		# include <sys/types.h>
		#endif
		#ifdef HAVE_NET_IF_DL_H
		# include <net/if_dl.h>
		#endif

Modified src/OFSystemInfo.h from [d7ddb6bfe4] to [c58919a56b].

17
18
19
20
21
22
23
24
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
52
53
54
55
56
57
17
18
19
20
21
22
23



























24
25
26
27
28
29
30







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







#import "OFString.h"

OF_ASSUME_NONNULL_BEGIN

@class OFDictionary OF_GENERIC(KeyType, ObjectType);
@class OFIRI;

#ifdef OF_SYSTEM_INFO_HAS_NETWORK_INTERFACES
/**
 * @brief A key in the per-interface dictionary returned by
 *	  @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
 *
 * @brief A class for querying information about the system.
 */
OF_SUBCLASSING_RESTRICTED
@interface OFSystemInfo: OFObject
86
87
88
89
90
91
92
93
94


95
96

97
98
99
100
101
102
103
59
60
61
62
63
64
65


66
67


68
69
70
71
72
73
74
75







-
-
+
+
-
-
+







# endif
# if defined(OF_POWERPC) || defined(OF_POWERPC64) || defined(DOXYGEN)
@property (class, readonly, nonatomic) bool supportsAltiVec;
# endif
# ifdef OF_WINDOWS
@property (class, readonly, nonatomic, getter=isWindowsNT) bool windowsNT;
# endif
# ifdef OF_SYSTEM_INFO_HAS_NETWORK_INTERFACES
@property (class, readonly, nonatomic) OFDictionary OF_GENERIC(OFString *,
# ifdef OF_HAVE_SOCKETS
@property (class, readonly, nullable, nonatomic)
    OFDictionary OF_GENERIC(OFNetworkInterfaceInfoKey, id) *)
    *networkInterfaces;
    OFArray OF_GENERIC(OFString *) *networkInterfaces;
# endif
#endif

/**
 * @brief Returns the size of a page.
 *
 * @return The size of a page
367
368
369
370
371
372
373
374

375
376
377

378
379

380
381

382
383
384
385
386
387
388
389
339
340
341
342
343
344
345

346
347
348

349
350

351
352

353

354
355
356
357
358
359
360







-
+


-
+

-
+

-
+
-







 * @note This method is only available on Windows.
 *
 * @return Whether the application is running on Windows NT
 */
+ (bool)isWindowsNT;
#endif

#ifdef OF_SYSTEM_INFO_HAS_NETWORK_INTERFACES
#ifdef OF_HAVE_SOCKETS
/**
 * @brief Returns the available (though not necessarily configured) network
 *	  interfaces and information about them.
 *	  interfaces.
 *
 * @return The available network interfaces and information about them
 * @return The available network interfaces
 */
+ (OFDictionary OF_GENERIC(OFString *, OFDictionary
+ (nullable OFArray OF_GENERIC(OFString *) *)networkInterfaces;
    OF_GENERIC(OFNetworkInterfaceInfoKey, id) *) *)networkInterfaces;
#endif

+ (instancetype)alloc OF_UNAVAILABLE;
- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/OFSystemInfo.m from [91568c0543] to [29fca6defb].

26
27
28
29
30
31
32
33
34


35
36
37
38
39
40
41
26
27
28
29
30
31
32


33
34
35
36
37
38
39
40
41







-
-
+
+







#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>
#ifdef HAVE_NET_IF_H
# include <net/if.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
69
70
71
72
73
74
75

76
77
78
79
80
81
82
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83







+







#import "OFSystemInfo.h"
#import "OFApplication.h"
#import "OFArray.h"
#import "OFData.h"
#import "OFDictionary.h"
#import "OFIRI.h"
#import "OFLocale.h"
#import "OFNumber.h"
#import "OFOnce.h"
#ifdef OF_HAVE_SOCKETS
# import "OFSocket.h"
#endif
#import "OFString.h"

#if defined(OF_MACOS) || defined(OF_IOS)
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
127
128
129
130
131
132
133







134
135
136
137
138
139
140







-
-
-
-
-
-
-








#if defined(OF_AMD64) || defined(OF_X86)
struct X86Regs {
	uint32_t eax, ebx, ecx, edx;
};
#endif

#ifdef OF_SYSTEM_INFO_HAS_NETWORK_INTERFACES
OFConstantString *const OFNetworkInterfaceAddresses =
    @"OFNetworkInterfaceAddresses";
OFConstantString *const OFNetworkInterfaceEthernetAddress =
    @"OFNetworkInterfaceEthernetAddress";
#endif

static size_t pageSize = 4096;
static size_t numberOfCPUs = 1;
static OFString *operatingSystemName = nil;
static OFString *operatingSystemVersion = nil;

static void
initOperatingSystemName(void)
840
841
842
843
844
845
846
847
848


849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866

867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886

887
888
889

890
891
892
893
894
895

896
897


898
899

900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916


917
918
919

920
921
922
923
924
925
926
927

928
929
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
962
963
964
965
966


967
968
969

970
971

972
973
974



975
976
977
978
979
980
981
982
834
835
836
837
838
839
840


841
842

843
















844




















845



846




847

848
849

850
851
852

853

















854
855



856








857




858






859









860



861





862

863




864






865
866



867


868



869
870
871
872
873
874
875
876
877
878
879







-
-
+
+
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-

-
+

-
+
+

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
+
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
+
-

-
-
-
-
+
-
-
-
-
-
-
+
+
-
-
-
+
-
-
+
-
-
-
+
+
+








#ifdef OF_WINDOWS
+ (bool)isWindowsNT
{
	return !(GetVersion() & 0x80000000);
}
#endif

#ifdef OF_SYSTEM_INFO_HAS_NETWORK_INTERFACES
static OFSocketAddress
#ifdef OF_HAVE_SOCKETS
+ (OFArray OF_GENERIC(OFString *) *)networkInterfaces
wrapSockaddr(struct sockaddr *sa)
{
	OFSocketAddress address;

	switch (sa->sa_family) {
	case AF_INET:
		address.family = OFSocketAddressFamilyIPv4;
		memcpy(&address.sockaddr.ipx, sa, sizeof(struct sockaddr_in));
		address.length = (socklen_t)sizeof(struct sockaddr_in);
		break;
# ifdef AF_INET6
	case AF_INET6:
		address.family = OFSocketAddressFamilyIPv6;
		memcpy(&address.sockaddr.ipx, sa, sizeof(struct sockaddr_in6));
		address.length = (socklen_t)sizeof(struct sockaddr_in6);
		break;
# endif
# ifdef AF_IPX
# ifdef HAVE_IF_NAMEINDEX
	case AF_IPX:
		address.family = OFSocketAddressFamilyIPX;
		memcpy(&address.sockaddr.ipx, sa, sizeof(struct sockaddr_ipx));
		address.length = (socklen_t)sizeof(struct sockaddr_ipx);
		break;
# endif
# ifdef AF_APPLETALK
	case AF_APPLETALK:
		address.family = OFSocketAddressFamilyAppleTalk;
		memcpy(&address.sockaddr.at, sa, sizeof(struct sockaddr_at));
		address.length = (socklen_t)sizeof(struct sockaddr_at);
		break;
# endif
	default:
		address.family = OFSocketAddressFamilyUnknown;
		memcpy(&address.sockaddr, sa, sizeof(struct sockaddr));
		address.length = sizeof(struct sockaddr);
		break;
	}

	OFMutableArray *ret = [OFMutableArray array];
	return address;
}

	void *pool = objc_autoreleasePoolPush();
+ (OFDictionary OF_GENERIC(OFString *, OFDictionary
    OF_GENERIC(OFNetworkInterfaceInfoKey, id) *) *)networkInterfaces
{
	OFMutableDictionary *interfaces = [OFMutableDictionary dictionary];
	OFStringEncoding encoding = [OFLocale encoding];
	struct ifaddrs *ifaddrs;
	struct if_nameindex *nameindex = if_nameindex();

	if (getifaddrs(&ifaddrs) != 0)
	if (nameindex == NULL) {
		objc_autoreleasePoolPop(pool);
		return nil;

	}
	@try {
		for (struct ifaddrs *iter = ifaddrs; iter != NULL;
		    iter = iter->ifa_next) {
			OFString *interfaceName =
			    [OFString stringWithCString: iter->ifa_name
					       encoding: encoding];
			OFMutableDictionary *interface;
			OFMutableData *addresses;
			OFSocketAddress address;

			interface = [interfaces objectForKey: interfaceName];
			if (interface == nil) {
				interface = [OFMutableDictionary dictionary];
				[interfaces setObject: interface
					       forKey: interfaceName];
			}


	@try {
			if (iter->ifa_addr == NULL)
				continue;

		for (size_t i = 0; nameindex[i].if_index != 0; i++)
# 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;

			[ret addObject: [OFString
				/* ARP hardware address type 1 is Ethernet. */
				if (sll->sll_hatype != 1)
					continue;

			    stringWithCString: nameindex[i].if_name
				addr = [OFData dataWithItems: sll->sll_addr
						       count: sll->sll_halen];
				[interface setObject: addr forKey: key];
				continue;
			}
# endif
				     encoding: encoding]];
# 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;

	} @finally {
				if (sdl->sdl_type != IFT_ETHER)
					continue;

		if_freenameindex(nameindex);
				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
	[ret makeImmutable];
				    dataWithItemSize: sizeof(OFSocketAddress)];
				[interface
				    setObject: addresses
				       forKey: OFNetworkInterfaceAddresses];
			}


	objc_autoreleasePoolPop(pool);
			address = wrapSockaddr(iter->ifa_addr);
			[addresses addItem: &address];
		}

	} @finally {
		freeifaddrs(ifaddrs);
	return ret;
	}

	return interfaces;
# else
	return nil;
# endif
}
#endif

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}
@end

Modified src/objfw-defs.h.in from [b557faae7b] to [5a8629e6a6].

47
48
49
50
51
52
53
54
55
56
57
47
48
49
50
51
52
53

54
55
56







-



#undef OF_HAVE__THREAD_LOCAL
#undef OF_HAVE___THREAD
#undef OF_NINTENDO_3DS
#undef OF_NINTENDO_DS
#undef OF_NINTENDO_SWITCH
#undef OF_NO_SHARED
#undef OF_OBJFW_RUNTIME
#undef OF_SYSTEM_INFO_HAS_NETWORK_INTERFACES
#undef OF_UNIVERSAL
#undef OF_WII
#undef OF_WII_U

Modified tests/OFSystemInfoTests.m from [f271eb5ab9] to [bc94edf915].

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
17
18
19
20
21
22
23




24
25
26
27
28
29
30







-
-
-
-








#import "TestsAppDelegate.h"

@implementation TestsAppDelegate (OFSystemInfoTests)
- (void)systemInfoTests
{
	void *pool = objc_autoreleasePoolPush();
#ifdef OF_SYSTEM_INFO_HAS_NETWORK_INTERFACES
	OFDictionary *networkInterfaces;
	bool firstInterface = true;
#endif

	[OFStdOut setForegroundColor: [OFColor lime]];

	[OFStdOut writeFormat: @"[OFSystemInfo] Page size: %zd\n",
	    [OFSystemInfo pageSize]];

	[OFStdOut writeFormat: @"[OFSystemInfo] Number of CPUs: %zd\n",
107
108
109
110
111
112
113
114
115
116



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
103
104
105
106
107
108
109



110
111
112





























































113
114
115
116
117







-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





#endif

#ifdef OF_POWERPC
	[OFStdOut writeFormat: @"[OFSystemInfo] Supports AltiVec: %d\n",
	    [OFSystemInfo supportsAltiVec]];
#endif

#ifdef OF_SYSTEM_INFO_HAS_NETWORK_INTERFACES
	[OFStdOut writeString: @"[OFSystemInfo] Network interfaces: "];
	networkInterfaces = [OFSystemInfo networkInterfaces];
#ifdef OF_HAVE_SOCKETS
	[OFStdOut writeFormat: @"[OFSystemInfo] Network interfaces: %@\n",
	    [[OFSystemInfo networkInterfaces] componentsJoinedByString: @", "]];
	for (OFString *name in networkInterfaces) {
		OFDictionary *interface = [networkInterfaces
		    objectForKey: name];
		OFData *etherAddr = [interface
		    objectForKey: OFNetworkInterfaceEthernetAddress];
		bool firstAddress = true;
		OFData *addrs;

		if (!firstInterface)
			[OFStdOut writeString: @"; "];
		firstInterface = false;

		[OFStdOut writeFormat: @"%@(", name];

		if (etherAddr.itemSize == 1 && etherAddr.count == 6) {
			const unsigned char *addr = etherAddr.items;
			[OFStdOut writeFormat:
			    @"MAC=%02X:%02X:%02X:%02X:%02X:%02X",
			    addr[0], addr[1], addr[2], addr[3], addr[4],
			    addr[5]];
			firstAddress = false;
		}

		addrs = [interface objectForKey: OFNetworkInterfaceAddresses];
		for (size_t i = 0; i < addrs.count; i++) {
			const OFSocketAddress *addr = [addrs itemAtIndex: i];
			OFString *string;

			@try {
				string = OFSocketAddressString(addr);
			} @catch (OFInvalidArgumentException *e) {
				continue;
			}

			if (!firstAddress)
				[OFStdOut writeString: @", "];
			firstAddress = nil;

			switch (addr->family) {
			case OFSocketAddressFamilyIPv4:
				[OFStdOut writeString: @"IPv4="];
				break;
			case OFSocketAddressFamilyIPv6:
				[OFStdOut writeString: @"IPv6="];
				break;
			case OFSocketAddressFamilyIPX:
				[OFStdOut writeString: @"IPX="];
				break;
			case OFSocketAddressFamilyAppleTalk:
				[OFStdOut writeString: @"AppleTalk="];
				break;
			default:
				[OFStdOut writeString: @"unknown="];
			}

			[OFStdOut writeString: string];
		}

		[OFStdOut writeString: @")"];
	}
	[OFStdOut writeString: @"\n"];
#endif

	objc_autoreleasePoolPop(pool);
}
@end