ObjFW  Check-in [c3f58bce43]

Overview
Comment:Add +[OFSystemInfo networkInterfaces]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c3f58bce43969a408edbe1a9e09ad08a3ec1193130e6a049675852dd1d34c43a
User & Date: js on 2023-04-22 09:55:54
Other Links: manifest | tags
Context
2023-04-22
10:14
OFSystemInfo: Move const into correct place check-in: 3d215a4f7d user: js tags: trunk
09:55
Add +[OFSystemInfo networkInterfaces] check-in: c3f58bce43 user: js tags: trunk
2023-04-17
16:44
Use @GOT instead of @GOTOFF for non-local symbols check-in: e26fd20d16 user: js tags: trunk
Changes

Modified Doxyfile from [f1f5fc12ae] to [95b2541e8f].

19
20
21
22
23
24
25

26
27
28
29
30
31
32
	     OF_FILE_MANAGER_SUPPORTS_LINKS			\
	     OF_FILE_MANAGER_SUPPORTS_OWNER			\
	     OF_FILE_MANAGER_SUPPORTS_PERMISSIONS		\
	     OF_FILE_MANAGER_SUPPORTS_SYMLINKS			\
	     OF_GENERIC(...)=					\
	     OF_HAVE_BLOCKS					\
	     OF_HAVE_FILES					\

	     OF_HAVE_SANDBOX					\
	     OF_HAVE_SOCKETS					\
	     OF_HAVE_THREADS					\
	     OF_KINDOF(...)=					\
	     OF_NO_RETURN=					\
	     OF_NO_RETURN_FUNC=					\
	     OF_NULLABLE_PROPERTY(...)=				\







>







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
	     OF_FILE_MANAGER_SUPPORTS_LINKS			\
	     OF_FILE_MANAGER_SUPPORTS_OWNER			\
	     OF_FILE_MANAGER_SUPPORTS_PERMISSIONS		\
	     OF_FILE_MANAGER_SUPPORTS_SYMLINKS			\
	     OF_GENERIC(...)=					\
	     OF_HAVE_BLOCKS					\
	     OF_HAVE_FILES					\
	     OF_HAVE_GETIFADDRS					\
	     OF_HAVE_SANDBOX					\
	     OF_HAVE_SOCKETS					\
	     OF_HAVE_THREADS					\
	     OF_KINDOF(...)=					\
	     OF_NO_RETURN=					\
	     OF_NO_RETURN_FUNC=					\
	     OF_NULLABLE_PROPERTY(...)=				\

Modified configure.ac from [f0175abcd7] to [8e28bb9d96].

1744
1745
1746
1747
1748
1749
1750





1751
1752
1753
1754
1755
1756
1757
			AC_DEFINE(HAVE_SELECT, 1,
				[Whether we have select() or similar])
			AC_SUBST(OF_SELECT_KERNEL_EVENT_OBSERVER_M,
				"OFSelectKernelEventObserver.m")
		])
		;;
	esac






	AC_ARG_WITH(tls,
		AS_HELP_STRING([--with-tls], [
			enable TLS support using the specified library
			(yes, openssl, gnutls, securetransport or no)]))
	AS_IF([test x"$with_tls" = x""], [with_tls="yes"])
	tls_support="no"







>
>
>
>
>







1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
			AC_DEFINE(HAVE_SELECT, 1,
				[Whether we have select() or similar])
			AC_SUBST(OF_SELECT_KERNEL_EVENT_OBSERVER_M,
				"OFSelectKernelEventObserver.m")
		])
		;;
	esac

	AC_CHECK_HEADERS(ifaddrs.h)
	AC_CHECK_FUNC(getifaddrs, [
		AC_DEFINE(OF_HAVE_GETIFADDRS, 1, [Whether we have getifaddrs()])
	])

	AC_ARG_WITH(tls,
		AS_HELP_STRING([--with-tls], [
			enable TLS support using the specified library
			(yes, openssl, gnutls, securetransport or no)]))
	AS_IF([test x"$with_tls" = x""], [with_tls="yes"])
	tls_support="no"

Modified src/OFSystemInfo.h from [f94336272c] to [6d6c0b651c].

14
15
16
17
18
19
20

21



















22
23
24
25
26
27
28
 */

#import "OFObject.h"
#import "OFString.h"

OF_ASSUME_NONNULL_BEGIN


@class OFIRI;




















/**
 * @class OFSystemInfo OFSystemInfo.h ObjFW/OFSystemInfo.h
 *
 * @brief A class for querying information about the system.
 */
OF_SUBCLASSING_RESTRICTED







>

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







14
15
16
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
 */

#import "OFObject.h"
#import "OFString.h"

OF_ASSUME_NONNULL_BEGIN

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

#if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_GETIFADDRS)
/**
 * @brief A key in the per-interface dictionary returned by
 *	  @ref networkInterfaces.
 *
 * Possible keys are:
 *
 *   * @ref OFNetworkInterfaceAddresses
 */
typedef OFString *OFNetworkInterfaceInfoKey;

/**
 * @brief The addresses of a network interface.
 *
 * This maps to an @ref OFData of @ref OFSocketAddress.
 */
extern const OFConstantString *OFNetworkInterfaceAddresses;
#endif

/**
 * @class OFSystemInfo OFSystemInfo.h ObjFW/OFSystemInfo.h
 *
 * @brief A class for querying information about the system.
 */
OF_SUBCLASSING_RESTRICTED
57
58
59
60
61
62
63





64
65
66
67
68
69
70
@property (class, readonly, nonatomic) bool supportsSHAExtensions;
# 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
#endif

/**
 * @brief Returns the size of a page.
 *
 * @return The size of a page







>
>
>
>
>







77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
@property (class, readonly, nonatomic) bool supportsSHAExtensions;
# 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
# if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_GETIFADDRS)
@property (class, readonly, nonatomic) OFDictionary OF_GENERIC(OFString *,
    OFDictionary OF_GENERIC(OFNetworkInterfaceInfoKey, id) *)
    *networkInterfaces;
# endif
#endif

/**
 * @brief Returns the size of a page.
 *
 * @return The size of a page
333
334
335
336
337
338
339











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












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

OF_ASSUME_NONNULL_END







>
>
>
>
>
>
>
>
>
>
>






358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
 *
 * @note This method is only available on Windows.
 *
 * @return Whether the application is running on Windows NT
 */
+ (bool)isWindowsNT;
#endif

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

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

OF_ASSUME_NONNULL_END

Modified src/OFSystemInfo.m from [b04c355341] to [3c961c10ed].

52
53
54
55
56
57
58

59
60
61
62



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82




83
84
85
86
87
88
89
#ifdef OF_DJGPP
# include <dos.h>
#endif

#import "OFSystemInfo.h"
#import "OFApplication.h"
#import "OFArray.h"

#import "OFDictionary.h"
#import "OFIRI.h"
#import "OFLocale.h"
#import "OFOnce.h"



#import "OFString.h"

#if defined(OF_MACOS) || defined(OF_IOS)
# ifdef HAVE_SYSDIR_H
#  include <sysdir.h>
# endif
#endif
#ifdef OF_WINDOWS
# include <windows.h>
#endif
#ifdef OF_HAIKU
# include <FindDirectory.h>
#endif
#ifdef OF_QNX
# 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







>




>
>
>




















>
>
>
>







52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifdef OF_DJGPP
# include <dos.h>
#endif

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

#if defined(OF_MACOS) || defined(OF_IOS)
# ifdef HAVE_SYSDIR_H
#  include <sysdir.h>
# endif
#endif
#ifdef OF_WINDOWS
# include <windows.h>
#endif
#ifdef OF_HAIKU
# include <FindDirectory.h>
#endif
#ifdef OF_QNX
# 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

#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
108
109
110
111
112
113
114





115
116
117
118
119
120
121
#endif

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






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

static void







>
>
>
>
>







116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#endif

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

#if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_GETIFADDRS)
const OFConstantString *OFNetworkInterfaceAddresses =
    @"OFNetworkInterfaceAddresses";
#endif

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

static void
815
816
817
818
819
820
821
822






























































































823
824
825
826
827

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































































































- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}
@end








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





828
829
830
831
832
833
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
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

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

#if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_GETIFADDRS)
static OFSocketAddress
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
	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;
	}

	return address;
}

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

	if (getifaddrs(&ifaddrs) != 0)
		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];
			}

			if (iter->ifa_addr == NULL)
				continue;

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

			address = wrapSockaddr(iter->ifa_addr);
			[addresses addItem: &address];
		}
	} @finally {
		freeifaddrs(ifaddrs);
	}

	return interfaces;
}
#endif

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}
@end

Modified src/objfw-defs.h.in from [376d21383b] to [af7372a4c7].

10
11
12
13
14
15
16

17
18
19
20
21
22
23
#undef OF_HAVE_BUILTIN_BSWAP16
#undef OF_HAVE_BUILTIN_BSWAP32
#undef OF_HAVE_BUILTIN_BSWAP64
#undef OF_HAVE_CHMOD
#undef OF_HAVE_CHOWN
#undef OF_HAVE_FILES
#undef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR

#undef OF_HAVE_IPV6
#undef OF_HAVE_IPX
#undef OF_HAVE_LIMITS_H
#undef OF_HAVE_LINK
#undef OF_HAVE_MAX_ALIGN_T
#undef OF_HAVE_NETATALK_AT_H
#undef OF_HAVE_NETAT_APPLETALK_H







>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#undef OF_HAVE_BUILTIN_BSWAP16
#undef OF_HAVE_BUILTIN_BSWAP32
#undef OF_HAVE_BUILTIN_BSWAP64
#undef OF_HAVE_CHMOD
#undef OF_HAVE_CHOWN
#undef OF_HAVE_FILES
#undef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR
#undef OF_HAVE_GETIFADDRS
#undef OF_HAVE_IPV6
#undef OF_HAVE_IPX
#undef OF_HAVE_LIMITS_H
#undef OF_HAVE_LINK
#undef OF_HAVE_MAX_ALIGN_T
#undef OF_HAVE_NETATALK_AT_H
#undef OF_HAVE_NETAT_APPLETALK_H