ObjFW  Check-in [550bd1b7bb]

Overview
Comment:Remove support for configuring AppleTalk

This didn't work without problems on all OSes. Since ofatalkcfg is no
longer there, there is no reason to keep this for now. In the future, if
there is a more generic replacement for ofatalkcfg, this can just be
reverted.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 550bd1b7bb1f503568cefc3a0e0d070c340f6994e8aad3d9ae2241e3fd266e64
User & Date: js on 2023-05-21 13:10:40
Other Links: manifest | tags
Context
2023-05-21
17:47
Change how +[OFSystemInfo networkInterfaces] works check-in: 43c80a7593 user: js tags: trunk
13:10
Remove support for configuring AppleTalk check-in: 550bd1b7bb user: js tags: trunk
13:02
Remove utils/ofatalkcfg check-in: 2ef6db8a44 user: js tags: trunk
Changes

Modified configure.ac from [945ea348f4] to [579103d61e].

1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
			#ifdef AF_APPLETALK
			egrep_cpp_yes
			#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 <sys/socket.h>
				#endif
				#include <net/if.h>
			])
		])
	])

	AC_CHECK_FUNCS(paccept accept4, break)

	AC_CHECK_FUNCS(kqueue1 kqueue, [
		AC_DEFINE(HAVE_KQUEUE, 1, [Whether we have kqueue])







<
<
<
<
<
<
<
<
<
<
<
<
<







1717
1718
1719
1720
1721
1722
1723













1724
1725
1726
1727
1728
1729
1730
			#ifdef AF_APPLETALK
			egrep_cpp_yes
			#endif
		], [
			AC_DEFINE(OF_HAVE_APPLETALK, 1,
			    [Whether we have AppleTalk])
			AC_SUBST(USE_SRCS_APPLETALK, '${SRCS_APPLETALK}')













		])
	])

	AC_CHECK_FUNCS(paccept accept4, break)

	AC_CHECK_FUNCS(kqueue1 kqueue, [
		AC_DEFINE(HAVE_KQUEUE, 1, [Whether we have kqueue])

Modified src/OFDDPSocket.h from [6a455c4113] to [d9acc0eea7].

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#import "OFDatagramSocket.h"

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.
 */
@protocol OFDDPSocketDelegate <OFDatagramSocketDelegate>
@end







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







16
17
18
19
20
21
22





















































23
24
25
26
27
28
29
#import "OFDatagramSocket.h"

OF_ASSUME_NONNULL_BEGIN

@class OFString;
@class OFDictionary OF_GENERIC(KeyType, ObjectType);






















































/**
 * @protocol OFDDPSocketDelegate OFDDPSocket.h ObjFW/OFDDPSocket.h
 *
 * @brief A delegate for OFDDPSocket.
 */
@protocol OFDDPSocketDelegate <OFDatagramSocketDelegate>
@end
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
 *
 * @note The delegate is retained for as long as asynchronous operations are
 *	 still ongoing.
 */
@property OF_NULLABLE_PROPERTY (assign, nonatomic)
    id <OFDDPSocketDelegate> 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".
 * @param port The port to bind to. 0 means to pick one and return it via the
 *	       returned socket address.







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







66
67
68
69
70
71
72








































73
74
75
76
77
78
79
 *
 * @note The delegate is retained for as long as asynchronous operations are
 *	 still ongoing.
 */
@property OF_NULLABLE_PROPERTY (assign, nonatomic)
    id <OFDDPSocketDelegate> delegate;









































/**
 * @brief Bind the socket to the specified network, node and port.
 *
 * @param network The network to bind to. 0 means any.
 * @param node The node to bind to. 0 means "this node".
 * @param port The port to bind to. 0 means to pick one and return it via the
 *	       returned socket address.

Modified src/OFDDPSocket.m from [2eb53d96c3] to [0f90d0e13f].

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
	unsigned int flags;
	struct at_addr address, router;
	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
{
#ifdef OF_MACOS
	const int one = 1;







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<



<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







55
56
57
58
59
60
61















62
63
64

















































































































































































65
66
67
68
69
70
71
	unsigned int flags;
	struct at_addr address, router;
	unsigned short netStart, netEnd;
	at_nvestr_t zoneName;
};
#endif
















@implementation OFDDPSocket
@dynamic delegate;


















































































































































































- (OFSocketAddress)bindToNetwork: (uint16_t)network
			    node: (uint8_t)node
			    port: (uint8_t)port
		    protocolType: (uint8_t)protocolType
{
#ifdef OF_MACOS
	const int one = 1;

Modified src/objfw-defs.h.in from [e2e8bf6055] to [b557faae7b].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#undef OF_APPLE_RUNTIME
#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
#undef OF_HAVE_CHMOD
#undef OF_HAVE_CHOWN






<







1
2
3
4
5
6

7
8
9
10
11
12
13
#undef OF_APPLE_RUNTIME
#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_ATOMIC_BUILTINS
#undef OF_HAVE_ATOMIC_OPS
#undef OF_HAVE_BUILTIN_BSWAP16
#undef OF_HAVE_BUILTIN_BSWAP32
#undef OF_HAVE_BUILTIN_BSWAP64
#undef OF_HAVE_CHMOD
#undef OF_HAVE_CHOWN