@@ -97,14 +97,14 @@ OFSocketAddressFamilyUnknown, /** IPv4 */ OFSocketAddressFamilyIPv4, /** IPv6 */ OFSocketAddressFamilyIPv6, + /** UNIX */ + OFSocketAddressFamilyUNIX, /** IPX */ OFSocketAddressFamilyIPX, - /** UNIX */ - OFSocketAddressFamilyUNIX, /** Any address family */ OFSocketAddressFamilyAny = 255 } OFSocketAddressFamily; #ifndef OF_HAVE_IPV6 @@ -116,10 +116,17 @@ uint8_t s6_addr[16]; } sin6_addr; uint32_t sin6_scope_id; }; #endif + +#if !defined(OF_HAVE_UNIX_SOCKETS) && !defined(OF_MORPHOS) && !defined(OF_MINT) +struct sockaddr_un { + sa_family_t sun_family; + char sun_path[108]; +}; +#endif #ifndef OF_HAVE_IPX # define IPX_NODE_LEN 6 struct sockaddr_ipx { sa_family_t sipx_family; @@ -135,17 +142,10 @@ # define sipx_network sa_netnum # define sipx_node sa_nodenum # define sipx_port sa_socket #endif -#if !defined(OF_HAVE_UNIX_SOCKETS) && !defined(OF_MORPHOS) && !defined(OF_MINT) -struct sockaddr_un { - sa_family_t sun_family; - char sun_path[108]; -}; -#endif - /** * @struct OFSocketAddress OFSocket.h ObjFW/OFSocket.h * * @brief A struct which represents a host / port pair for a socket. */ @@ -160,12 +160,12 @@ OFSocketAddressFamily family; union { struct sockaddr sockaddr; struct sockaddr_in in; struct sockaddr_in6 in6; - struct sockaddr_ipx ipx; struct sockaddr_un un; + struct sockaddr_ipx ipx; } sockaddr; socklen_t length; } OFSocketAddress; #ifdef __cplusplus @@ -197,30 +197,29 @@ * @param port The port to use * @return The parsed IPv6 and port as an OFSocketAddress */ extern OFSocketAddress OFSocketAddressParseIPv6(OFString *IP, uint16_t port); -/** - * @brief Creates an IPX address for the specified node, network and port. - * - * @param node The node in the IPX network - * @param network The IPX network - * @param port The IPX port (sometimes called socket number) on the node - * @return An IPX socket address with the specified node, network and port. - */ -extern OFSocketAddress OFSocketAddressMakeIPX( - const unsigned char node[_Nonnull IPX_NODE_LEN], uint32_t network, - uint16_t port); - /** * @brief Creates a UNIX socket address from the specified path. * * @param path The path of the UNIX socket * @return A UNIX socket address with the specified path */ extern OFSocketAddress OFSocketAddressMakeUNIX(OFString *path); +/** + * @brief Creates an IPX address for the specified node, network and port. + * + * @param network The IPX network + * @param node The node in the IPX network + * @param port The IPX port (sometimes called socket number) on the node + * @return An IPX socket address with the specified node, network and port. + */ +extern OFSocketAddress OFSocketAddressMakeIPX(uint32_t network, + const unsigned char node[_Nonnull IPX_NODE_LEN], uint16_t port); + /** * @brief Compares two OFSocketAddress for equality. * * @param address1 The address to compare with the second address * @param address2 The second address @@ -264,10 +263,19 @@ * @param address The address on which to get the port * @return The port of the address */ extern uint16_t OFSocketAddressPort(const OFSocketAddress *_Nonnull address); +/** + * @brief Gets the UNIX socket path of the specified @ref OFSocketAddress. + * + * @param address The address on which to get the UNIX socket path + * @return The UNIX socket path + */ +extern OFString *_Nullable OFSocketAddressUNIXPath( + const OFSocketAddress *_Nonnull address); + /** * @brief Sets the IPX network of the specified @ref OFSocketAddress. * * @param address The address on which to set the IPX network * @param network The IPX network to set on the address @@ -300,19 +308,10 @@ * @param node A byte array to store the IPX node of the address */ extern void OFSocketAddressIPXNode(const OFSocketAddress *_Nonnull address, unsigned char node[_Nonnull IPX_NODE_LEN]); -/** - * @brief Gets the UNIX socket path of the specified @ref OFSocketAddress. - * - * @param address The address on which to get the UNIX socket path - * @return The UNIX socket path - */ -extern OFString *_Nullable OFSocketAddressUNIXPath( - const OFSocketAddress *_Nonnull address); - extern bool OFSocketInit(void); #if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS) extern void OFSocketDeinit(void); #endif extern int OFSocketErrNo(void);