ObjFW  Check-in [a8c9d73327]

Overview
Comment:Add OFSocketAddressDescription()
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a8c9d73327b853548394c1268315bfff1474d23102da4ac657ee892a9d1f8bf1
User & Date: js on 2023-10-22 21:45:53
Other Links: manifest | tags
Context
2023-10-22
21:47
Fix OFSocketAddressString() for AppleTalk check-in: 4056d5e2b6 user: js tags: trunk
21:45
Add OFSocketAddressDescription() check-in: a8c9d73327 user: js tags: trunk
2023-10-21
20:52
+[networkInterfaces]: Use index as key on Windows check-in: ad9452c908 user: js tags: trunk
Changes

Modified src/OFSocket.h from [39b53adb69] to [346d4cc46a].

286
287
288
289
290
291
292
293
294
295
296
297











298
299
300
301
302
303
304
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, without the port
 */
extern OFString *_Nonnull OFSocketAddressString(
    const OFSocketAddress *_Nonnull address);












/**
 * @brief Sets the IP port of the specified @ref OFSocketAddress.
 *
 * @param address The address on which to set the port
 * @param port The port to set on the address
 */
extern void OFSocketAddressSetIPPort(OFSocketAddress *_Nonnull address,







|




>
>
>
>
>
>
>
>
>
>
>







286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
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 a string, without the port
 */
extern OFString *_Nonnull OFSocketAddressString(
    const OFSocketAddress *_Nonnull address);

/**
 * @brief Returns a description for the specified @ref OFSocketAddress.
 *
 * This is similar to @ref OFSocketAddressString, but it also contains the port.
 *
 * @param address The address to return a description for
 * @return The address as an string, with the port
 */
extern OFString *_Nonnull OFSocketAddressDescription(
    const OFSocketAddress *_Nonnull address);

/**
 * @brief Sets the IP port of the specified @ref OFSocketAddress.
 *
 * @param address The address on which to set the port
 * @param port The port to set on the address
 */
extern void OFSocketAddressSetIPPort(OFSocketAddress *_Nonnull address,

Modified src/OFSocket.m from [0cd5c67cfd] to [c153f444b0].

985
986
987
988
989
990
991





























992
993
994
995
996
997
998
		return IPXString(address);
	case OFSocketAddressFamilyAppleTalk:
		return appleTalkString(address);
	default:
		@throw [OFInvalidArgumentException exception];
	}
}






























void
OFSocketAddressSetIPPort(OFSocketAddress *address, uint16_t port)
{
	switch (address->family) {
	case OFSocketAddressFamilyIPv4:
		address->sockaddr.in.sin_port = OFToBigEndian16(port);







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







985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
		return IPXString(address);
	case OFSocketAddressFamilyAppleTalk:
		return appleTalkString(address);
	default:
		@throw [OFInvalidArgumentException exception];
	}
}

OFString *
OFSocketAddressDescription(const OFSocketAddress *address)
{
	switch (address->family) {
	case OFSocketAddressFamilyIPv4:
		return [OFString
		    stringWithFormat: @"%@:%" PRIu16,
				      IPv4String(address),
				      OFSocketAddressIPPort(address)];
	case OFSocketAddressFamilyIPv6:
		return [OFString
		    stringWithFormat: @"[%@]:%" PRIu16,
				      IPv6String(address),
				      OFSocketAddressIPPort(address)];
	case OFSocketAddressFamilyIPX:
		return [OFString
		    stringWithFormat: @"%@.%" PRIX16,
				      IPXString(address),
				      OFSocketAddressIPXPort(address)];
	case OFSocketAddressFamilyAppleTalk:
		return [OFString
		    stringWithFormat: @"%@." PRIu8,
				      appleTalkString(address),
				      OFSocketAddressAppleTalkPort(address)];
	default:
		return OFSocketAddressString(address);
	}
}

void
OFSocketAddressSetIPPort(OFSocketAddress *address, uint16_t port)
{
	switch (address->family) {
	case OFSocketAddressFamilyIPv4:
		address->sockaddr.in.sin_port = OFToBigEndian16(port);