ObjFW  Check-in [f902c447ed]

Overview
Comment:tests: Print network interface addresses
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f902c447edf92885230cedac19fe06b6e02b965c25a2cbf5f9b1e8c88a5260d7
User & Date: js on 2023-04-23 19:49:47
Other Links: manifest | tags
Context
2023-04-24
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
12:00
PLATFORMS.md: Update Solaris check-in: 6b8ce15d4d user: js tags: trunk
Changes

Modified tests/OFSystemInfoTests.m from [79a55a5faf] to [646021bd53].

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();





	[OFStdOut setForegroundColor: [OFColor lime]];

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

	[OFStdOut writeFormat: @"[OFSystemInfo] Number of CPUs: %zd\n",







>
>
>
>







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

#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",
104
105
106
107
108
109
110
111
112


































113








114
115
116
117
118

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

#ifdef OF_SYSTEM_INFO_HAS_NETWORK_INTERFACES
	[OFStdOut writeFormat: @"[OFSystemInfo] Network interfaces: %@\n",
			       [[[OFSystemInfo networkInterfaces] allKeys]


































			       componentsJoinedByString: @", "]];








#endif

	objc_autoreleasePoolPop(pool);
}
@end







|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>





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

#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];
	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: @"%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;

			[OFStdOut writeString: string];
		}

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

	objc_autoreleasePoolPop(pool);
}
@end