Index: src/OFIPSocketAsyncConnector.m ================================================================== --- src/OFIPSocketAsyncConnector.m +++ src/OFIPSocketAsyncConnector.m @@ -136,11 +136,11 @@ { OFSocketAddress address = *(const OFSocketAddress *) [_socketAddresses itemAtIndex: _socketAddressesIndex++]; int errNo; - OFSocketAddressSetPort(&address, _port); + OFSocketAddressSetIPPort(&address, _port); if (![_socket of_createSocketForAddress: &address errNo: &errNo]) { if (_socketAddressesIndex >= _socketAddresses.count) { _exception = [[OFConnectIPSocketFailedException alloc] initWithHost: _host Index: src/OFSocket.h ================================================================== --- src/OFSocket.h +++ src/OFSocket.h @@ -244,27 +244,25 @@ */ extern OFString *_Nonnull OFSocketAddressString( const OFSocketAddress *_Nonnull address); /** - * @brief Sets the port of the specified @ref OFSocketAddress, independent of - * the address family used. + * @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 OFSocketAddressSetPort(OFSocketAddress *_Nonnull address, +extern void OFSocketAddressSetIPPort(OFSocketAddress *_Nonnull address, uint16_t port); /** - * @brief Returns the port of the specified @ref OFSocketAddress, independent of - * the address family used. + * @brief Returns the IP port of the specified @ref OFSocketAddress. * * @param address The address on which to get the port * @return The port of the address */ -extern uint16_t OFSocketAddressPort(const OFSocketAddress *_Nonnull address); +extern uint16_t OFSocketAddressIPPort(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 @@ -307,10 +305,27 @@ * @param node A byte array to store the IPX node of the address */ extern void OFSocketAddressGetIPXNode(const OFSocketAddress *_Nonnull address, unsigned char node[_Nonnull IPX_NODE_LEN]); +/** + * @brief Sets the IPX 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 OFSocketAddressSetIPXPort(OFSocketAddress *_Nonnull address, + uint16_t port); + +/** + * @brief Returns the IPX port of the specified @ref OFSocketAddress. + * + * @param address The address on which to get the port + * @return The port of the address + */ +extern uint16_t OFSocketAddressIPXPort(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); Index: src/OFSocket.m ================================================================== --- src/OFSocket.m +++ src/OFSocket.m @@ -836,37 +836,32 @@ @throw [OFInvalidArgumentException exception]; } } void -OFSocketAddressSetPort(OFSocketAddress *address, uint16_t port) +OFSocketAddressSetIPPort(OFSocketAddress *address, uint16_t port) { switch (address->family) { case OFSocketAddressFamilyIPv4: address->sockaddr.in.sin_port = OFToBigEndian16(port); break; case OFSocketAddressFamilyIPv6: address->sockaddr.in6.sin6_port = OFToBigEndian16(port); break; - case OFSocketAddressFamilyIPX: - address->sockaddr.ipx.sipx_port = OFToBigEndian16(port); - break; default: @throw [OFInvalidArgumentException exception]; } } uint16_t -OFSocketAddressPort(const OFSocketAddress *address) +OFSocketAddressIPPort(const OFSocketAddress *address) { switch (address->family) { case OFSocketAddressFamilyIPv4: return OFFromBigEndian16(address->sockaddr.in.sin_port); case OFSocketAddressFamilyIPv6: return OFFromBigEndian16(address->sockaddr.in6.sin6_port); - case OFSocketAddressFamilyIPX: - return OFFromBigEndian16(address->sockaddr.ipx.sipx_port); default: @throw [OFInvalidArgumentException exception]; } } @@ -933,5 +928,23 @@ if (address->family != OFSocketAddressFamilyIPX) @throw [OFInvalidArgumentException exception]; memcpy(node, address->sockaddr.ipx.sipx_node, IPX_NODE_LEN); } + +void +OFSocketAddressSetIPXPort(OFSocketAddress *address, uint16_t port) +{ + if (address->family != OFSocketAddressFamilyIPX) + @throw [OFInvalidArgumentException exception]; + + address->sockaddr.ipx.sipx_port = OFToBigEndian16(port); +} + +uint16_t +OFSocketAddressIPXPort(const OFSocketAddress *address) +{ + if (address->family != OFSocketAddressFamilyIPX) + @throw [OFInvalidArgumentException exception]; + + return OFFromBigEndian16(address->sockaddr.ipx.sipx_port); +} Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -309,11 +309,11 @@ socketAddresses = [[OFThread DNSResolver] resolveAddressesForHost: host addressFamily: OFSocketAddressFamilyAny]; address = *(OFSocketAddress *)[socketAddresses itemAtIndex: 0]; - OFSocketAddressSetPort(&address, port); + OFSocketAddressSetIPPort(&address, port); if ((_socket = socket( ((struct sockaddr *)&address.sockaddr)->sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle) @throw [OFBindIPSocketFailedException Index: src/OFUDPSocket.m ================================================================== --- src/OFUDPSocket.m +++ src/OFUDPSocket.m @@ -52,11 +52,11 @@ if ((_socket = socket( ((struct sockaddr *)&address->sockaddr)->sa_family, SOCK_DGRAM | SOCK_CLOEXEC | extraType, 0)) == OFInvalidSocketHandle) @throw [OFBindIPSocketFailedException exceptionWithHost: OFSocketAddressString(address) - port: OFSocketAddressPort(address) + port: OFSocketAddressIPPort(address) socket: self errNo: OFSocketErrNo()]; _canBlock = true; @@ -66,11 +66,11 @@ fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); } #endif #if defined(OF_HPUX) || defined(OF_WII) || defined(OF_NINTENDO_3DS) - if (OFSocketAddressPort(address) != 0) { + if (OFSocketAddressIPPort(address) != 0) { #endif if (bind(_socket, (struct sockaddr *)&address->sockaddr, address->length) != 0) { int errNo = OFSocketErrNo(); @@ -77,11 +77,11 @@ closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindIPSocketFailedException exceptionWithHost: OFSocketAddressString(address) - port: OFSocketAddressPort(address) + port: OFSocketAddressIPPort(address) socket: self errNo: errNo]; } #if defined(OF_HPUX) || defined(OF_WII) || defined(OF_NINTENDO_3DS) } else { @@ -100,11 +100,11 @@ break; if (OFSocketErrNo() != EADDRINUSE) { int errNo = OFSocketErrNo(); OFString *host = OFSocketAddressString(address); - port = OFSocketAddressPort(address); + port = OFSocketAddressIPPort(address); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindIPSocketFailedException @@ -117,11 +117,11 @@ } #endif objc_autoreleasePoolPop(pool); - if ((port = OFSocketAddressPort(address)) > 0) + if ((port = OFSocketAddressIPPort(address)) > 0) return port; #if !defined(OF_HPUX) && !defined(OF_WII) && !defined(OF_NINTENDO_3DS) memset(address, 0, sizeof(*address)); @@ -133,11 +133,11 @@ closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindIPSocketFailedException exceptionWithHost: OFSocketAddressString(address) - port: OFSocketAddressPort(address) + port: OFSocketAddressIPPort(address) socket: self errNo: errNo]; } switch (((struct sockaddr *)&address->sockaddr)->sa_family) { @@ -151,21 +151,21 @@ closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindIPSocketFailedException exceptionWithHost: OFSocketAddressString(address) - port: OFSocketAddressPort(address) + port: OFSocketAddressIPPort(address) socket: self errNo: EAFNOSUPPORT]; } #else closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindIPSocketFailedException exceptionWithHost: OFSocketAddressString(address) - port: OFSocketAddressPort(address) + port: OFSocketAddressIPPort(address) socket: self errNo: EADDRNOTAVAIL]; #endif } @@ -181,14 +181,14 @@ socketAddresses = [[OFThread DNSResolver] resolveAddressesForHost: host addressFamily: OFSocketAddressFamilyAny]; address = *(OFSocketAddress *)[socketAddresses itemAtIndex: 0]; - OFSocketAddressSetPort(&address, port); + OFSocketAddressSetIPPort(&address, port); port = [self of_bindToAddress: &address extraType: 0]; objc_autoreleasePoolPop(pool); return port; } @end Index: tests/OFSPXSocketTests.m ================================================================== --- tests/OFSPXSocketTests.m +++ tests/OFSPXSocketTests.m @@ -118,11 +118,11 @@ return; } network = OFSocketAddressIPXNetwork(&address1); OFSocketAddressGetIPXNode(&address1, node); - port = OFSocketAddressPort(&address1); + port = OFSocketAddressIPXPort(&address1); TEST(@"-[listen]", R([sockServer listen])) TEST(@"-[connectToNetwork:node:port:]", R([sockClient connectToNetwork: network node: node port: port])) @@ -158,11 +158,11 @@ delegate->_expectedNetwork = network = OFSocketAddressIPXNetwork(&address1); OFSocketAddressGetIPXNode(&address1, node); memcpy(delegate->_expectedNode, node, IPX_NODE_LEN); - delegate->_expectedPort = port = OFSocketAddressPort(&address1); + delegate->_expectedPort = port = OFSocketAddressIPXPort(&address1); @try { [sockClient asyncConnectToNetwork: network node: node port: port]; Index: tests/OFSPXStreamSocketTests.m ================================================================== --- tests/OFSPXStreamSocketTests.m +++ tests/OFSPXStreamSocketTests.m @@ -119,11 +119,11 @@ return; } network = OFSocketAddressIPXNetwork(&address1); OFSocketAddressGetIPXNode(&address1, node); - port = OFSocketAddressPort(&address1); + port = OFSocketAddressIPXPort(&address1); TEST(@"-[listen]", R([sockServer listen])) TEST(@"-[connectToNetwork:node:port:]", R([sockClient connectToNetwork: network node: node port: port])) @@ -162,11 +162,11 @@ delegate->_expectedNetwork = network = OFSocketAddressIPXNetwork(&address1); OFSocketAddressGetIPXNode(&address1, node); memcpy(delegate->_expectedNode, node, IPX_NODE_LEN); - delegate->_expectedPort = port = OFSocketAddressPort(&address1); + delegate->_expectedPort = port = OFSocketAddressIPXPort(&address1); @try { [sockClient asyncConnectToNetwork: network node: node port: port]; Index: tests/OFSocketTests.m ================================================================== --- tests/OFSocketTests.m +++ tests/OFSocketTests.m @@ -81,11 +81,11 @@ OFSocketAddressParseIP(@"127.0.a.1", 1234)) EXPECT_EXCEPTION(@"Refusing invalid IPv4 #6", OFInvalidFormatException, OFSocketAddressParseIP(@"127.0..1", 1234)) - TEST(@"Port of an IPv4 address", OFSocketAddressPort(&addr) == 1234) + TEST(@"Port of an IPv4 address", OFSocketAddressIPPort(&addr) == 1234) TEST(@"Converting an IPv4 to a string", [OFSocketAddressString(&addr) isEqual: @"127.0.0.1"]) TEST(@"Parsing an IPv6 #1", @@ -143,11 +143,11 @@ OFSocketAddressParseIP(@"1:2:3:4:5:6:7::", 1234)) EXPECT_EXCEPTION(@"Refusing invalid IPv6 #10", OFInvalidFormatException, OFSocketAddressParseIP(@"1:2", 1234)) - TEST(@"Port of an IPv6 address", OFSocketAddressPort(&addr) == 1234) + TEST(@"Port of an IPv6 address", OFSocketAddressIPPort(&addr) == 1234) SET_V6(addr, 0, 0, 0, 0, 0, 0, 0, 0) TEST(@"Converting an IPv6 to a string #1", [OFSocketAddressString(&addr) isEqual: @"::"]) Index: tests/OFUDPSocketTests.m ================================================================== --- tests/OFUDPSocketTests.m +++ tests/OFUDPSocketTests.m @@ -42,11 +42,11 @@ TEST(@"-[receiveIntoBuffer:length:sender:]", [sock receiveIntoBuffer: buf length: 6 sender: &addr2] == 6 && !memcmp(buf, "Hello", 6) && [OFSocketAddressString(&addr2) isEqual: @"127.0.0.1"] && - OFSocketAddressPort(&addr2) == port1) + OFSocketAddressIPPort(&addr2) == port1) addr3 = OFSocketAddressParseIP(@"127.0.0.1", port1 + 1); /* * TODO: Move those tests elsewhere as soon as the DNS resolving part