Index: src/OFSocket.h ================================================================== --- src/OFSocket.h +++ src/OFSocket.h @@ -288,15 +288,26 @@ /** * @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 + * @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 Index: src/OFSocket.m ================================================================== --- src/OFSocket.m +++ src/OFSocket.m @@ -987,10 +987,39 @@ 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) {