Index: src/OFDNSResolver.h ================================================================== --- src/OFDNSResolver.h +++ src/OFDNSResolver.h @@ -99,11 +99,11 @@ * @brief This method is called when a DNS resolver resolved a host to * addresses. * * @param resolver The acting resolver * @param host The host the resolver resolved - * @param addresses OFData containing several of_socket_address_t + * @param addresses OFData containing several OFSocketAddress * @param exception The exception that occurred during resolving, or nil on * success */ - (void)resolver: (OFDNSResolver *)resolver didResolveHost: (OFString *)host @@ -257,11 +257,11 @@ /** * @brief Synchronously resolves the specified host to socket addresses. * * @param host The host to resolve * @param addressFamily The desired socket address family - * @return OFData containing several of_socket_address_t + * @return OFData containing several OFSocketAddress */ - (OFData *)resolveAddressesForHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily; /** Index: src/OFDNSResolver.m ================================================================== --- src/OFDNSResolver.m +++ src/OFDNSResolver.m @@ -72,11 +72,11 @@ OFDNSResolverSettings *_settings; size_t _nameServersIndex; unsigned int _attempt; id _delegate; OFData *_queryData; - of_socket_address_t _usedNameServer; + OFSocketAddress _usedNameServer; OFTCPSocket *_TCPSocket; OFMutableData *_TCPQueryData; void *_TCPBuffer; size_t _responseLength; OFTimer *_cancelTimer; @@ -171,17 +171,17 @@ parseResourceRecord(OFString *name, of_dns_class_t DNSClass, of_dns_record_type_t recordType, uint32_t TTL, const unsigned char *buffer, size_t length, size_t i, uint16_t dataLength) { if (recordType == OF_DNS_RECORD_TYPE_A && DNSClass == OF_DNS_CLASS_IN) { - of_socket_address_t address; + OFSocketAddress address; if (dataLength != 4) @throw [OFInvalidServerReplyException exception]; memset(&address, 0, sizeof(address)); - address.family = OF_SOCKET_ADDRESS_FAMILY_IPV4; + address.family = OFSocketAddressFamilyIPv4; address.length = sizeof(address.sockaddr.in); address.sockaddr.in.sin_family = AF_INET; memcpy(&address.sockaddr.in.sin_addr.s_addr, buffer + i, 4); @@ -358,17 +358,17 @@ mailbox: mailbox TXTDomainName: TXTDomainName TTL: TTL] autorelease]; } else if (recordType == OF_DNS_RECORD_TYPE_AAAA && DNSClass == OF_DNS_CLASS_IN) { - of_socket_address_t address; + OFSocketAddress address; if (dataLength != 16) @throw [OFInvalidServerReplyException exception]; memset(&address, 0, sizeof(address)); - address.family = OF_SOCKET_ADDRESS_FAMILY_IPV6; + address.family = OFSocketAddressFamilyIPv6; address.length = sizeof(address.sockaddr.in6); #ifdef AF_INET6 address.sockaddr.in6.sin6_family = AF_INET6; #else @@ -735,18 +735,18 @@ port: 53 runLoopMode: runLoopMode]; return; } - context->_usedNameServer = of_socket_address_parse_ip(nameServer, 53); + context->_usedNameServer = OFSocketAddressParseIP(nameServer, 53); switch (context->_usedNameServer.family) { #ifdef OF_HAVE_IPV6 - case OF_SOCKET_ADDRESS_FAMILY_IPV6: + case OFSocketAddressFamilyIPv6: if (_IPv6Socket == nil) { - of_socket_address_t address = - of_socket_address_parse_ip(@"::", 0); + OFSocketAddress address = + OFSocketAddressParseIPv6(@"::", 0); _IPv6Socket = [[OFUDPSocket alloc] init]; [_IPv6Socket of_bindToAddress: &address extraType: SOCK_DNS]; _IPv6Socket.canBlock = false; @@ -754,14 +754,14 @@ } sock = _IPv6Socket; break; #endif - case OF_SOCKET_ADDRESS_FAMILY_IPV4: + case OFSocketAddressFamilyIPv4: if (_IPv4Socket == nil) { - of_socket_address_t address = - of_socket_address_parse_ip(@"0.0.0.0", 0); + OFSocketAddress address = + OFSocketAddressParseIPv4(@"0.0.0.0", 0); _IPv4Socket = [[OFUDPSocket alloc] init]; [_IPv4Socket of_bindToAddress: &address extraType: SOCK_DNS]; _IPv4Socket.canBlock = false; @@ -879,11 +879,11 @@ exception: exception]; } - (bool)of_handleResponseBuffer: (unsigned char *)buffer length: (size_t)length - sender: (const of_socket_address_t *)sender + sender: (const OFSocketAddress *)sender { OFDictionary *answerRecords = nil, *authorityRecords = nil; OFDictionary *additionalRecords = nil; OFDNSResponse *response = nil; id exception = nil; @@ -901,11 +901,11 @@ return true; if (context->_TCPSocket != nil) { if ([_TCPQueries objectForKey: context->_TCPSocket] != context) return true; - } else if (!of_socket_address_equal(sender, &context->_usedNameServer)) + } else if (!OFSocketAddressEqual(sender, &context->_usedNameServer)) return true; [context->_cancelTimer invalidate]; [context->_cancelTimer release]; context->_cancelTimer = nil; @@ -1041,11 +1041,11 @@ } - (bool)socket: (OFDatagramSocket *)sock didReceiveIntoBuffer: (void *)buffer length: (size_t)length - sender: (const of_socket_address_t *)sender + sender: (const OFSocketAddress *)sender exception: (id)exception { if (exception != nil) return true; @@ -1179,11 +1179,11 @@ - (void)asyncResolveAddressesForHost: (OFString *)host delegate: (id )delegate { [self asyncResolveAddressesForHost: host - addressFamily: OF_SOCKET_ADDRESS_FAMILY_ANY + addressFamily: OFSocketAddressFamilyAny runLoopMode: OFDefaultRunLoopMode delegate: delegate]; } - (void)asyncResolveAddressesForHost: (OFString *)host Index: src/OFDNSResolverSettings.m ================================================================== --- src/OFDNSResolverSettings.m +++ src/OFDNSResolverSettings.m @@ -74,11 +74,11 @@ { if (hostname == nil) return nil; @try { - of_socket_address_parse_ip(hostname, 0); + OFSocketAddressParseIP(hostname, 0); /* * If we are still here, the host name is a valid IP address. * We can't use that as local domain. */ Index: src/OFDNSResourceRecord.h ================================================================== --- src/OFDNSResourceRecord.h +++ src/OFDNSResourceRecord.h @@ -122,17 +122,17 @@ * @brief A class representing an A DNS resource record. */ OF_SUBCLASSING_RESTRICTED @interface OFADNSResourceRecord: OFDNSResourceRecord { - of_socket_address_t _address; + OFSocketAddress _address; } /** * @brief The IPv4 address of the resource record. */ -@property (readonly, nonatomic) const of_socket_address_t *address; +@property (readonly, nonatomic) const OFSocketAddress *address; - (instancetype)initWithName: (OFString *)name DNSClass: (of_dns_class_t)DNSClass recordType: (of_dns_record_type_t)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; @@ -145,11 +145,11 @@ * @param address The address for the resource record * @param TTL The time to live for the resource record * @return An initialized OFADNSResourceRecord */ - (instancetype)initWithName: (OFString *)name - address: (const of_socket_address_t *)address + address: (const OFSocketAddress *)address TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end /** * @class OFAAAADNSResourceRecord \ @@ -158,17 +158,17 @@ * @brief A class represenging a DNS resource record. */ OF_SUBCLASSING_RESTRICTED @interface OFAAAADNSResourceRecord: OFDNSResourceRecord { - of_socket_address_t _address; + OFSocketAddress _address; } /** * @brief The IPv6 address of the resource record. */ -@property (readonly, nonatomic) const of_socket_address_t *address; +@property (readonly, nonatomic) const OFSocketAddress *address; - (instancetype)initWithName: (OFString *)name DNSClass: (of_dns_class_t)DNSClass recordType: (of_dns_record_type_t)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; @@ -181,11 +181,11 @@ * @param address The address for the resource record * @param TTL The time to live for the resource record * @return An initialized OFAAAADNSResourceRecord */ - (instancetype)initWithName: (OFString *)name - address: (const of_socket_address_t *)address + address: (const OFSocketAddress *)address TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end /** * @class OFCNAMEDNSResourceRecord \ Index: src/OFDNSResourceRecord.m ================================================================== --- src/OFDNSResourceRecord.m +++ src/OFDNSResourceRecord.m @@ -194,11 +194,11 @@ { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name - address: (const of_socket_address_t *)address + address: (const OFSocketAddress *)address TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: OF_DNS_CLASS_IN recordType: OF_DNS_RECORD_TYPE_A @@ -207,11 +207,11 @@ _address = *address; return self; } -- (const of_socket_address_t *)address +- (const OFSocketAddress *)address { return &_address; } - (bool)isEqual: (id)object @@ -233,11 +233,11 @@ return false; if (record->_recordType != _recordType) return false; - if (!of_socket_address_equal(&record->_address, &_address)) + if (!OFSocketAddressEqual(&record->_address, &_address)) return false; return true; } @@ -250,11 +250,11 @@ OF_HASH_ADD_HASH(hash, _name.hash); OF_HASH_ADD(hash, _DNSClass >> 8); OF_HASH_ADD(hash, _DNSClass); OF_HASH_ADD(hash, _recordType >> 8); OF_HASH_ADD(hash, _recordType); - OF_HASH_ADD_HASH(hash, of_socket_address_hash(&_address)); + OF_HASH_ADD_HASH(hash, OFSocketAddressHash(&_address)); OF_HASH_FINALIZE(hash); return hash; } @@ -265,12 +265,11 @@ @"<%@:\n" @"\tName = %@\n" @"\tAddress = %@\n" @"\tTTL = %" PRIu32 "\n" @">", - self.className, _name, - of_socket_address_ip_string(&_address, NULL), _TTL]; + self.className, _name, OFSocketAddressString(&_address), _TTL]; } @end @implementation OFAAAADNSResourceRecord - (instancetype)initWithName: (OFString *)name @@ -280,11 +279,11 @@ { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name - address: (const of_socket_address_t *)address + address: (const OFSocketAddress *)address TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: OF_DNS_CLASS_IN recordType: OF_DNS_RECORD_TYPE_AAAA @@ -293,11 +292,11 @@ _address = *address; return self; } -- (const of_socket_address_t *)address +- (const OFSocketAddress *)address { return &_address; } - (bool)isEqual: (id)object @@ -319,11 +318,11 @@ return false; if (record->_recordType != _recordType) return false; - if (!of_socket_address_equal(&record->_address, &_address)) + if (!OFSocketAddressEqual(&record->_address, &_address)) return false; return true; } @@ -336,11 +335,11 @@ OF_HASH_ADD_HASH(hash, _name.hash); OF_HASH_ADD(hash, _DNSClass >> 8); OF_HASH_ADD(hash, _DNSClass); OF_HASH_ADD(hash, _recordType >> 8); OF_HASH_ADD(hash, _recordType); - OF_HASH_ADD_HASH(hash, of_socket_address_hash(&_address)); + OF_HASH_ADD_HASH(hash, OFSocketAddressHash(&_address)); OF_HASH_FINALIZE(hash); return hash; } @@ -351,12 +350,11 @@ @"<%@:\n" @"\tName = %@\n" @"\tAddress = %@\n" @"\tTTL = %" PRIu32 "\n" @">", - self.className, _name, - of_socket_address_ip_string(&_address, NULL), _TTL]; + self.className, _name, OFSocketAddressString(&_address), _TTL]; } @end @implementation OFCNAMEDNSResourceRecord @synthesize alias = _alias; Index: src/OFDatagramSocket.h ================================================================== --- src/OFDatagramSocket.h +++ src/OFDatagramSocket.h @@ -35,11 +35,11 @@ * @param exception An exception which occurred while receiving or `nil` on * success * @return A bool whether the same block should be used for the next receive */ typedef bool (^OFDatagramSocketAsyncReceiveBlock)(size_t length, - const of_socket_address_t *_Nonnull sender, id _Nullable exception); + const OFSocketAddress *_Nonnull sender, id _Nullable exception); /** * @brief A block which is called when a packet has been sent. * * @param data The data which was sent @@ -47,11 +47,11 @@ * @param exception An exception which occurred while reading or `nil` on * success * @return The data to repeat the send with or nil if it should not repeat */ typedef OFData *_Nullable (^OFDatagramSocketAsyncSendDataBlock)( - OFData *_Nonnull data, const of_socket_address_t *_Nonnull receiver, + OFData *_Nonnull data, const OFSocketAddress *_Nonnull receiver, id _Nullable exception); #endif /** * @protocol OFDatagramSocketDelegate OFDatagramSocket.h \ @@ -73,11 +73,11 @@ * @return A bool whether the same block should be used for the next receive */ - (bool)socket: (OFDatagramSocket *)socket didReceiveIntoBuffer: (void *)buffer length: (size_t)length - sender: (const of_socket_address_t *_Nonnull)sender + sender: (const OFSocketAddress *_Nonnull)sender exception: (nullable id)exception; /** * @brief This method is called when a packet has been sent. * @@ -87,11 +87,11 @@ * @param exception An exception that occurred while sending, or nil on success * @return The data to repeat the send with or nil if it should not repeat */ - (nullable OFData *)socket: (OFDatagramSocket *)socket didSendData: (OFData *)data - receiver: (const of_socket_address_t *_Nonnull)receiver + receiver: (const OFSocketAddress *_Nonnull)receiver exception: (nullable id)exception; @end /** * @class OFDatagramSocket OFDatagramSocket.h ObjFW/OFDatagramSocket.h @@ -150,17 +150,17 @@ * * If the buffer is too small, the datagram is truncated. * * @param buffer The buffer to write the datagram to * @param length The length of the buffer - * @param sender A pointer to an @ref of_socket_address_t, which will be set to - * the address of the sender + * @param sender A pointer to an @ref OFSocketAddress, which will be set to the + * address of the sender * @return The length of the received datagram */ - (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length - sender: (of_socket_address_t *)sender; + sender: (OFSocketAddress *)sender; /** * @brief Asynchronously receives a datagram and stores it into the specified * buffer. * @@ -230,67 +230,67 @@ /** * @brief Sends the specified datagram to the specified address. * * @param buffer The buffer to send as a datagram * @param length The length of the buffer - * @param receiver A pointer to an @ref of_socket_address_t to which the - * datagram should be sent + * @param receiver A pointer to an @ref OFSocketAddress to which the datagram + * should be sent */ - (void)sendBuffer: (const void *)buffer length: (size_t)length - receiver: (const of_socket_address_t *)receiver; + receiver: (const OFSocketAddress *)receiver; /** * @brief Asynchronously sends the specified datagram to the specified address. * * @param data The data to send as a datagram - * @param receiver A pointer to an @ref of_socket_address_t to which the - * datagram should be sent. The receiver is copied. + * @param receiver A pointer to an @ref OFSocketAddress to which the datagram + * should be sent. The receiver is copied. */ - (void)asyncSendData: (OFData *)data - receiver: (const of_socket_address_t *)receiver; + receiver: (const OFSocketAddress *)receiver; /** * @brief Asynchronously sends the specified datagram to the specified address. * * @param data The data to send as a datagram - * @param receiver A pointer to an @ref of_socket_address_t to which the - * datagram should be sent. The receiver is copied. + * @param receiver A pointer to an @ref OFSocketAddress to which the datgram + * should be sent. The receiver is copied. * @param runLoopMode The run loop mode in which to perform the async send */ - (void)asyncSendData: (OFData *)data - receiver: (const of_socket_address_t *)receiver + receiver: (const OFSocketAddress *)receiver runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously sends the specified datagram to the specified address. * * @param data The data to send as a datagram - * @param receiver A pointer to an @ref of_socket_address_t to which the - * datagram should be sent. The receiver is copied. + * @param receiver A pointer to an @ref OFSocketAddress to which the datagram + * should be sent. The receiver is copied. * @param block The block to call when the packet has been sent. It should * return the data for the next send with the same callback or nil * if it should not repeat. */ - (void)asyncSendData: (OFData *)data - receiver: (const of_socket_address_t *)receiver + receiver: (const OFSocketAddress *)receiver block: (OFDatagramSocketAsyncSendDataBlock)block; /** * @brief Asynchronously sends the specified datagram to the specified address. * * @param data The data to send as a datagram - * @param receiver A pointer to an @ref of_socket_address_t to which the - * datagram should be sent. The receiver is copied. + * @param receiver A pointer to an @ref OFSocketAddress to which the datagram + * should be sent. The receiver is copied. * @param runLoopMode The run loop mode in which to perform the async send * @param block The block to call when the packet has been sent. It should * return the data for the next send with the same callback or nil * if it should not repeat. */ - (void)asyncSendData: (OFData *)data - receiver: (const of_socket_address_t *)receiver + receiver: (const OFSocketAddress *)receiver runLoopMode: (OFRunLoopMode)runLoopMode block: (OFDatagramSocketAsyncSendDataBlock)block; #endif /** Index: src/OFDatagramSocket.m ================================================================== --- src/OFDatagramSocket.m +++ src/OFDatagramSocket.m @@ -165,11 +165,11 @@ #endif } - (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length - sender: (of_socket_address_t *)sender + sender: (OFSocketAddress *)sender { ssize_t ret; if (_socket == INVALID_SOCKET) @throw [OFNotOpenException exceptionWithObject: self]; @@ -195,24 +195,24 @@ errNo: of_socket_errno()]; #endif switch (sender->sockaddr.sockaddr.sa_family) { case AF_INET: - sender->family = OF_SOCKET_ADDRESS_FAMILY_IPV4; + sender->family = OFSocketAddressFamilyIPv4; break; #ifdef OF_HAVE_IPV6 case AF_INET6: - sender->family = OF_SOCKET_ADDRESS_FAMILY_IPV6; + sender->family = OFSocketAddressFamilyIPv6; break; #endif #ifdef OF_HAVE_IPX case AF_IPX: - sender->family = OF_SOCKET_ADDRESS_FAMILY_IPX; + sender->family = OFSocketAddressFamilyIPX; break; #endif default: - sender->family = OF_SOCKET_ADDRESS_FAMILY_UNKNOWN; + sender->family = OFSocketAddressFamilyUnknown; break; } return ret; } @@ -263,11 +263,11 @@ } #endif - (void)sendBuffer: (const void *)buffer length: (size_t)length - receiver: (const of_socket_address_t *)receiver + receiver: (const OFSocketAddress *)receiver { if (_socket == INVALID_SOCKET) @throw [OFNotOpenException exceptionWithObject: self]; #ifndef OF_WINDOWS @@ -305,19 +305,19 @@ bytesWritten: bytesWritten errNo: 0]; } - (void)asyncSendData: (OFData *)data - receiver: (const of_socket_address_t *)receiver + receiver: (const OFSocketAddress *)receiver { [self asyncSendData: data receiver: receiver runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncSendData: (OFData *)data - receiver: (const of_socket_address_t *)receiver + receiver: (const OFSocketAddress *)receiver runLoopMode: (OFRunLoopMode)runLoopMode { [OFRunLoop of_addAsyncSendForDatagramSocket: self data: data receiver: receiver @@ -328,21 +328,21 @@ delegate: _delegate]; } #ifdef OF_HAVE_BLOCKS - (void)asyncSendData: (OFData *)data - receiver: (const of_socket_address_t *)receiver + receiver: (const OFSocketAddress *)receiver block: (OFDatagramSocketAsyncSendDataBlock)block { [self asyncSendData: data receiver: receiver runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncSendData: (OFData *)data - receiver: (const of_socket_address_t *)receiver + receiver: (const OFSocketAddress *)receiver runLoopMode: (OFRunLoopMode)runLoopMode block: (OFDatagramSocketAsyncSendDataBlock)block { [OFRunLoop of_addAsyncSendForDatagramSocket: self data: data Index: src/OFHTTPRequest.h ================================================================== --- src/OFHTTPRequest.h +++ src/OFHTTPRequest.h @@ -73,11 +73,11 @@ { OFURL *_URL; of_http_request_method_t _method; of_http_request_protocol_version_t _protocolVersion; OFDictionary OF_GENERIC(OFString *, OFString *) *_Nullable _headers; - of_socket_address_t _remoteAddress; + OFSocketAddress _remoteAddress; bool _hasRemoteAddress; OF_RESERVE_IVARS(OFHTTPRequest, 4) } /** @@ -109,12 +109,11 @@ /** * @brief The remote address from which the request originates. * * @note The setter creates a copy of the remote address. */ -@property OF_NULLABLE_PROPERTY (nonatomic) - const of_socket_address_t *remoteAddress; +@property OF_NULLABLE_PROPERTY (nonatomic) const OFSocketAddress *remoteAddress; /** * @brief Creates a new OFHTTPRequest. * * @return A new, autoreleased OFHTTPRequest Index: src/OFHTTPRequest.m ================================================================== --- src/OFHTTPRequest.m +++ src/OFHTTPRequest.m @@ -121,19 +121,19 @@ [_headers release]; [super dealloc]; } -- (void)setRemoteAddress: (const of_socket_address_t *)remoteAddress +- (void)setRemoteAddress: (const OFSocketAddress *)remoteAddress { _hasRemoteAddress = (remoteAddress != NULL); if (_hasRemoteAddress) _remoteAddress = *remoteAddress; } -- (const of_socket_address_t *)remoteAddress +- (const OFSocketAddress *)remoteAddress { if (_hasRemoteAddress) return &_remoteAddress; return NULL; @@ -175,11 +175,11 @@ ![request->_URL isEqual: _URL] || ![request->_headers isEqual: _headers]) return false; if (request.remoteAddress != self.remoteAddress && - !of_socket_address_equal(request.remoteAddress, self.remoteAddress)) + !OFSocketAddressEqual(request.remoteAddress, self.remoteAddress)) return false; return true; } @@ -193,11 +193,11 @@ OF_HASH_ADD(hash, _protocolVersion.major); OF_HASH_ADD(hash, _protocolVersion.minor); OF_HASH_ADD_HASH(hash, _URL.hash); OF_HASH_ADD_HASH(hash, _headers.hash); if (_hasRemoteAddress) - OF_HASH_ADD_HASH(hash, of_socket_address_hash(&_remoteAddress)); + OF_HASH_ADD_HASH(hash, OFSocketAddressHash(&_remoteAddress)); OF_HASH_FINALIZE(hash); return hash; } @@ -258,12 +258,11 @@ indentedHeaders = [_headers.description stringByReplacingOccurrencesOfString: @"\n" withString: @"\n\t"]; if (_hasRemoteAddress) - remoteAddress = - of_socket_address_ip_string(&_remoteAddress, NULL); + remoteAddress = OFSocketAddressString(&_remoteAddress); else remoteAddress = nil; ret = [[OFString alloc] initWithFormat: @"<%@:\n\tURL = %@\n" Index: src/OFHostAddressResolver.m ================================================================== --- src/OFHostAddressResolver.m +++ src/OFHostAddressResolver.m @@ -64,23 +64,23 @@ return (dots >= minNumberOfDotsInAbsoluteName); } static bool addressForRecord(OF_KINDOF(OFDNSResourceRecord *) record, - const of_socket_address_t **address, OFSocketAddressFamily addressFamily) + const OFSocketAddress **address, OFSocketAddressFamily addressFamily) { switch ([record recordType]) { #ifdef OF_HAVE_IPV6 case OF_DNS_RECORD_TYPE_AAAA: - if (addressFamily != OF_SOCKET_ADDRESS_FAMILY_IPV6 && - addressFamily != OF_SOCKET_ADDRESS_FAMILY_ANY) + if (addressFamily != OFSocketAddressFamilyIPv6 && + addressFamily != OFSocketAddressFamilyAny) return false; break; #endif case OF_DNS_RECORD_TYPE_A: - if (addressFamily != OF_SOCKET_ADDRESS_FAMILY_IPV4 && - addressFamily != OF_SOCKET_ADDRESS_FAMILY_ANY) + if (addressFamily != OFSocketAddressFamilyIPv4 && + addressFamily != OFSocketAddressFamilyAny) return false; break; default: return false; } @@ -160,12 +160,12 @@ _host, searchDomain]; } else domainName = _host; #ifdef OF_HAVE_IPV6 - if (_addressFamily == OF_SOCKET_ADDRESS_FAMILY_IPV6 || - _addressFamily == OF_SOCKET_ADDRESS_FAMILY_ANY) { + if (_addressFamily == OFSocketAddressFamilyIPv6 || + _addressFamily == OFSocketAddressFamilyAny) { OFDNSQuery *query = [OFDNSQuery queryWithDomainName: domainName DNSClass: OF_DNS_CLASS_IN recordType: OF_DNS_RECORD_TYPE_AAAA]; _numExpectedResponses++; @@ -173,12 +173,12 @@ runLoopMode: _runLoopMode delegate: self]; } #endif - if (_addressFamily == OF_SOCKET_ADDRESS_FAMILY_IPV4 || - _addressFamily == OF_SOCKET_ADDRESS_FAMILY_ANY) { + if (_addressFamily == OFSocketAddressFamilyIPv4 || + _addressFamily == OFSocketAddressFamilyAny) { OFDNSQuery *query = [OFDNSQuery queryWithDomainName: domainName DNSClass: OF_DNS_CLASS_IN recordType: OF_DNS_RECORD_TYPE_A]; _numExpectedResponses++; @@ -204,11 +204,11 @@ return; } for (OF_KINDOF(OFDNSResourceRecord *) record in [response.answerRecords objectForKey: query.domainName]) { - const of_socket_address_t *address = NULL; + const OFSocketAddress *address = NULL; OFDNSQuery *CNAMEQuery; if ([record DNSClass] != OF_DNS_CLASS_IN) continue; @@ -266,17 +266,16 @@ { void *pool = objc_autoreleasePoolPush(); OFArray OF_GENERIC(OFString *) *aliases; @try { - of_socket_address_t address = - of_socket_address_parse_ip(_host, 0); + OFSocketAddress address = OFSocketAddressParseIP(_host, 0); OFData *addresses = nil; id exception = nil; if (_addressFamily == address.family || - _addressFamily == OF_SOCKET_ADDRESS_FAMILY_ANY) + _addressFamily == OFSocketAddressFamilyAny) addresses = [OFData dataWithItems: &address count: 1 itemSize: sizeof(address)]; else exception = [OFInvalidArgumentException exception]; @@ -289,24 +288,24 @@ } @catch (OFInvalidFormatException *e) { } if ((aliases = [_settings->_staticHosts objectForKey: _host]) != nil) { OFMutableData *addresses = [OFMutableData - dataWithItemSize: sizeof(of_socket_address_t)]; + dataWithItemSize: sizeof(OFSocketAddress)]; id exception = nil; for (OFString *alias in aliases) { - of_socket_address_t address; + OFSocketAddress address; @try { - address = of_socket_address_parse_ip(alias, 0); + address = OFSocketAddressParseIP(alias, 0); } @catch (OFInvalidFormatException *e) { continue; } if (_addressFamily != address.family && - _addressFamily != OF_SOCKET_ADDRESS_FAMILY_ANY) + _addressFamily != OFSocketAddressFamilyAny) continue; [addresses addItem: &address]; } @@ -327,11 +326,11 @@ return; } _isFQDN = isFQDN(_host, _settings->_minNumberOfDotsInAbsoluteName); _addresses = [[OFMutableData alloc] - initWithItemSize: sizeof(of_socket_address_t)]; + initWithItemSize: sizeof(OFSocketAddress)]; [self sendQueries]; objc_autoreleasePoolPop(pool); } Index: src/OFIPSocketAsyncConnector.h ================================================================== --- src/OFIPSocketAsyncConnector.h +++ src/OFIPSocketAsyncConnector.h @@ -18,13 +18,13 @@ #import "OFRunLoop+Private.h" OF_ASSUME_NONNULL_BEGIN @protocol OFIPSocketAsyncConnecting -- (bool)of_createSocketForAddress: (const of_socket_address_t *)address +- (bool)of_createSocketForAddress: (const OFSocketAddress *)address errNo: (int *)errNo; -- (bool)of_connectSocketToAddress: (const of_socket_address_t *)address +- (bool)of_connectSocketToAddress: (const OFSocketAddress *)address errNo: (int *)errNo; - (void)of_closeSocket; @end @interface OFIPSocketAsyncConnector: OFObject = _socketAddresses.count) { _exception = [[OFConnectionFailedException alloc] initWithHost: _host @@ -224,12 +224,11 @@ } - (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode { @try { - of_socket_address_t address = - of_socket_address_parse_ip(_host, _port); + OFSocketAddress address = OFSocketAddressParseIP(_host, _port); _socketAddresses = [[OFData alloc] initWithItems: &address count: 1 itemSize: sizeof(address)]; @@ -239,10 +238,10 @@ } @catch (OFInvalidFormatException *e) { } [[OFThread DNSResolver] asyncResolveAddressesForHost: _host - addressFamily: OF_SOCKET_ADDRESS_FAMILY_ANY + addressFamily: OFSocketAddressFamilyAny runLoopMode: runLoopMode delegate: self]; } @end Index: src/OFIPXSocket.h ================================================================== --- src/OFIPXSocket.h +++ src/OFIPXSocket.h @@ -30,15 +30,15 @@ /** * @class OFIPXSocket OFIPXSocket.h ObjFW/OFIPXSocket.h * * @brief A class which provides methods to create and use IPX sockets. * - * Addresses are of type @ref of_socket_address_t. You can use - * @ref of_socket_address_ipx to create an address or - * @ref of_socket_address_get_ipx_network to get the IPX network, - * @ref of_socket_address_get_ipx_node to get the IPX node and - * @ref of_socket_address_get_port to get the port (sometimes also called + * Addresses are of type @ref OFSocketAddress. You can use + * @ref OFSocketAddressMakeIPX to create an address or + * @ref OFSocketAddressIPXNetwork to get the IPX network, + * @ref OFSocketAddressIpxNode to get the IPX node and + * @ref OFSocketAddressPort to get the port (sometimes also called * socket number). * * @warning Even though the OFCopying protocol is implemented, it does *not* * return an independent copy of the socket, but instead retains it. * This is so that the socket can be used as a key for a dictionary, @@ -70,10 +70,9 @@ * @param port The port (sometimes called socket number) to bind to. 0 means to * pick one and return it. * @param packetType The packet type to use on the socket * @return The address on which this socket can be reached */ -- (of_socket_address_t)bindToPort: (uint16_t)port - packetType: (uint8_t)packetType; +- (OFSocketAddress)bindToPort: (uint16_t)port packetType: (uint8_t)packetType; @end OF_ASSUME_NONNULL_END Index: src/OFIPXSocket.m ================================================================== --- src/OFIPXSocket.m +++ src/OFIPXSocket.m @@ -30,24 +30,23 @@ #import "socket_helpers.h" @implementation OFIPXSocket @dynamic delegate; -- (of_socket_address_t)bindToPort: (uint16_t)port - packetType: (uint8_t)packetType +- (OFSocketAddress)bindToPort: (uint16_t)port packetType: (uint8_t)packetType { const unsigned char zeroNode[IPX_NODE_LEN] = { 0 }; - of_socket_address_t address; + OFSocketAddress address; int protocol = 0; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) int flags; #endif if (_socket != INVALID_SOCKET) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; - address = of_socket_address_ipx(zeroNode, 0, port); + address = OFSocketAddressMakeIPX(zeroNode, 0, port); #ifdef OF_WINDOWS protocol = NSPROTO_IPX + packetType; #else _packetType = address.sockaddr.ipx.sipx_type = packetType; @@ -79,11 +78,11 @@ socket: self errNo: errNo]; } memset(&address, 0, sizeof(address)); - address.family = OF_SOCKET_ADDRESS_FAMILY_IPX; + address.family = OFSocketAddressFamilyIPX; address.length = (socklen_t)sizeof(address.sockaddr); if (of_getsockname(_socket, &address.sockaddr.sockaddr, &address.length) != 0) { int errNo = of_socket_errno(); @@ -111,19 +110,19 @@ } #ifndef OF_WINDOWS - (void)sendBuffer: (const void *)buffer length: (size_t)length - receiver: (const of_socket_address_t *)receiver + receiver: (const OFSocketAddress *)receiver { - of_socket_address_t fixedReceiver; + OFSocketAddress fixedReceiver; memcpy(&fixedReceiver, receiver, sizeof(fixedReceiver)); /* If it's not IPX, no fix-up needed - it will fail anyway. */ - if (fixedReceiver.family == OF_SOCKET_ADDRESS_FAMILY_IPX) + if (fixedReceiver.family == OFSocketAddressFamilyIPX) fixedReceiver.sockaddr.ipx.sipx_type = _packetType; [super sendBuffer: buffer length: length receiver: &fixedReceiver]; } #endif @end Index: src/OFRunLoop+Private.h ================================================================== --- src/OFRunLoop+Private.h +++ src/OFRunLoop+Private.h @@ -95,11 +95,11 @@ block: (nullable OFDatagramSocketAsyncReceiveBlock)block # endif delegate: (nullable id ) delegate; + (void)of_addAsyncSendForDatagramSocket: (OFDatagramSocket *)socket data: (OFData *)data - receiver: (const of_socket_address_t *)receiver + receiver: (const OFSocketAddress *)receiver mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (nullable OFDatagramSocketAsyncSendDataBlock)block # endif delegate: (nullable id )delegate; Index: src/OFRunLoop.m ================================================================== --- src/OFRunLoop.m +++ src/OFRunLoop.m @@ -171,11 +171,11 @@ @public # ifdef OF_HAVE_BLOCKS OFDatagramSocketAsyncSendDataBlock _block; # endif OFData *_data; - of_socket_address_t _receiver; + OFSocketAddress _receiver; } @end @interface OFRunLoopPacketReceiveQueueItem: OFRunLoopQueueItem { @@ -788,11 +788,11 @@ @implementation OFRunLoopDatagramReceiveQueueItem - (bool)handleObject: (id)object { size_t length; - of_socket_address_t address; + OFSocketAddress address; id exception = nil; @try { length = [object receiveIntoBuffer: _buffer length: _length @@ -1238,11 +1238,11 @@ QUEUE_ITEM } + (void)of_addAsyncSendForDatagramSocket: (OFDatagramSocket *)sock data: (OFData *)data - receiver: (const of_socket_address_t *)receiver + receiver: (const OFSocketAddress *)receiver mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (OFDatagramSocketAsyncSendDataBlock)block # endif delegate: (id )delegate Index: src/OFSPXSocket.h ================================================================== --- src/OFSPXSocket.h +++ src/OFSPXSocket.h @@ -157,9 +157,9 @@ * * @param port The port (sometimes called socket number) to bind to. 0 means to * pick one and return it. * @return The address on which this socket can be reached */ -- (of_socket_address_t)bindToPort: (uint16_t)port; +- (OFSocketAddress)bindToPort: (uint16_t)port; @end OF_ASSUME_NONNULL_END Index: src/OFSPXSocket.m ================================================================== --- src/OFSPXSocket.m +++ src/OFSPXSocket.m @@ -34,13 +34,13 @@ #endif #define SPX_PACKET_TYPE 5 @interface OFSPXSocket () -- (int)of_createSocketForAddress: (const of_socket_address_t *)address +- (int)of_createSocketForAddress: (const OFSocketAddress *)address errNo: (int *)errNo; -- (bool)of_connectSocketToAddress: (const of_socket_address_t *)address +- (bool)of_connectSocketToAddress: (const OFSocketAddress *)address errNo: (int *)errNo; - (void)of_closeSocket; @end OF_DIRECT_MEMBERS @@ -103,12 +103,12 @@ [super dealloc]; } - (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode { - of_socket_address_t address = - of_socket_address_ipx(_node, _network, _port); + OFSocketAddress address = + OFSocketAddressMakeIPX(_node, _network, _port); id exception = nil; int errNo; if (![_socket of_createSocketForAddress: &address errNo: &errNo]) { exception = [self of_connectionFailedExceptionForErrNo: errNo]; @@ -172,11 +172,11 @@ @end @implementation OFSPXSocket @dynamic delegate; -- (int)of_createSocketForAddress: (const of_socket_address_t *)address +- (int)of_createSocketForAddress: (const OFSocketAddress *)address errNo: (int *)errNo { #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif @@ -196,11 +196,11 @@ #endif return true; } -- (bool)of_connectSocketToAddress: (const of_socket_address_t *)address +- (bool)of_connectSocketToAddress: (const OFSocketAddress *)address errNo: (int *)errNo { if (_socket == INVALID_SOCKET) @throw [OFNotOpenException exceptionWithObject: self]; @@ -221,12 +221,11 @@ - (void)connectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port { - of_socket_address_t address = - of_socket_address_ipx(node, network, port); + OFSocketAddress address = OFSocketAddressMakeIPX(node, network, port); int errNo; if (![self of_createSocketForAddress: &address errNo: &errNo]) @throw [OFConnectionFailedException exceptionWithNode: node @@ -308,22 +307,22 @@ objc_autoreleasePoolPop(pool); } #endif -- (of_socket_address_t)bindToPort: (uint16_t)port +- (OFSocketAddress)bindToPort: (uint16_t)port { const unsigned char zeroNode[IPX_NODE_LEN] = { 0 }; - of_socket_address_t address; + OFSocketAddress address; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) int flags; #endif if (_socket != INVALID_SOCKET) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; - address = of_socket_address_ipx(zeroNode, 0, port); + address = OFSocketAddressMakeIPX(zeroNode, 0, port); if ((_socket = socket(address.sockaddr.sockaddr.sa_family, SOCK_SEQPACKET | SOCK_CLOEXEC, NSPROTO_SPX)) == INVALID_SOCKET) @throw [OFBindFailedException exceptionWithPort: port @@ -349,11 +348,11 @@ socket: self errNo: errNo]; } memset(&address, 0, sizeof(address)); - address.family = OF_SOCKET_ADDRESS_FAMILY_IPX; + address.family = OFSocketAddressFamilyIPX; address.length = (socklen_t)sizeof(address.sockaddr); if (of_getsockname(_socket, &address.sockaddr.sockaddr, &address.length) != 0) { int errNo = of_socket_errno(); Index: src/OFSPXStreamSocket.h ================================================================== --- src/OFSPXStreamSocket.h +++ src/OFSPXStreamSocket.h @@ -162,9 +162,9 @@ * * @param port The port (sometimes called socket number) to bind to. 0 means to * pick one and return it. * @return The address on which this socket can be reached */ -- (of_socket_address_t)bindToPort: (uint16_t)port; +- (OFSocketAddress)bindToPort: (uint16_t)port; @end OF_ASSUME_NONNULL_END Index: src/OFSPXStreamSocket.m ================================================================== --- src/OFSPXStreamSocket.m +++ src/OFSPXStreamSocket.m @@ -34,13 +34,13 @@ #endif #define SPX_PACKET_TYPE 5 @interface OFSPXStreamSocket () -- (int)of_createSocketForAddress: (const of_socket_address_t *)address +- (int)of_createSocketForAddress: (const OFSocketAddress *)address errNo: (int *)errNo; -- (bool)of_connectSocketToAddress: (const of_socket_address_t *)address +- (bool)of_connectSocketToAddress: (const OFSocketAddress *)address errNo: (int *)errNo; - (void)of_closeSocket; @end OF_DIRECT_MEMBERS @@ -104,12 +104,12 @@ [super dealloc]; } - (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode { - of_socket_address_t address = - of_socket_address_ipx(_node, _network, _port); + OFSocketAddress address = + OFSocketAddressMakeIPX(_node, _network, _port); id exception = nil; int errNo; if (![_socket of_createSocketForAddress: &address errNo: &errNo]) { exception = [self of_connectionFailedExceptionForErrNo: errNo]; @@ -174,11 +174,11 @@ @end @implementation OFSPXStreamSocket @dynamic delegate; -- (int)of_createSocketForAddress: (const of_socket_address_t *)address +- (int)of_createSocketForAddress: (const OFSocketAddress *)address errNo: (int *)errNo { #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif @@ -198,11 +198,11 @@ #endif return true; } -- (bool)of_connectSocketToAddress: (const of_socket_address_t *)address +- (bool)of_connectSocketToAddress: (const OFSocketAddress *)address errNo: (int *)errNo { if (_socket == INVALID_SOCKET) @throw [OFNotOpenException exceptionWithObject: self]; @@ -223,12 +223,11 @@ - (void)connectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port { - of_socket_address_t address = - of_socket_address_ipx(node, network, port); + OFSocketAddress address = OFSocketAddressMakeIPX(node, network, port); int errNo; if (![self of_createSocketForAddress: &address errNo: &errNo]) @throw [OFConnectionFailedException exceptionWithNode: node @@ -310,22 +309,22 @@ objc_autoreleasePoolPop(pool); } #endif -- (of_socket_address_t)bindToPort: (uint16_t)port +- (OFSocketAddress)bindToPort: (uint16_t)port { const unsigned char zeroNode[IPX_NODE_LEN] = { 0 }; - of_socket_address_t address; + OFSocketAddress address; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) int flags; #endif if (_socket != INVALID_SOCKET) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; - address = of_socket_address_ipx(zeroNode, 0, port); + address = OFSocketAddressMakeIPX(zeroNode, 0, port); if ((_socket = socket(address.sockaddr.sockaddr.sa_family, SOCK_STREAM | SOCK_CLOEXEC, NSPROTO_SPX)) == INVALID_SOCKET) @throw [OFBindFailedException exceptionWithPort: port @@ -351,11 +350,11 @@ socket: self errNo: errNo]; } memset(&address, 0, sizeof(address)); - address.family = OF_SOCKET_ADDRESS_FAMILY_IPX; + address.family = OFSocketAddressFamilyIPX; address.length = (socklen_t)sizeof(address.sockaddr); if (of_getsockname(_socket, &address.sockaddr.sockaddr, &address.length) != 0) { int errNo = of_socket_errno(); Index: src/OFSequencedPacketSocket.h ================================================================== --- src/OFSequencedPacketSocket.h +++ src/OFSequencedPacketSocket.h @@ -127,11 +127,11 @@ @interface OFSequencedPacketSocket: OFObject { OFSocketHandle _socket; bool _canBlock, _listening; - of_socket_address_t _remoteAddress; + OFSocketAddress _remoteAddress; id _Nullable _delegate; OF_RESERVE_IVARS(OFSequencedPacketSocket, 4) } /** @@ -149,11 +149,11 @@ /** * @brief The remote address. * * @note This only works for accepted sockets! */ -@property (readonly, nonatomic) const of_socket_address_t *remoteAddress; +@property (readonly, nonatomic) const OFSocketAddress *remoteAddress; /** * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are Index: src/OFSequencedPacketSocket.m ================================================================== --- src/OFSequencedPacketSocket.m +++ src/OFSequencedPacketSocket.m @@ -362,25 +362,24 @@ assert(client->_remoteAddress.length <= (socklen_t)sizeof(client->_remoteAddress.sockaddr)); switch (client->_remoteAddress.sockaddr.sockaddr.sa_family) { case AF_INET: - client->_remoteAddress.family = OF_SOCKET_ADDRESS_FAMILY_IPV4; + client->_remoteAddress.family = OFSocketAddressFamilyIPv4; break; #ifdef OF_HAVE_IPV6 case AF_INET6: - client->_remoteAddress.family = OF_SOCKET_ADDRESS_FAMILY_IPV6; + client->_remoteAddress.family = OFSocketAddressFamilyIPv6; break; #endif #ifdef OF_HAVE_IPX case AF_IPX: - client->_remoteAddress.family = OF_SOCKET_ADDRESS_FAMILY_IPX; + client->_remoteAddress.family = OFSocketAddressFamilyIPX; break; #endif default: - client->_remoteAddress.family = - OF_SOCKET_ADDRESS_FAMILY_UNKNOWN; + client->_remoteAddress.family = OFSocketAddressFamilyUnknown; break; } return client; } @@ -413,11 +412,11 @@ block: block delegate: nil]; } #endif -- (const of_socket_address_t *)remoteAddress +- (const OFSocketAddress *)remoteAddress { if (_socket == INVALID_SOCKET) @throw [OFNotOpenException exceptionWithObject: self]; if (_remoteAddress.length == 0) Index: src/OFStreamSocket.h ================================================================== --- src/OFStreamSocket.h +++ src/OFStreamSocket.h @@ -66,11 +66,11 @@ @interface OFStreamSocket: OFStream { OFSocketHandle _socket; bool _atEndOfStream, _listening; - of_socket_address_t _remoteAddress; + OFSocketAddress _remoteAddress; OF_RESERVE_IVARS(OFStreamSocket, 4) } /** * @brief Whether the socket is a listening socket. @@ -80,11 +80,11 @@ /** * @brief The remote address. * * @note This only works for accepted sockets! */ -@property (readonly, nonatomic) const of_socket_address_t *remoteAddress; +@property (readonly, nonatomic) const OFSocketAddress *remoteAddress; /** * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are Index: src/OFStreamSocket.m ================================================================== --- src/OFStreamSocket.m +++ src/OFStreamSocket.m @@ -286,25 +286,24 @@ assert(client->_remoteAddress.length <= (socklen_t)sizeof(client->_remoteAddress.sockaddr)); switch (client->_remoteAddress.sockaddr.sockaddr.sa_family) { case AF_INET: - client->_remoteAddress.family = OF_SOCKET_ADDRESS_FAMILY_IPV4; + client->_remoteAddress.family = OFSocketAddressFamilyIPv4; break; #ifdef OF_HAVE_IPV6 case AF_INET6: - client->_remoteAddress.family = OF_SOCKET_ADDRESS_FAMILY_IPV6; + client->_remoteAddress.family = OFSocketAddressFamilyIPv6; break; #endif #ifdef OF_HAVE_IPX case AF_IPX: - client->_remoteAddress.family = OF_SOCKET_ADDRESS_FAMILY_IPX; + client->_remoteAddress.family = OFSocketAddressFamilyIPX; break; #endif default: - client->_remoteAddress.family = - OF_SOCKET_ADDRESS_FAMILY_UNKNOWN; + client->_remoteAddress.family = OFSocketAddressFamilyUnknown; break; } return client; } @@ -336,11 +335,11 @@ block: block delegate: nil]; } #endif -- (const of_socket_address_t *)remoteAddress +- (const OFSocketAddress *)remoteAddress { if (_socket == INVALID_SOCKET) @throw [OFNotOpenException exceptionWithObject: self]; if (_remoteAddress.length == 0) Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -134,11 +134,11 @@ [_SOCKS5Host release]; [super dealloc]; } -- (bool)of_createSocketForAddress: (const of_socket_address_t *)address +- (bool)of_createSocketForAddress: (const OFSocketAddress *)address errNo: (int *)errNo { #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif @@ -158,11 +158,11 @@ #endif return true; } -- (bool)of_connectSocketToAddress: (const of_socket_address_t *)address +- (bool)of_connectSocketToAddress: (const OFSocketAddress *)address errNo: (int *)errNo { if (_socket == INVALID_SOCKET) @throw [OFNotOpenException exceptionWithObject: self]; @@ -300,11 +300,11 @@ - (uint16_t)bindToHost: (OFString *)host port: (uint16_t)port { const int one = 1; void *pool = objc_autoreleasePoolPush(); OFData *socketAddresses; - of_socket_address_t address; + OFSocketAddress address; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif if (_socket != INVALID_SOCKET) @@ -314,14 +314,14 @@ @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; socketAddresses = [[OFThread DNSResolver] resolveAddressesForHost: host - addressFamily: OF_SOCKET_ADDRESS_FAMILY_ANY]; + addressFamily: OFSocketAddressFamilyAny]; - address = *(of_socket_address_t *)[socketAddresses itemAtIndex: 0]; - of_socket_address_set_port(&address, port); + address = *(OFSocketAddress *)[socketAddresses itemAtIndex: 0]; + OFSocketAddressSetPort(&address, port); if ((_socket = socket(address.sockaddr.sockaddr.sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0)) == INVALID_SOCKET) @throw [OFBindFailedException exceptionWithHost: host @@ -361,11 +361,11 @@ int ret; while (rnd < 1024) rnd = (uint16_t)rand(); - of_socket_address_set_port(&address, rnd); + OFSocketAddressSetPort(&address, rnd); if ((ret = bind(_socket, &address.sockaddr.sockaddr, address.length)) == 0) { port = rnd; break; Index: src/OFUDPSocket+Private.h ================================================================== --- src/OFUDPSocket+Private.h +++ src/OFUDPSocket+Private.h @@ -17,10 +17,10 @@ OF_ASSUME_NONNULL_BEGIN OF_DIRECT_MEMBERS @interface OFUDPSocket () -- (uint16_t)of_bindToAddress: (of_socket_address_t *)address +- (uint16_t)of_bindToAddress: (OFSocketAddress *)address extraType: (int)extraType; @end OF_ASSUME_NONNULL_END Index: src/OFUDPSocket.h ================================================================== --- src/OFUDPSocket.h +++ src/OFUDPSocket.h @@ -30,15 +30,16 @@ /** * @class OFUDPSocket OFUDPSocket.h ObjFW/OFUDPSocket.h * * @brief A class which provides methods to create and use UDP sockets. * - * Addresses are of type @ref of_socket_address_t. You can use the current - * thread's @ref OFDNSResolver to create an address for a host / port pair and - * @ref of_socket_address_ip_string to get the IP string / port pair for an - * address. If you want to compare two addresses, you can use @ref - * of_socket_address_equal and you can use @ref of_socket_address_hash to get a + * Addresses are of type @ref OFSocketAddress. You can use the current thread's + * @ref OFDNSResolver to create an address for a host / port pair, + * @ref OFSocketAddressString to get the IP address string for an address and + * @ref OFSocketAddressPort to get the port for an address. If you want to + * compare two addresses, you can use + * @ref OFEqualSocketAddress and you can use @ref OFSocketAddressHash to get a * hash to use in e.g. @ref OFMapTable. * * @warning Even though the OFCopying protocol is implemented, it does *not* * return an independent copy of the socket, but instead retains it. * This is so that the socket can be used as a key for a dictionary, Index: src/OFUDPSocket.m ================================================================== --- src/OFUDPSocket.m +++ src/OFUDPSocket.m @@ -39,29 +39,26 @@ #import "socket_helpers.h" @implementation OFUDPSocket @dynamic delegate; -- (uint16_t)of_bindToAddress: (of_socket_address_t *)address +- (uint16_t)of_bindToAddress: (OFSocketAddress *)address extraType: (int)extraType OF_DIRECT { void *pool = objc_autoreleasePoolPush(); - OFString *host; uint16_t port; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif if ((_socket = socket(address->sockaddr.sockaddr.sa_family, - SOCK_DGRAM | SOCK_CLOEXEC | extraType, 0)) == INVALID_SOCKET) { - host = of_socket_address_ip_string(address, &port); + SOCK_DGRAM | SOCK_CLOEXEC | extraType, 0)) == INVALID_SOCKET) @throw [OFBindFailedException - exceptionWithHost: host - port: port + exceptionWithHost: OFSocketAddressString(address) + port: OFSocketAddressPort(address) socket: self errNo: of_socket_errno()]; - } _canBlock = true; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) /* {} needed to avoid warning with Clang 10 if next #if is false. */ @@ -69,24 +66,24 @@ fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); } #endif #if defined(OF_HPUX) || defined(OF_WII) || defined(OF_NINTENDO_3DS) - if (of_socket_address_get_port(address) != 0) { + if (OFSocketAddressPort(address) != 0) { #endif if (bind(_socket, &address->sockaddr.sockaddr, address->length) != 0) { int errNo = of_socket_errno(); closesocket(_socket); _socket = INVALID_SOCKET; - host = of_socket_address_ip_string(address, &port); - @throw [OFBindFailedException exceptionWithHost: host - port: port - socket: self - errNo: errNo]; + @throw [OFBindFailedException + exceptionWithHost: OFSocketAddressString(address) + port: OFSocketAddressPort(address) + socket: self + errNo: errNo]; } #if defined(OF_HPUX) || defined(OF_WII) || defined(OF_NINTENDO_3DS) } else { for (;;) { uint16_t rnd = 0; @@ -93,26 +90,26 @@ int ret; while (rnd < 1024) rnd = (uint16_t)rand(); - of_socket_address_set_port(address, rnd); + OFSocketAddressSetPort(address, rnd); if ((ret = bind(_socket, &address->sockaddr.sockaddr, address->length)) == 0) { port = rnd; break; } if (of_socket_errno() != EADDRINUSE) { int errNo = of_socket_errno(); + OFString *host = OFSocketAddressString(address); + uint16_t port = OFSocketAddressPort(port); closesocket(_socket); _socket = INVALID_SOCKET; - host = of_socket_address_ip_string( - address, &port); @throw [OFBindFailedException exceptionWithHost: host port: port socket: self errNo: errNo]; @@ -121,11 +118,11 @@ } #endif objc_autoreleasePoolPop(pool); - if ((port = of_socket_address_get_port(address)) > 0) + if ((port = OFSocketAddressPort(address)) > 0) return port; #if !defined(OF_HPUX) && !defined(OF_WII) && !defined(OF_NINTENDO_3DS) memset(address, 0, sizeof(*address)); @@ -135,15 +132,15 @@ int errNo = of_socket_errno(); closesocket(_socket); _socket = INVALID_SOCKET; - host = of_socket_address_ip_string(address, &port); - @throw [OFBindFailedException exceptionWithHost: host - port: port - socket: self - errNo: errNo]; + @throw [OFBindFailedException + exceptionWithHost: OFSocketAddressString(address) + port: OFSocketAddressPort(address) + socket: self + errNo: errNo]; } if (address->sockaddr.sockaddr.sa_family == AF_INET) return OF_BSWAP16_IF_LE(address->sockaddr.in.sin_port); # ifdef OF_HAVE_IPV6 @@ -152,46 +149,46 @@ # endif else { closesocket(_socket); _socket = INVALID_SOCKET; - host = of_socket_address_ip_string(address, &port); - @throw [OFBindFailedException exceptionWithHost: host - port: port - socket: self - errNo: EAFNOSUPPORT]; + @throw [OFBindFailedException + exceptionWithHost: OFSocketAddressString(address) + port: OFSocketAddressPort(address) + socket: self + errNo: EAFNOSUPPORT]; } #else closesocket(_socket); _socket = INVALID_SOCKET; - host = of_socket_address_ip_string(address, &port); - @throw [OFBindFailedException exceptionWithHost: host - port: port - socket: self - errNo: EADDRNOTAVAIL]; + @throw [OFBindFailedException + exceptionWithHost: OFSocketAddressString(address) + port: OFSocketAddressPort(address) + socket: self + errNo: EADDRNOTAVAIL]; #endif } - (uint16_t)bindToHost: (OFString *)host port: (uint16_t)port { void *pool = objc_autoreleasePoolPush(); OFData *socketAddresses; - of_socket_address_t address; + OFSocketAddress address; if (_socket != INVALID_SOCKET) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; socketAddresses = [[OFThread DNSResolver] resolveAddressesForHost: host - addressFamily: OF_SOCKET_ADDRESS_FAMILY_ANY]; + addressFamily: OFSocketAddressFamilyAny]; - address = *(of_socket_address_t *)[socketAddresses itemAtIndex: 0]; - of_socket_address_set_port(&address, port); + address = *(OFSocketAddress *)[socketAddresses itemAtIndex: 0]; + OFSocketAddressSetPort(&address, port); port = [self of_bindToAddress: &address extraType: 0]; objc_autoreleasePoolPop(pool); return port; } @end Index: src/socket.h ================================================================== --- src/socket.h +++ src/socket.h @@ -82,19 +82,19 @@ /** * @brief A socket address family. */ typedef enum { /** An unknown address family. */ - OF_SOCKET_ADDRESS_FAMILY_UNKNOWN, + OFSocketAddressFamilyUnknown, /** IPv4 */ - OF_SOCKET_ADDRESS_FAMILY_IPV4, + OFSocketAddressFamilyIPv4, /** IPv6 */ - OF_SOCKET_ADDRESS_FAMILY_IPV6, + OFSocketAddressFamilyIPv6, /** IPX */ - OF_SOCKET_ADDRESS_FAMILY_IPX, + OFSocketAddressFamilyIPX, /** Any address family */ - OF_SOCKET_ADDRESS_FAMILY_ANY = 255 + OFSocketAddressFamilyAny = 255 } OFSocketAddressFamily; #ifndef OF_HAVE_IPV6 struct sockaddr_in6 { sa_family_t sin6_family; @@ -124,15 +124,15 @@ # define sipx_node sa_nodenum # define sipx_port sa_socket #endif /** - * @struct of_socket_address_t socket.h ObjFW/socket.h + * @struct OFSocketAddress socket.h ObjFW/socket.h * * @brief A struct which represents a host / port pair for a socket. */ -struct OF_BOXABLE of_socket_address_t { +struct OF_BOXABLE OFSocketAddress { /* * Even though struct sockaddr contains the family, we need to use our * own family, as we need to support storing an IPv6 address on systems * that don't support IPv6. These may not have AF_INET6 defined and we * can't just define it, as the value is system-dependent and might @@ -145,143 +145,135 @@ struct sockaddr_in6 in6; struct sockaddr_ipx ipx; } sockaddr; socklen_t length; }; -typedef struct of_socket_address_t of_socket_address_t; +typedef struct OFSocketAddress OFSocketAddress; #ifdef __cplusplus extern "C" { #endif /** - * @brief Parses the specified IP and port into an of_socket_address_t. + * @brief Parses the specified IP (either v4 or v6) and port into an + * @ref OFSocketAddress. * * @param IP The IP to parse * @param port The port to use - * @return The parsed IP and port as an of_socket_address_t + * @return The parsed IP and port as an OFSocketAddress */ -extern of_socket_address_t of_socket_address_parse_ip( - OFString *IP, uint16_t port); +extern OFSocketAddress OFSocketAddressParseIP(OFString *IP, uint16_t port); /** - * @brief Parses the specified IPv4 and port into an of_socket_address_t. + * @brief Parses the specified IPv4 and port into an @ref OFSocketAddress. * * @param IP The IPv4 to parse * @param port The port to use - * @return The parsed IPv4 and port as an of_socket_address_t + * @return The parsed IPv4 and port as an OFSocketAddress */ -extern of_socket_address_t of_socket_address_parse_ipv4( - OFString *IP, uint16_t port); +extern OFSocketAddress OFSocketAddressParseIPv4(OFString *IP, uint16_t port); /** - * @brief Parses the specified IPv6 and port into an of_socket_address_t. + * @brief Parses the specified IPv6 and port into an @ref OFSocketAddress. * * @param IP The IPv6 to parse * @param port The port to use - * @return The parsed IPv6 and port as an of_socket_address_t + * @return The parsed IPv6 and port as an OFSocketAddress */ -extern of_socket_address_t of_socket_address_parse_ipv6( - OFString *IP, uint16_t port); +extern OFSocketAddress OFSocketAddressParseIPv6(OFString *IP, uint16_t port); /** * @brief Creates an IPX address for the specified network, node 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 */ -extern of_socket_address_t of_socket_address_ipx( +extern OFSocketAddress OFSocketAddressMakeIPX( const unsigned char node[_Nonnull IPX_NODE_LEN], uint32_t network, uint16_t port); /** - * @brief Compares two of_socket_address_t for equality. + * @brief Compares two OFSocketAddress for equality. * * @param address1 The address to compare with the second address * @param address2 The second address * @return Whether the two addresses are equal */ -extern bool of_socket_address_equal( - const of_socket_address_t *_Nonnull address1, - const of_socket_address_t *_Nonnull address2); +extern bool OFSocketAddressEqual(const OFSocketAddress *_Nonnull address1, + const OFSocketAddress *_Nonnull address2); /** - * @brief Returns the hash for the specified of_socket_address_t. + * @brief Returns the hash for the specified @ref OFSocketAddress. * * @param address The address to hash - * @return The hash for the specified of_socket_address_t + * @return The hash for the specified OFSocketAddress */ -extern unsigned long of_socket_address_hash( - const of_socket_address_t *_Nonnull address); +extern unsigned long OFSocketAddressHash( + const OFSocketAddress *_Nonnull address); /** - * @brief Converts the specified of_socket_address_t to an IP string and port. + * @brief Converts the specified @ref OFSocketAddress to a string. * * @param address The address to convert to a string - * @param port A pointer to an uint16_t which should be set to the port of the - * address or NULL if the port is not needed * @return The address as an IP string */ -extern OFString *_Nonnull of_socket_address_ip_string( - const of_socket_address_t *_Nonnull address, uint16_t *_Nullable port); +extern OFString *_Nonnull OFSocketAddressString( + const OFSocketAddress *_Nonnull address); /** - * @brief Sets the port of the specified of_socket_address_t, independent of + * @brief Sets the port of the specified @ref OFSocketAddress, independent of * the address family used. * * @param address The address on which to set the port * @param port The port to set on the address */ -extern void of_socket_address_set_port(of_socket_address_t *_Nonnull address, +extern void OFSocketAddressSetPort(OFSocketAddress *_Nonnull address, uint16_t port); /** - * @brief Returns the port of the specified of_socket_address_t, independent of + * @brief Returns the port of the specified @ref OFSocketAddress, independent of * the address family used. * * @param address The address on which to get the port * @return The port of the address */ -extern uint16_t of_socket_address_get_port( - const of_socket_address_t *_Nonnull address); +extern uint16_t OFSocketAddressPort(const OFSocketAddress *_Nonnull address); /** - * @brief Sets the IPX network of the specified of_socket_address_t. + * @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 */ -extern void of_socket_address_set_ipx_network( - of_socket_address_t *_Nonnull address, uint32_t network); +extern void OFSocketAddressSetIPXNetwork(OFSocketAddress *_Nonnull address, + uint32_t network); /** - * @brief Returns the IPX network of the specified of_socket_address_t. + * @brief Returns the IPX network of the specified @ref OFSocketAddress. * * @param address The address on which to get the IPX network * @return The IPX network of the address */ -extern uint32_t of_socket_address_get_ipx_network( - const of_socket_address_t *_Nonnull address); +extern uint32_t OFSocketAddressIPXNetwork( + const OFSocketAddress *_Nonnull address); /** - * @brief Sets the IPX node of the specified of_socket_address_t. + * @brief Sets the IPX node of the specified @ref OFSocketAddress. * * @param address The address on which to set the IPX node * @param node The IPX node to set on the address */ -extern void of_socket_address_set_ipx_node( - of_socket_address_t *_Nonnull address, +extern void OFSocketAddressSetIPXNode(OFSocketAddress *_Nonnull address, const unsigned char node[_Nonnull IPX_NODE_LEN]); /** - * @brief Gets the IPX node of the specified of_socket_address_t. + * @brief Gets the IPX node of the specified @ref OFSocketAddress. * * @param address The address on which to get the IPX node * @param node A byte array to store the IPX node of the address */ -extern void of_socket_address_get_ipx_node( - const of_socket_address_t *_Nonnull address, +extern void OFSocketAddressIPXNode(const OFSocketAddress *_Nonnull address, unsigned char node[_Nonnull IPX_NODE_LEN]); extern bool of_socket_init(void); #if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS) extern void of_socket_deinit(void); Index: src/socket.m ================================================================== --- src/socket.m +++ src/socket.m @@ -346,23 +346,23 @@ return ret; } #endif -of_socket_address_t -of_socket_address_parse_ipv4(OFString *IPv4, uint16_t port) +OFSocketAddress +OFSocketAddressParseIPv4(OFString *IPv4, uint16_t port) { void *pool = objc_autoreleasePoolPush(); OFCharacterSet *whitespaceCharacterSet = [OFCharacterSet whitespaceCharacterSet]; - of_socket_address_t ret; + OFSocketAddress ret; struct sockaddr_in *addrIn = &ret.sockaddr.in; OFArray OF_GENERIC(OFString *) *components; uint32_t addr; memset(&ret, '\0', sizeof(ret)); - ret.family = OF_SOCKET_ADDRESS_FAMILY_IPV4; + ret.family = OFSocketAddressFamilyIPv4; #if defined(OF_WII) || defined(OF_NINTENDO_3DS) ret.length = 8; #else ret.length = sizeof(ret.sockaddr.in); #endif @@ -420,20 +420,20 @@ @throw [OFInvalidFormatException exception]; return (uint16_t)number; } -of_socket_address_t -of_socket_address_parse_ipv6(OFString *IPv6, uint16_t port) +OFSocketAddress +OFSocketAddressParseIPv6(OFString *IPv6, uint16_t port) { void *pool = objc_autoreleasePoolPush(); - of_socket_address_t ret; + OFSocketAddress ret; struct sockaddr_in6 *addrIn6 = &ret.sockaddr.in6; size_t doubleColon; memset(&ret, '\0', sizeof(ret)); - ret.family = OF_SOCKET_ADDRESS_FAMILY_IPV6; + ret.family = OFSocketAddressFamilyIPv6; ret.length = sizeof(ret.sockaddr.in6); #ifdef AF_INET6 addrIn6->sin6_family = AF_INET6; #else @@ -499,32 +499,32 @@ objc_autoreleasePoolPop(pool); return ret; } -of_socket_address_t -of_socket_address_parse_ip(OFString *IP, uint16_t port) +OFSocketAddress +OFSocketAddressParseIP(OFString *IP, uint16_t port) { - of_socket_address_t ret; + OFSocketAddress ret; @try { - ret = of_socket_address_parse_ipv6(IP, port); + ret = OFSocketAddressParseIPv6(IP, port); } @catch (OFInvalidFormatException *e) { - ret = of_socket_address_parse_ipv4(IP, port); + ret = OFSocketAddressParseIPv4(IP, port); } return ret; } -of_socket_address_t -of_socket_address_ipx(const unsigned char node[IPX_NODE_LEN], uint32_t network, +OFSocketAddress +OFSocketAddressMakeIPX(const unsigned char node[IPX_NODE_LEN], uint32_t network, uint16_t port) { - of_socket_address_t ret; + OFSocketAddress ret; memset(&ret, '\0', sizeof(ret)); - ret.family = OF_SOCKET_ADDRESS_FAMILY_IPX; + ret.family = OFSocketAddressFamilyIPX; ret.length = sizeof(ret.sockaddr.ipx); #ifdef AF_IPX ret.sockaddr.ipx.sipx_family = AF_IPX; #else @@ -538,22 +538,22 @@ return ret; } bool -of_socket_address_equal(const of_socket_address_t *address1, - const of_socket_address_t *address2) +OFSocketAddressEqual(const OFSocketAddress *address1, + const OFSocketAddress *address2) { const struct sockaddr_in *addrIn1, *addrIn2; const struct sockaddr_in6 *addrIn6_1, *addrIn6_2; const struct sockaddr_ipx *addrIPX1, *addrIPX2; if (address1->family != address2->family) return false; switch (address1->family) { - case OF_SOCKET_ADDRESS_FAMILY_IPV4: + case OFSocketAddressFamilyIPv4: #if defined(OF_WII) || defined(OF_NINTENDO_3DS) if (address1->length < 8 || address2->length < 8) @throw [OFInvalidArgumentException exception]; #else if (address1->length < (socklen_t)sizeof(struct sockaddr_in) || @@ -568,11 +568,11 @@ return false; if (addrIn1->sin_addr.s_addr != addrIn2->sin_addr.s_addr) return false; break; - case OF_SOCKET_ADDRESS_FAMILY_IPV6: + case OFSocketAddressFamilyIPv6: if (address1->length < (socklen_t)sizeof(struct sockaddr_in6) || address2->length < (socklen_t)sizeof(struct sockaddr_in6)) @throw [OFInvalidArgumentException exception]; addrIn6_1 = &address1->sockaddr.in6; @@ -584,11 +584,11 @@ addrIn6_2->sin6_addr.s6_addr, sizeof(addrIn6_1->sin6_addr.s6_addr)) != 0) return false; break; - case OF_SOCKET_ADDRESS_FAMILY_IPX: + case OFSocketAddressFamilyIPX: if (address1->length < (socklen_t)sizeof(struct sockaddr_ipx) || address2->length < (socklen_t)sizeof(struct sockaddr_ipx)) @throw [OFInvalidArgumentException exception]; addrIPX1 = &address1->sockaddr.ipx; @@ -610,19 +610,19 @@ return true; } unsigned long -of_socket_address_hash(const of_socket_address_t *address) +OFSocketAddressHash(const OFSocketAddress *address) { uint32_t hash; OF_HASH_INIT(hash); OF_HASH_ADD(hash, address->family); switch (address->family) { - case OF_SOCKET_ADDRESS_FAMILY_IPV4: + case OFSocketAddressFamilyIPv4: #if defined(OF_WII) || defined(OF_NINTENDO_3DS) if (address->length < 8) @throw [OFInvalidArgumentException exception]; #else if (address->length < (socklen_t)sizeof(struct sockaddr_in)) @@ -635,11 +635,11 @@ OF_HASH_ADD(hash, address->sockaddr.in.sin_addr.s_addr >> 16); OF_HASH_ADD(hash, address->sockaddr.in.sin_addr.s_addr >> 8); OF_HASH_ADD(hash, address->sockaddr.in.sin_addr.s_addr); break; - case OF_SOCKET_ADDRESS_FAMILY_IPV6: + case OFSocketAddressFamilyIPv6: if (address->length < (socklen_t)sizeof(struct sockaddr_in6)) @throw [OFInvalidArgumentException exception]; OF_HASH_ADD(hash, address->sockaddr.in6.sin6_port >> 8); OF_HASH_ADD(hash, address->sockaddr.in6.sin6_port); @@ -648,11 +648,11 @@ i < sizeof(address->sockaddr.in6.sin6_addr.s6_addr); i++) OF_HASH_ADD(hash, address->sockaddr.in6.sin6_addr.s6_addr[i]); break; - case OF_SOCKET_ADDRESS_FAMILY_IPX:; + case OFSocketAddressFamilyIPX:; unsigned char network[ sizeof(address->sockaddr.ipx.sipx_network)]; if (address->length < (socklen_t)sizeof(struct sockaddr_ipx)) @throw [OFInvalidArgumentException exception]; @@ -678,28 +678,25 @@ return hash; } static OFString * -IPv4String(const of_socket_address_t *address, uint16_t *port) +IPv4AddressString(const OFSocketAddress *address) { const struct sockaddr_in *addrIn = &address->sockaddr.in; uint32_t addr = OF_BSWAP32_IF_LE(addrIn->sin_addr.s_addr); OFString *string; string = [OFString stringWithFormat: @"%u.%u.%u.%u", (addr & 0xFF000000) >> 24, (addr & 0x00FF0000) >> 16, (addr & 0x0000FF00) >> 8, addr & 0x000000FF]; - if (port != NULL) - *port = OF_BSWAP16_IF_LE(addrIn->sin_port); - return string; } static OFString * -IPv6String(const of_socket_address_t *address, uint16_t *port) +IPv6AddressString(const OFSocketAddress *address) { OFMutableString *string = [OFMutableString string]; const struct sockaddr_in6 *addrIn6 = &address->sockaddr.in6; int_fast8_t zerosStart = -1, maxZerosStart = -1; uint_fast8_t zerosCount = 0, maxZerosCount = 0; @@ -758,101 +755,97 @@ } } [string makeImmutable]; - if (port != NULL) - *port = OF_BSWAP16_IF_LE(addrIn6->sin6_port); - return string; } OFString * -of_socket_address_ip_string(const of_socket_address_t *address, uint16_t *port) +OFSocketAddressString(const OFSocketAddress *address) { switch (address->family) { - case OF_SOCKET_ADDRESS_FAMILY_IPV4: - return IPv4String(address, port); - case OF_SOCKET_ADDRESS_FAMILY_IPV6: - return IPv6String(address, port); + case OFSocketAddressFamilyIPv4: + return IPv4AddressString(address); + case OFSocketAddressFamilyIPv6: + return IPv6AddressString(address); default: @throw [OFInvalidArgumentException exception]; } } void -of_socket_address_set_port(of_socket_address_t *address, uint16_t port) +OFSocketAddressSetPort(OFSocketAddress *address, uint16_t port) { switch (address->family) { - case OF_SOCKET_ADDRESS_FAMILY_IPV4: + case OFSocketAddressFamilyIPv4: address->sockaddr.in.sin_port = OF_BSWAP16_IF_LE(port); break; - case OF_SOCKET_ADDRESS_FAMILY_IPV6: + case OFSocketAddressFamilyIPv6: address->sockaddr.in6.sin6_port = OF_BSWAP16_IF_LE(port); break; - case OF_SOCKET_ADDRESS_FAMILY_IPX: + case OFSocketAddressFamilyIPX: address->sockaddr.ipx.sipx_port = OF_BSWAP16_IF_LE(port); break; default: @throw [OFInvalidArgumentException exception]; } } uint16_t -of_socket_address_get_port(const of_socket_address_t *address) +OFSocketAddressPort(const OFSocketAddress *address) { switch (address->family) { - case OF_SOCKET_ADDRESS_FAMILY_IPV4: + case OFSocketAddressFamilyIPv4: return OF_BSWAP16_IF_LE(address->sockaddr.in.sin_port); - case OF_SOCKET_ADDRESS_FAMILY_IPV6: + case OFSocketAddressFamilyIPv6: return OF_BSWAP16_IF_LE(address->sockaddr.in6.sin6_port); - case OF_SOCKET_ADDRESS_FAMILY_IPX: + case OFSocketAddressFamilyIPX: return OF_BSWAP16_IF_LE(address->sockaddr.ipx.sipx_port); default: @throw [OFInvalidArgumentException exception]; } } void -of_socket_address_set_ipx_network(of_socket_address_t *address, - uint32_t network) +OFSocketAddressSetIPXNetwork(OFSocketAddress *address, uint32_t network) { - if (address->family != OF_SOCKET_ADDRESS_FAMILY_IPX) + if (address->family != OFSocketAddressFamilyIPX) @throw [OFInvalidArgumentException exception]; network = OF_BSWAP32_IF_LE(network); memcpy(&address->sockaddr.ipx.sipx_network, &network, sizeof(address->sockaddr.ipx.sipx_network)); } uint32_t -of_socket_address_get_ipx_network(const of_socket_address_t *address) +OFSocketAddressIPXNetwork(const OFSocketAddress *address) { uint32_t network; - if (address->family != OF_SOCKET_ADDRESS_FAMILY_IPX) + if (address->family != OFSocketAddressFamilyIPX) @throw [OFInvalidArgumentException exception]; memcpy(&network, &address->sockaddr.ipx.sipx_network, sizeof(network)); return OF_BSWAP32_IF_LE(network); } void -of_socket_address_set_ipx_node(of_socket_address_t *address, +OFSocketAddressSetIPXNode(OFSocketAddress *address, const unsigned char node[IPX_NODE_LEN]) { - if (address->family != OF_SOCKET_ADDRESS_FAMILY_IPX) + if (address->family != OFSocketAddressFamilyIPX) @throw [OFInvalidArgumentException exception]; memcpy(address->sockaddr.ipx.sipx_node, node, IPX_NODE_LEN); } void -of_socket_address_get_ipx_node(const of_socket_address_t *address, +OFSocketAddressIPXNode(const OFSocketAddress *address, unsigned char node[IPX_NODE_LEN]) { - if (address->family != OF_SOCKET_ADDRESS_FAMILY_IPX) + if (address->family != OFSocketAddressFamilyIPX) @throw [OFInvalidArgumentException exception]; memcpy(node, address->sockaddr.ipx.sipx_node, IPX_NODE_LEN); } Index: tests/OFIPXSocketTests.m ================================================================== --- tests/OFIPXSocketTests.m +++ tests/OFIPXSocketTests.m @@ -24,11 +24,11 @@ @implementation TestsAppDelegate (OFIPXSocketTests) - (void)IPXSocketTests { void *pool = objc_autoreleasePoolPush(); OFIPXSocket *sock; - of_socket_address_t address1, address2; + OFSocketAddress address1, address2; char buffer[5]; TEST(@"+[socket]", (sock = [OFIPXSocket socket])) @try { @@ -60,12 +60,11 @@ R([sock sendBuffer: "Hello" length: 5 receiver: &address1])) TEST(@"-[receiveIntoBuffer:length:sender:]", [sock receiveIntoBuffer: buffer length: 5 sender: &address2] == 5 && memcmp(buffer, "Hello", 5) == 0 && - of_socket_address_equal(&address1, &address2) && - of_socket_address_hash(&address1) == - of_socket_address_hash(&address2)) + OFSocketAddressEqual(&address1, &address2) && + OFSocketaddressHash(&address1) == OFSocketaddressHash(&address2)) objc_autoreleasePoolPop(pool); } @end Index: tests/OFSPXSocketTests.m ================================================================== --- tests/OFSPXSocketTests.m +++ tests/OFSPXSocketTests.m @@ -71,12 +71,12 @@ @implementation TestsAppDelegate (OFSPXSocketTests) - (void)SPXSocketTests { void *pool = objc_autoreleasePoolPush(); OFSPXSocket *sockClient, *sockServer, *sockAccepted;; - of_socket_address_t address1; - const of_socket_address_t *address2; + OFSocketAddress address1; + const OFSocketAddress *address2; unsigned char node[IPX_NODE_LEN], node2[IPX_NODE_LEN]; uint32_t network; uint16_t port; char buffer[5]; SPXSocketDelegate *delegate; @@ -113,13 +113,13 @@ objc_autoreleasePoolPop(pool); return; } - of_socket_address_get_ipx_node(&address1, node); - network = of_socket_address_get_ipx_network(&address1); - port = of_socket_address_get_port(&address1); + OFSocketAddressIPXNode(&address1, node); + network = OFSocketAddressIPXNetwork(&address1); + port = OFSocketAddressPort(&address1); TEST(@"-[listen]", R([sockServer listen])) TEST(@"-[connectToNode:network:port:]", R([sockClient connectToNode: node network: network port: port])) @@ -133,13 +133,13 @@ [sockClient receiveIntoBuffer: buffer length: 5] == 5 && memcmp(buffer, "Hello", 5) == 0) TEST(@"-[remoteAddress]", (address2 = sockAccepted.remoteAddress) && - R(of_socket_address_get_ipx_node(address2, node2)) && + R(OFSocketAddressIPXNode(address2, node2)) && memcmp(node, node2, IPX_NODE_LEN) == 0 && - of_socket_address_get_ipx_network(address2) == network) + OFSocketAddressIPXNetwork(address2) == network) delegate = [[[SPXSocketDelegate alloc] init] autorelease]; sockServer = [OFSPXSocket socket]; delegate->_expectedServerSocket = sockServer; @@ -151,15 +151,15 @@ address1 = [sockServer bindToPort: 0]; [sockServer listen]; [sockServer asyncAccept]; - of_socket_address_get_ipx_node(&address1, node); + OFSocketAddressIPXNode(&address1, node); memcpy(delegate->_expectedNode, node, IPX_NODE_LEN); delegate->_expectedNetwork = network = - of_socket_address_get_ipx_network(&address1); - delegate->_expectedPort = port = of_socket_address_get_port(&address1); + OFSocketAddressIPXNetwork(&address1); + delegate->_expectedPort = port = OFSocketAddressPort(&address1); @try { [sockClient asyncConnectToNode: node network: network port: port]; Index: tests/OFSPXStreamSocketTests.m ================================================================== --- tests/OFSPXStreamSocketTests.m +++ tests/OFSPXStreamSocketTests.m @@ -71,12 +71,12 @@ @implementation TestsAppDelegate (OFSPXStreamSocketTests) - (void)SPXStreamSocketTests { void *pool = objc_autoreleasePoolPush(); OFSPXStreamSocket *sockClient, *sockServer, *sockAccepted;; - of_socket_address_t address1; - const of_socket_address_t *address2; + OFSocketAddress address1; + const OFSocketAddress *address2; unsigned char node[IPX_NODE_LEN], node2[IPX_NODE_LEN]; uint32_t network; uint16_t port; char buffer[5]; SPXStreamSocketDelegate *delegate; @@ -113,13 +113,13 @@ objc_autoreleasePoolPop(pool); return; } - of_socket_address_get_ipx_node(&address1, node); - network = of_socket_address_get_ipx_network(&address1); - port = of_socket_address_get_port(&address1); + OFSocketAddressIPXNode(&address1, node); + network = OFSocketAddressIPXNetwork(&address1); + port = OFSocketAddressPort(&address1); TEST(@"-[listen]", R([sockServer listen])) TEST(@"-[connectToNode:network:port:]", R([sockClient connectToNode: node network: network port: port])) @@ -136,13 +136,13 @@ [sockClient readIntoBuffer: buffer length: 3] == 3 && memcmp(buffer, "llo", 3) == 0) TEST(@"-[remoteAddress]", (address2 = sockAccepted.remoteAddress) && - R(of_socket_address_get_ipx_node(address2, node2)) && + R(OFSocketAddressIPXNode(address2, node2)) && memcmp(node, node2, IPX_NODE_LEN) == 0 && - of_socket_address_get_ipx_network(address2) == network) + OFSocketAddressIPXNetwork(address2) == network) delegate = [[[SPXStreamSocketDelegate alloc] init] autorelease]; sockServer = [OFSPXStreamSocket socket]; delegate->_expectedServerSocket = sockServer; @@ -154,15 +154,15 @@ address1 = [sockServer bindToPort: 0]; [sockServer listen]; [sockServer asyncAccept]; - of_socket_address_get_ipx_node(&address1, node); + OFSocketAddressIPXNode(&address1, node); memcpy(delegate->_expectedNode, node, IPX_NODE_LEN); delegate->_expectedNetwork = network = - of_socket_address_get_ipx_network(&address1); - delegate->_expectedPort = port = of_socket_address_get_port(&address1); + OFSocketAddressIPXNetwork(&address1); + delegate->_expectedPort = port = OFSocketAddressPort(&address1); @try { [sockClient asyncConnectToNode: node network: network port: port]; Index: tests/OFTCPSocketTests.m ================================================================== --- tests/OFTCPSocketTests.m +++ tests/OFTCPSocketTests.m @@ -41,11 +41,11 @@ R([client connectToHost: @"127.0.0.1" port: port])) TEST(@"-[accept]", (accepted = [server accept])) TEST(@"-[remoteAddress]", - [of_socket_address_ip_string(accepted.remoteAddress, NULL) + [OFSocketAddressString(accepted.remoteAddress) isEqual: @"127.0.0.1"]) TEST(@"-[writeString:]", [client writeString: @"Hello!"]) TEST(@"-[readIntoBuffer:length:]", Index: tests/OFUDPSocketTests.m ================================================================== --- tests/OFUDPSocketTests.m +++ tests/OFUDPSocketTests.m @@ -24,43 +24,42 @@ @implementation TestsAppDelegate (OFUDPSocketTests) - (void)UDPSocketTests { void *pool = objc_autoreleasePoolPush(); OFUDPSocket *sock; - uint16_t port1, port2; - of_socket_address_t addr1, addr2, addr3; + uint16_t port1; + OFSocketAddress addr1, addr2, addr3; char buf[6]; - OFString *host; TEST(@"+[socket]", (sock = [OFUDPSocket socket])) TEST(@"-[bindToHost:port:]", (port1 = [sock bindToHost: @"127.0.0.1" port: 0])) - addr1 = of_socket_address_parse_ip(@"127.0.0.1", port1); + addr1 = OFSocketAddressParseIP(@"127.0.0.1", port1); TEST(@"-[sendBuffer:length:receiver:]", R([sock sendBuffer: "Hello" length: 6 receiver: &addr1])) TEST(@"-[receiveIntoBuffer:length:sender:]", [sock receiveIntoBuffer: buf length: 6 sender: &addr2] == 6 && !memcmp(buf, "Hello", 6) && - (host = of_socket_address_ip_string(&addr2, &port2)) && - [host isEqual: @"127.0.0.1"] && port2 == port1) + [OFSocketAddressString(&addr2) isEqual: @"127.0.0.1"] && + OFSocketAddressPort(&addr2) == port1) - addr3 = of_socket_address_parse_ip(@"127.0.0.1", port1 + 1); + addr3 = OFSocketAddressParseIP(@"127.0.0.1", port1 + 1); /* * TODO: Move those tests elsewhere as soon as the DNS resolving part * is no longer in OFUDPSocket. */ - TEST(@"of_socket_address_equal()", - of_socket_address_equal(&addr1, &addr2) && - !of_socket_address_equal(&addr1, &addr3)) + TEST(@"OFSocketAddressEqual()", + OFSocketAddressEqual(&addr1, &addr2) && + !OFSocketAddressEqual(&addr1, &addr3)) - TEST(@"of_socket_address_hash()", - of_socket_address_hash(&addr1) == of_socket_address_hash(&addr2) && - of_socket_address_hash(&addr1) != of_socket_address_hash(&addr3)) + TEST(@"OFSocketAddressHash()", + OFSocketAddressHash(&addr1) == OFSocketAddressHash(&addr2) && + OFSocketAddressHash(&addr1) != OFSocketAddressHash(&addr3)) objc_autoreleasePoolPop(pool); } @end Index: tests/SocketTests.m ================================================================== --- tests/SocketTests.m +++ tests/SocketTests.m @@ -56,169 +56,144 @@ @implementation TestsAppDelegate (SocketTests) - (void)socketTests { void *pool = objc_autoreleasePoolPush(); - of_socket_address_t addr; - uint16_t port; + OFSocketAddress addr; TEST(@"Parsing an IPv4", - R(addr = of_socket_address_parse_ip(@"127.0.0.1", 1234)) && + R(addr = OFSocketAddressParseIP(@"127.0.0.1", 1234)) && OF_BSWAP32_IF_LE(addr.sockaddr.in.sin_addr.s_addr) == 0x7F000001 && OF_BSWAP16_IF_LE(addr.sockaddr.in.sin_port) == 1234) - EXPECT_EXCEPTION(@"Refusing invalid IPv4 #1", - OFInvalidFormatException, - of_socket_address_parse_ip(@"127.0.0.0.1", 1234)) - - EXPECT_EXCEPTION(@"Refusing invalid IPv4 #2", - OFInvalidFormatException, - of_socket_address_parse_ip(@"127.0.0.256", 1234)) - - EXPECT_EXCEPTION(@"Refusing invalid IPv4 #3", - OFInvalidFormatException, - of_socket_address_parse_ip(@"127.0.0. 1", 1234)) - - EXPECT_EXCEPTION(@"Refusing invalid IPv4 #4", - OFInvalidFormatException, - of_socket_address_parse_ip(@" 127.0.0.1", 1234)) - - EXPECT_EXCEPTION(@"Refusing invalid IPv4 #5", - OFInvalidFormatException, - of_socket_address_parse_ip(@"127.0.a.1", 1234)) - - EXPECT_EXCEPTION(@"Refusing invalid IPv4 #6", - OFInvalidFormatException, - of_socket_address_parse_ip(@"127.0..1", 1234)) + EXPECT_EXCEPTION(@"Refusing invalid IPv4 #1", OFInvalidFormatException, + OFSocketAddressParseIP(@"127.0.0.0.1", 1234)) + + EXPECT_EXCEPTION(@"Refusing invalid IPv4 #2", OFInvalidFormatException, + OFSocketAddressParseIP(@"127.0.0.256", 1234)) + + EXPECT_EXCEPTION(@"Refusing invalid IPv4 #3", OFInvalidFormatException, + OFSocketAddressParseIP(@"127.0.0. 1", 1234)) + + EXPECT_EXCEPTION(@"Refusing invalid IPv4 #4", OFInvalidFormatException, + OFSocketAddressParseIP(@" 127.0.0.1", 1234)) + + EXPECT_EXCEPTION(@"Refusing invalid IPv4 #5", OFInvalidFormatException, + 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(@"Converting an IPv4 to a string", - [of_socket_address_ip_string(&addr, &port) isEqual: @"127.0.0.1"] && - port == 1234) + [OFSocketAddressString(&addr) isEqual: @"127.0.0.1"]) TEST(@"Parsing an IPv6 #1", - R(addr = of_socket_address_parse_ip( + R(addr = OFSocketAddressParseIP( @"1122:3344:5566:7788:99aa:bbCc:ddee:ff00", 1234)) && COMPARE_V6(addr, 0x1122, 0x3344, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0xDDEE, 0xFF00) && OF_BSWAP16_IF_LE(addr.sockaddr.in6.sin6_port) == 1234) TEST(@"Parsing an IPv6 #2", - R(addr = of_socket_address_parse_ip(@"::", 1234)) && + R(addr = OFSocketAddressParseIP(@"::", 1234)) && COMPARE_V6(addr, 0, 0, 0, 0, 0, 0, 0, 0) && OF_BSWAP16_IF_LE(addr.sockaddr.in6.sin6_port) == 1234) TEST(@"Parsing an IPv6 #3", - R(addr = of_socket_address_parse_ip(@"aaAa::bBbb", 1234)) && + R(addr = OFSocketAddressParseIP(@"aaAa::bBbb", 1234)) && COMPARE_V6(addr, 0xAAAA, 0, 0, 0, 0, 0, 0, 0xBBBB) && OF_BSWAP16_IF_LE(addr.sockaddr.in6.sin6_port) == 1234) TEST(@"Parsing an IPv6 #4", - R(addr = of_socket_address_parse_ip(@"aaAa::", 1234)) && + R(addr = OFSocketAddressParseIP(@"aaAa::", 1234)) && COMPARE_V6(addr, 0xAAAA, 0, 0, 0, 0, 0, 0, 0) && OF_BSWAP16_IF_LE(addr.sockaddr.in6.sin6_port) == 1234) TEST(@"Parsing an IPv6 #5", - R(addr = of_socket_address_parse_ip(@"::aaAa", 1234)) && + R(addr = OFSocketAddressParseIP(@"::aaAa", 1234)) && COMPARE_V6(addr, 0, 0, 0, 0, 0, 0, 0, 0xAAAA) && OF_BSWAP16_IF_LE(addr.sockaddr.in6.sin6_port) == 1234) - EXPECT_EXCEPTION(@"Refusing invalid IPv6 #1", - OFInvalidFormatException, - of_socket_address_parse_ip(@"1:::2", 1234)) - - EXPECT_EXCEPTION(@"Refusing invalid IPv6 #2", - OFInvalidFormatException, - of_socket_address_parse_ip(@"1: ::2", 1234)) - - EXPECT_EXCEPTION(@"Refusing invalid IPv6 #3", - OFInvalidFormatException, - of_socket_address_parse_ip(@"1:: :2", 1234)) - - EXPECT_EXCEPTION(@"Refusing invalid IPv6 #4", - OFInvalidFormatException, - of_socket_address_parse_ip(@"1::2::3", 1234)) - - EXPECT_EXCEPTION(@"Refusing invalid IPv6 #5", - OFInvalidFormatException, - of_socket_address_parse_ip(@"10000::1", 1234)) - - EXPECT_EXCEPTION(@"Refusing invalid IPv6 #6", - OFInvalidFormatException, - of_socket_address_parse_ip(@"::10000", 1234)) - - EXPECT_EXCEPTION(@"Refusing invalid IPv6 #7", - OFInvalidFormatException, - of_socket_address_parse_ip(@"::1::", 1234)) - - EXPECT_EXCEPTION(@"Refusing invalid IPv6 #8", - OFInvalidFormatException, - of_socket_address_parse_ip(@"1:2:3:4:5:6:7:", 1234)) - - EXPECT_EXCEPTION(@"Refusing invalid IPv6 #9", - OFInvalidFormatException, - of_socket_address_parse_ip(@"1:2:3:4:5:6:7::", 1234)) - - EXPECT_EXCEPTION(@"Refusing invalid IPv6 #10", - OFInvalidFormatException, - of_socket_address_parse_ip(@"1:2", 1234)) + EXPECT_EXCEPTION(@"Refusing invalid IPv6 #1", OFInvalidFormatException, + OFSocketAddressParseIP(@"1:::2", 1234)) + + EXPECT_EXCEPTION(@"Refusing invalid IPv6 #2", OFInvalidFormatException, + OFSocketAddressParseIP(@"1: ::2", 1234)) + + EXPECT_EXCEPTION(@"Refusing invalid IPv6 #3", OFInvalidFormatException, + OFSocketAddressParseIP(@"1:: :2", 1234)) + + EXPECT_EXCEPTION(@"Refusing invalid IPv6 #4", OFInvalidFormatException, + OFSocketAddressParseIP(@"1::2::3", 1234)) + + EXPECT_EXCEPTION(@"Refusing invalid IPv6 #5", OFInvalidFormatException, + OFSocketAddressParseIP(@"10000::1", 1234)) + + EXPECT_EXCEPTION(@"Refusing invalid IPv6 #6", OFInvalidFormatException, + OFSocketAddressParseIP(@"::10000", 1234)) + + EXPECT_EXCEPTION(@"Refusing invalid IPv6 #7", OFInvalidFormatException, + OFSocketAddressParseIP(@"::1::", 1234)) + + EXPECT_EXCEPTION(@"Refusing invalid IPv6 #8", OFInvalidFormatException, + OFSocketAddressParseIP(@"1:2:3:4:5:6:7:", 1234)) + + EXPECT_EXCEPTION(@"Refusing invalid IPv6 #9", OFInvalidFormatException, + 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) SET_V6(addr, 0, 0, 0, 0, 0, 0, 0, 0) TEST(@"Converting an IPv6 to a string #1", - [of_socket_address_ip_string(&addr, &port) isEqual: @"::"] && - port == 1234) + [OFSocketAddressString(&addr) isEqual: @"::"]) SET_V6(addr, 0, 0, 0, 0, 0, 0, 0, 1) TEST(@"Converting an IPv6 to a string #2", - [of_socket_address_ip_string(&addr, &port) isEqual: @"::1"] && - port == 1234) + [OFSocketAddressString(&addr) isEqual: @"::1"]) SET_V6(addr, 1, 0, 0, 0, 0, 0, 0, 0) TEST(@"Converting an IPv6 to a string #3", - [of_socket_address_ip_string(&addr, &port) isEqual: @"1::"] && - port == 1234) + [OFSocketAddressString(&addr) isEqual: @"1::"]) SET_V6(addr, 0x1122, 0x3344, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0xDDEE, 0xFF00) TEST(@"Converting an IPv6 to a string #4", - [of_socket_address_ip_string(&addr, &port) isEqual: - @"1122:3344:5566:7788:99aa:bbcc:ddee:ff00"] && - port == 1234) + [OFSocketAddressString(&addr) + isEqual: @"1122:3344:5566:7788:99aa:bbcc:ddee:ff00"]) SET_V6(addr, 0x1122, 0x3344, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0xDDEE, 0) TEST(@"Converting an IPv6 to a string #5", - [of_socket_address_ip_string(&addr, &port) isEqual: - @"1122:3344:5566:7788:99aa:bbcc:ddee:0"] && - port == 1234) + [OFSocketAddressString(&addr) + isEqual: @"1122:3344:5566:7788:99aa:bbcc:ddee:0"]) SET_V6(addr, 0x1122, 0x3344, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0, 0) TEST(@"Converting an IPv6 to a string #6", - [of_socket_address_ip_string(&addr, &port) isEqual: - @"1122:3344:5566:7788:99aa:bbcc::"] && - port == 1234) + [OFSocketAddressString(&addr) + isEqual: @"1122:3344:5566:7788:99aa:bbcc::"]) SET_V6(addr, 0, 0x3344, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0xDDEE, 0xFF00) TEST(@"Converting an IPv6 to a string #7", - [of_socket_address_ip_string(&addr, &port) isEqual: - @"0:3344:5566:7788:99aa:bbcc:ddee:ff00"] && - port == 1234) + [OFSocketAddressString(&addr) + isEqual: @"0:3344:5566:7788:99aa:bbcc:ddee:ff00"]) SET_V6(addr, 0, 0, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0xDDEE, 0xFF00) TEST(@"Converting an IPv6 to a string #8", - [of_socket_address_ip_string(&addr, &port) isEqual: - @"::5566:7788:99aa:bbcc:ddee:ff00"] && - port == 1234) + [OFSocketAddressString(&addr) + isEqual: @"::5566:7788:99aa:bbcc:ddee:ff00"]) SET_V6(addr, 0, 0, 0x5566, 0, 0, 0, 0xDDEE, 0xFF00) TEST(@"Converting an IPv6 to a string #9", - [of_socket_address_ip_string(&addr, &port) isEqual: - @"0:0:5566::ddee:ff00"] && - port == 1234) + [OFSocketAddressString(&addr) isEqual: @"0:0:5566::ddee:ff00"]) SET_V6(addr, 0, 0, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0, 0) TEST(@"Converting an IPv6 to a string #10", - [of_socket_address_ip_string(&addr, &port) isEqual: - @"::5566:7788:99aa:bbcc:0:0"] && - port == 1234) + [OFSocketAddressString(&addr) + isEqual: @"::5566:7788:99aa:bbcc:0:0"]) objc_autoreleasePoolPop(pool); } @end