Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -1719,23 +1719,10 @@ #endif ], [ AC_DEFINE(OF_HAVE_APPLETALK, 1, [Whether we have AppleTalk]) AC_SUBST(USE_SRCS_APPLETALK, '${SRCS_APPLETALK}') - - AC_CHECK_TYPE([struct ifreq], [ - AC_DEFINE(OF_HAVE_APPLETALK_IFCONFIG, 1, - m4_normalize([ - Whether AppleTalk interfaces - can be configured - ])) - ], [], [ - #ifdef OF_HAVE_SYS_SOCKET_H - # include - #endif - #include - ]) ]) ]) AC_CHECK_FUNCS(paccept accept4, break) Index: src/OFDDPSocket.h ================================================================== --- src/OFDDPSocket.h +++ src/OFDDPSocket.h @@ -18,63 +18,10 @@ OF_ASSUME_NONNULL_BEGIN @class OFString; @class OFDictionary OF_GENERIC(KeyType, ObjectType); -#ifdef OF_HAVE_APPLETALK_IFCONFIG -/** - * @brief A dictionary mapping keys of type @ref - * OFAppleTalkInterfaceConfigurationKey. - */ -typedef OFConstantString *OFAppleTalkInterfaceConfigurationKey; - -/** - * @brief A key for OFAppleTalkInterfaceConfiguration. - * - * Possible keys are: - * * @ref OFAppleTalkInterfaceConfigurationNetwork - * * @ref OFAppleTalkInterfaceConfigurationNode - * * @ref OFAppleTalkInterfaceConfigurationPhase - * * @ref OFAppleTalkInterfaceConfigurationNetworkRange - */ -typedef OFDictionary OF_GENERIC(OFAppleTalkInterfaceConfigurationKey, id) - *OFAppleTalkInterfaceConfiguration; - -/** - * @brief The AppleTalk network of an interface. - * - * The corresponding value is of type @ref OFNumber in the range 0 to 65535. - */ -extern const OFAppleTalkInterfaceConfigurationKey - OFAppleTalkInterfaceConfigurationNetwork; - -/** - * @brief The AppleTalk node of an interface. - * - * The corresponding value is of type @ref OFNumber in the range 0 to 255. - */ -extern const OFAppleTalkInterfaceConfigurationKey - OFAppleTalkInterfaceConfigurationNode; - -/** - * @brief The AppleTalk phase of an interface. - * - * The corresponding value is of type @ref OFNumber in the range 1 to 2. - */ -extern const OFAppleTalkInterfaceConfigurationKey - OFAppleTalkInterfaceConfigurationPhase; - -/** - * @brief The AppleTalk network range of an interface. - * - * The corresponding value is of type @ref OFPair with two @ref OFNumber, both - * in the range 0 to 65535. - */ -extern const OFAppleTalkInterfaceConfigurationKey - OFAppleTalkInterfaceConfigurationNetworkRange; -#endif - /** * @protocol OFDDPSocketDelegate OFDDPSocket.h ObjFW/OFDDPSocket.h * * @brief A delegate for OFDDPSocket. */ @@ -121,50 +68,10 @@ * still ongoing. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id delegate; -#ifdef OF_HAVE_APPLETALK_IFCONFIG -/** - * @brief Configures the specified interface with the specified AppleTalk - * configuration. - * - * @param configuration The AppleTalk configuration for the interface. See - * @ref OFAppleTalkInterfaceConfiguration for more - * details. - * @param interfaceName The name of the interface to configure for AppleTalk - * @throw OFSetOptionFailedException Setting the configuration failed. Consult - * errNo for details. - */ -+ (void)setConfiguration: (OFAppleTalkInterfaceConfiguration)configuration - forInterface: (OFString *)interfaceName; - -/** - * @brief Returns the AppleTalk configuration for the specified interface. - * - * @param interfaceName The name of the interface for which to return the - * AppleTalk configuration - * @return The AppleTalk configuration for the specified interface, or `nil` if - * the specified interface is not configured for AppleTalk. See - * @ref OFAppleTalkInterfaceConfiguration for more details. - * @throw OFGetOptionFailedException Getting the configuration failed. Consult - * errNo for details. - */ -+ (nullable OFAppleTalkInterfaceConfiguration) - configurationForInterface: (OFString *)interfaceName; - -/** - * @brief Removes the AppleTalk configuration for the specified interface. - * - * @param interfaceName The name of the interface for which to remove the - * AppleTalk configuration - * @throw OFSetOptionFailedException Removing the configuration failed. Consult - * errNo for details. - */ -+ (void)removeConfigurationForInterface: (OFString *)interfaceName; -#endif - /** * @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". Index: src/OFDDPSocket.m ================================================================== --- src/OFDDPSocket.m +++ src/OFDDPSocket.m @@ -57,205 +57,13 @@ unsigned short netStart, netEnd; at_nvestr_t zoneName; }; #endif -#ifdef OF_HAVE_APPLETALK_IFCONFIG -const OFAppleTalkInterfaceConfigurationKey - OFAppleTalkInterfaceConfigurationNode = - @"OFAppleTalkInterfaceConfigurationNode"; -const OFAppleTalkInterfaceConfigurationKey - OFAppleTalkInterfaceConfigurationNetwork = - @"OFAppleTalkInterfaceConfigurationNetwork"; -const OFAppleTalkInterfaceConfigurationKey - OFAppleTalkInterfaceConfigurationPhase = - @"OFAppleTalkInterfaceConfigurationPhase"; -const OFAppleTalkInterfaceConfigurationKey - OFAppleTalkInterfaceConfigurationNetworkRange = - @"OFAppleTalkInterfaceConfigurationNetworkRange"; -#endif - @implementation OFDDPSocket @dynamic delegate; -#ifdef OF_HAVE_APPLETALK_IFCONFIG -+ (void)setConfiguration: (OFAppleTalkInterfaceConfiguration)config - forInterface: (OFString *)interfaceName -{ - OFNumber *network, *node, *phase; - OFPair OF_GENERIC(OFNumber *, OFNumber *) *range; - int sock; - struct ifreq request; - struct sockaddr_at *sat; - uint16_t rangeStart, rangeEnd; - - if (interfaceName.UTF8StringLength > IFNAMSIZ - 1) - @throw [OFOutOfRangeException exception]; - - network = [config - objectForKey: OFAppleTalkInterfaceConfigurationNetwork]; - node = [config objectForKey: OFAppleTalkInterfaceConfigurationNode]; - phase = [config objectForKey: OFAppleTalkInterfaceConfigurationPhase]; - range = [config - objectForKey: OFAppleTalkInterfaceConfigurationNetworkRange]; - - if (network == nil || node == nil) - @throw [OFInvalidArgumentException exception]; - - if (phase != nil && phase.unsignedCharValue != 1 && - phase.unsignedCharValue != 2) - @throw [OFInvalidArgumentException exception]; - -# ifdef OF_MACOS - if ((sock = socket(AF_APPLETALK, SOCK_RAW, 0)) < 0) -# else - if ((sock = socket(AF_APPLETALK, SOCK_DGRAM, 0)) < 0) -# endif - @throw [OFSetOptionFailedException - exceptionWithObject: nil - errNo: OFSocketErrNo()]; - - memset(&request, 0, sizeof(request)); - strncpy(request.ifr_name, interfaceName.UTF8String, IFNAMSIZ - 1); - sat = (struct sockaddr_at *)(void *)&request.ifr_addr; - sat->sat_family = AF_APPLETALK; - sat->sat_net = OFToBigEndian16(network.unsignedShortValue); - sat->sat_node = node.unsignedCharValue; - /* - * The netrange is hidden in sat_zero and different OSes use different - * struct names for it, so the portable way is setting sat_zero - * directly. - */ - sat->sat_zero[0] = (phase != nil ? phase.unsignedCharValue : 2); - if (range != nil) { - rangeStart = [range.firstObject unsignedShortValue]; - rangeEnd = [range.secondObject unsignedShortValue]; - } else { - rangeStart = rangeEnd = network.unsignedShortValue; - } - sat->sat_zero[2] = rangeStart >> 8; - sat->sat_zero[3] = rangeStart & 0xFF; - sat->sat_zero[4] = rangeEnd >> 8; - sat->sat_zero[5] = rangeEnd & 0xFF; - - if (ioctl(sock, SIOCSIFADDR, &request) != 0) - @throw [OFSetOptionFailedException - exceptionWithObject: nil - errNo: OFSocketErrNo()]; - - close(sock); -} - -+ (OFAppleTalkInterfaceConfiguration) - configurationForInterface: (OFString *)interfaceName -{ - int sock; - struct ifreq request; - struct sockaddr_at *sat; -# ifndef OF_LINUX - uint16_t rangeStart, rangeEnd; - OFPair *range; -# endif - - if (interfaceName.UTF8StringLength > IFNAMSIZ - 1) - @throw [OFOutOfRangeException exception]; - -# ifdef OF_MACOS - if ((sock = socket(AF_APPLETALK, SOCK_RAW, 0)) < 0) -# else - if ((sock = socket(AF_APPLETALK, SOCK_DGRAM, 0)) < 0) -# endif - @throw [OFGetOptionFailedException - exceptionWithObject: nil - errNo: OFSocketErrNo()]; - - memset(&request, 0, sizeof(request)); - strncpy(request.ifr_name, interfaceName.UTF8String, IFNAMSIZ - 1); - - if (ioctl(sock, SIOCGIFADDR, &request) < 0) { - int errNo = OFSocketErrNo(); - - /* No AppleTalk configured on this interface. */ - if (errNo == EADDRNOTAVAIL) { - close(sock); - return nil; - } - - @throw [OFGetOptionFailedException exceptionWithObject: nil - errNo: errNo]; - } - - sat = (struct sockaddr_at *)(void *)&request.ifr_addr; - - close(sock); - -# ifndef OF_LINUX - /* - * Linux currently doesn't fill out the phase or netrange. - * - * The netrange is hidden in sat_zero and different OSes use different - * struct names for it, so the portable way is setting sat_zero - * directly. - */ - rangeStart = sat->sat_zero[2] << 8 | sat->sat_zero[3]; - rangeEnd = sat->sat_zero[4] << 8 | sat->sat_zero[5]; - range = [OFPair - pairWithFirstObject: [OFNumber numberWithUnsignedShort: rangeStart] - secondObject: [OFNumber numberWithUnsignedShort: rangeEnd]]; -# endif - - return [OFDictionary dictionaryWithKeysAndObjects: - OFAppleTalkInterfaceConfigurationNode, - [OFNumber numberWithUnsignedChar: sat->sat_node], - OFAppleTalkInterfaceConfigurationNetwork, - [OFNumber numberWithUnsignedShort: OFFromBigEndian16(sat->sat_net)], -# ifndef OF_LINUX - OFAppleTalkInterfaceConfigurationPhase, - [OFNumber numberWithUnsignedChar: sat->sat_zero[0]], - OFAppleTalkInterfaceConfigurationNetworkRange, range, -# endif - nil]; -} - -+ (void)removeConfigurationForInterface: (OFString *)interfaceName -{ - int sock; - struct ifreq request; - - if (interfaceName.UTF8StringLength > IFNAMSIZ - 1) - @throw [OFOutOfRangeException exception]; - -# ifdef OF_MACOS - if ((sock = socket(AF_APPLETALK, SOCK_RAW, 0)) < 0) -# else - if ((sock = socket(AF_APPLETALK, SOCK_DGRAM, 0)) < 0) -# endif - @throw [OFSetOptionFailedException - exceptionWithObject: nil - errNo: OFSocketErrNo()]; - - /* - * NetBSD requires the address to be removed, while Linux ignores the - * address entirely. - */ - - memset(&request, 0, sizeof(request)); - strncpy(request.ifr_name, interfaceName.UTF8String, IFNAMSIZ - 1); - - if (ioctl(sock, SIOCGIFADDR, &request) != 0) - if (errno != EADDRNOTAVAIL) - @throw [OFSetOptionFailedException - exceptionWithObject: nil - errNo: OFSocketErrNo()]; - - if (ioctl(sock, SIOCDIFADDR, &request) != 0) - @throw [OFSetOptionFailedException - exceptionWithObject: nil - errNo: OFSocketErrNo()]; -} -#endif - - (OFSocketAddress)bindToNetwork: (uint16_t)network node: (uint8_t)node port: (uint8_t)port protocolType: (uint8_t)protocolType { Index: src/objfw-defs.h.in ================================================================== --- src/objfw-defs.h.in +++ src/objfw-defs.h.in @@ -2,11 +2,10 @@ #undef OF_BIG_ENDIAN #undef OF_CLASSIC_MACOS #undef OF_FLOAT_BIG_ENDIAN #undef OF_HAVE_AFUNIX_H #undef OF_HAVE_APPLETALK -#undef OF_HAVE_APPLETALK_IFCONFIG #undef OF_HAVE_ATOMIC_BUILTINS #undef OF_HAVE_ATOMIC_OPS #undef OF_HAVE_BUILTIN_BSWAP16 #undef OF_HAVE_BUILTIN_BSWAP32 #undef OF_HAVE_BUILTIN_BSWAP64