ObjFW  Diff

Differences From Artifact [b04c355341]:

To Artifact [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