Index: src/OFDDPSocket.h ================================================================== --- src/OFDDPSocket.h +++ src/OFDDPSocket.h @@ -60,18 +60,21 @@ */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id delegate; /** - * @brief Bind the socket to the specified network and port. + * @brief Bind the socket to the specified network, node and port. * * @param network The network to bind to. 0 means any. + * @param node The node to bind to. 0 means "this node". * @param port The port to bind to. 0 means to pick one and return it via the * returned socket address. * @return The address on which this socket can be reached * @throw OFBindDDPSockeFailedException Binding failed * @throw OFAlreadyConnectedException The socket is already bound */ -- (OFSocketAddress)bindToNetwork: (uint16_t)network port: (uint8_t)port; +- (OFSocketAddress)bindToNetwork: (uint16_t)network + node: (uint8_t)node + port: (uint8_t)port; @end OF_ASSUME_NONNULL_END Index: src/OFDDPSocket.m ================================================================== --- src/OFDDPSocket.m +++ src/OFDDPSocket.m @@ -29,26 +29,29 @@ #import "OFBindDDPSocketFailedException.h" @implementation OFDDPSocket @dynamic delegate; -- (OFSocketAddress)bindToNetwork: (uint16_t)network port: (uint8_t)port +- (OFSocketAddress)bindToNetwork: (uint16_t)network + node: (uint8_t)node + port: (uint8_t)port { OFSocketAddress address; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) int flags; #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; - address = OFSocketAddressMakeAppleTalk(network, 0, port); + address = OFSocketAddressMakeAppleTalk(network, node, port); if ((_socket = socket(address.sockaddr.at.sat_family, SOCK_DGRAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle) @throw [OFBindDDPSocketFailedException exceptionWithNetwork: network + node: node port: port socket: self errNo: OFSocketErrNo()]; _canBlock = true; @@ -65,10 +68,11 @@ closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindDDPSocketFailedException exceptionWithNetwork: network + node: node port: port socket: self errNo: errNo]; } @@ -83,10 +87,11 @@ closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindDDPSocketFailedException exceptionWithNetwork: network + node: node port: port socket: self errNo: errNo]; } @@ -94,13 +99,14 @@ closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindDDPSocketFailedException exceptionWithNetwork: network + node: node port: port socket: self errNo: EAFNOSUPPORT]; } return address; } @end Index: src/exceptions/OFBindDDPSocketFailedException.h ================================================================== --- src/exceptions/OFBindDDPSocketFailedException.h +++ src/exceptions/OFBindDDPSocketFailedException.h @@ -26,33 +26,40 @@ */ OF_SUBCLASSING_RESTRICTED @interface OFBindDDPSocketFailedException: OFBindSocketFailedException { uint16_t _network; - uint8_t _port; + uint8_t _node, _port; } /** * @brief The DDP network on which binding failed. */ @property (readonly, nonatomic) uint16_t network; +/** + * @brief The DDP node for which binding failed. + */ +@property (readonly, nonatomic) uint8_t node; + /** * @brief The DDP port on which binding failed. */ @property (readonly, nonatomic) uint8_t port; /** * @brief Creates a new, autoreleased bind DDP socket failed exception. * * @param network The DDP network on which binding failed + * @param node The DDP node for which binding failed * @param port The DDP port on which binding failed * @param socket The socket which could not be bound * @param errNo The errno of the error that occurred * @return A new, autoreleased bind DDP socket failed exception */ + (instancetype)exceptionWithNetwork: (uint16_t)network + node: (uint8_t)node port: (uint8_t)port socket: (id)socket errNo: (int)errNo; + (instancetype)exceptionWithSocket: (id)socket @@ -60,19 +67,21 @@ /** * @brief Initializes an already allocated bind DDP socket failed exception. * * @param network The DDP network on which binding failed + * @param node The DDP node for which binding failed * @param port The DDP port on which binding failed * @param socket The socket which could not be bound * @param errNo The errno of the error that occurred * @return An initialized bind DDP socket failed exception */ - (instancetype)initWithNetwork: (uint16_t)network + node: (uint8_t)node port: (uint8_t)port socket: (id)socket errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)initWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END Index: src/exceptions/OFBindDDPSocketFailedException.m ================================================================== --- src/exceptions/OFBindDDPSocketFailedException.m +++ src/exceptions/OFBindDDPSocketFailedException.m @@ -18,23 +18,25 @@ #import "OFBindDDPSocketFailedException.h" #import "OFData.h" #import "OFString.h" @implementation OFBindDDPSocketFailedException -@synthesize network = _network, port = _port; +@synthesize network = _network, node = _node, port = _port; + (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithNetwork: (uint16_t)network + node: (uint8_t)node port: (uint8_t)port socket: (id)sock errNo: (int)errNo { return [[[self alloc] initWithNetwork: network + node: node port: port socket: sock errNo: errNo] autorelease]; } @@ -42,18 +44,20 @@ { OF_INVALID_INIT_METHOD } - (instancetype)initWithNetwork: (uint16_t)network + node: (uint8_t)node port: (uint8_t)port socket: (id)sock errNo: (int)errNo { self = [super initWithSocket: sock errNo: errNo]; @try { _network = network; + _node = node; _port = port; } @catch (id e) { [self release]; @throw e; } @@ -62,10 +66,10 @@ } - (OFString *)description { return [OFString stringWithFormat: - @"Binding to port %" @PRIx8 @" on network %" PRIx16 @" failed in " - @"socket of type %@: %@", - _port, _network, [_socket class], OFStrError(_errNo)]; + @"Binding to port %" @PRIx8 @" of node %" @PRIx8 @" on network " + @"%" PRIx16 @" failed in socket of type %@: %@", + _port, _node, _network, [_socket class], OFStrError(_errNo)]; } @end Index: tests/OFDDPSocketTests.m ================================================================== --- tests/OFDDPSocketTests.m +++ tests/OFDDPSocketTests.m @@ -30,24 +30,24 @@ char buffer[5]; TEST(@"+[socket]", (sock = [OFDDPSocket socket])) @try { - TEST(@"-[bindToNetwork:port:]", - R(address1 = [sock bindToNetwork: 0 port: 0])) + TEST(@"-[bindToNetwork:node:port:]", + R(address1 = [sock bindToNetwork: 0 node: 0 port: 0])) } @catch (OFBindSocketFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: - @"\r[OFDDPSocket] -[bindToNetwork:port:] " + @"\r[OFDDPSocket] -[bindToNetwork:node:port:] " @"AppleTalk unsupported, skipping tests"]; break; case EADDRNOTAVAIL: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: - @"\r[OFDDPSocket] -[bindToNetwork:port:] " + @"\r[OFDDPSocket] -[bindToNetwork:node:port:] " @"AppleTalk not configured, skipping tests"]; break; default: @throw e; }