ObjFW  Check-in [79c5eeefcc]

Overview
Comment:OFSocketAddressString: Add AppleTalk support
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 79c5eeefcc1b929fde696d44e924b68400b428e8ea402c01d330dec4a29e9774
User & Date: js on 2023-05-20 20:54:17
Other Links: manifest | tags
Context
2023-05-20
21:07
OFSocketAddressString: Add IPX support check-in: bd332cc15f user: js tags: trunk
20:54
OFSocketAddressString: Add AppleTalk support check-in: 79c5eeefcc user: js tags: trunk
16:42
OFUDPSocketTests: Remove obsolete comment check-in: 5028d169ad user: js tags: trunk
Changes

Modified src/OFSocket.h from [12afd4de67] to [413740135d].

286
287
288
289
290
291
292
293

294
295
296
297
298
299
300
286
287
288
289
290
291
292

293
294
295
296
297
298
299
300







-
+







extern unsigned long OFSocketAddressHash(
    const OFSocketAddress *_Nonnull address);

/**
 * @brief Converts the specified @ref OFSocketAddress to a string.
 *
 * @param address The address to convert to a string
 * @return The address as an IP string
 * @return The address as an IP string, without the port
 */
extern OFString *_Nonnull OFSocketAddressString(
    const OFSocketAddress *_Nonnull address);

/**
 * @brief Sets the IP port of the specified @ref OFSocketAddress.
 *

Modified src/OFSocket.m from [70652127c8] to [8fc5b1646d].

904
905
906
907
908
909
910









911
912
913
914
915
916
917
918
919


920
921
922
923
924
925
926
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







+
+
+
+
+
+
+
+
+









+
+







			[string appendFormat: @"%%%u", addrIn6->sin6_scope_id];
	}

	[string makeImmutable];

	return string;
}

static OFString *
appleTalkString(const OFSocketAddress *address)
{
	const struct sockaddr_at *addrAT = &address->sockaddr.at;

	return [OFString stringWithFormat: @"%d.%d",
	    OFFromBigEndian16(addrAT->sat_net), addrAT->sat_node];
}

OFString *
OFSocketAddressString(const OFSocketAddress *address)
{
	switch (address->family) {
	case OFSocketAddressFamilyIPv4:
		return IPv4String(address);
	case OFSocketAddressFamilyIPv6:
		return IPv6String(address);
	case OFSocketAddressFamilyAppleTalk:
		return appleTalkString(address);
	default:
		@throw [OFInvalidArgumentException exception];
	}
}

void
OFSocketAddressSetIPPort(OFSocketAddress *address, uint16_t port)

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

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
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







-
-
-
+
+
+
+

















+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+












			[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]];
			[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