ObjFW  Diff

Differences From Artifact [11bd6fb256]:

  • File src/OFDDPSocket.m — part of check-in [9c2f20e736] at 2022-11-03 00:14:27 on branch trunk — OFDDPSocket: Don't include the type with the data

    This seems to be an oddity limited to OSes that have implemented DDP
    exclusively for netatalk, while macOS and Windows don't include it with
    the data.

    While on macOS it's possible to achieve the previous behavior via some
    hacks, this is impossible on Windows, so the proper approach is to
    handle it like everybody else: Specify the protocol type when binding
    and only handle packets of the correct protocol type. (user: js, size: 7082) [annotate] [blame] [check-ins using] [more...]

To Artifact [d532fdd70f]:


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
42
43
44
45
46
47
48




49
50
51
52
53
54
55







-
-
-
-







	unsigned int flags;
	struct at_addr address, router;
	unsigned short netStart, netEnd;
	at_nvestr_t zoneName;
};
#endif

#ifndef ATPROTO_BASE
# define ATPROTO_BASE 0
#endif

@implementation OFDDPSocket
@dynamic delegate;

- (OFSocketAddress)bindToNetwork: (uint16_t)network
			    node: (uint8_t)node
			    port: (uint8_t)port
		    protocolType: (uint8_t)protocolType
71
72
73
74
75
76
77
78

79
80
81

82
83
84



85
86
87
88
89
90
91
67
68
69
70
71
72
73

74
75
76

77
78
79
80
81
82
83
84
85
86
87
88
89
90







-
+


-
+



+
+
+







		@throw [OFInvalidArgumentException exception];

	if (_socket != OFInvalidSocketHandle)
		@throw [OFAlreadyConnectedException exceptionWithSocket: self];

	address = OFSocketAddressMakeAppleTalk(network, node, port);

#ifdef OF_MACOS
#if defined(OF_MACOS)
	if ((_socket = socket(address.sockaddr.at.sat_family,
	    SOCK_RAW | SOCK_CLOEXEC, protocolType)) == OFInvalidSocketHandle)
#else
#elif defined(OF_WINDOWS)
	if ((_socket = socket(address.sockaddr.at.sat_family,
	    SOCK_DGRAM | SOCK_CLOEXEC, ATPROTO_BASE + protocolType)) ==
	    OFInvalidSocketHandle)
#else
	if ((_socket = socket(address.sockaddr.at.sat_family,
	    SOCK_DGRAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle)
#endif
		@throw [OFBindDDPSocketFailedException
		    exceptionWithNetwork: network
				    node: node
				    port: port
			    protocolType: protocolType
				  socket: self
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
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







+
-
-
+
+
+


















+
-
-
+
+
+







	ssize_t ret;
	uint8_t protocolType;
	struct iovec iov[2] = {
		{ &protocolType, 1 },
		{ buffer, length }
	};
	struct msghdr msg = {
		.msg_name = (sender != NULL
		.msg_name = (struct sockaddr *)&sender->sockaddr,
		.msg_namelen = (socklen_t)sizeof(sender->sockaddr),
		    ? (struct sockaddr *)&sender->sockaddr : NULL),
		.msg_namelen = (sender != NULL
		    ? (socklen_t)sizeof(sender->sockaddr) : 0),
		.msg_iov = iov,
		.msg_iovlen = 2
	};

	if (_socket == OFInvalidSocketHandle)
		@throw [OFNotOpenException exceptionWithObject: self];

	if ((ret = recvmsg(_socket, &msg, 0)) < 0)
		@throw [OFReadFailedException
		    exceptionWithObject: self
			requestedLength: length
				  errNo: OFSocketErrNo()];

	if (ret < 1 || protocolType != _protocolType)
		@throw [OFReadFailedException exceptionWithObject: self
						  requestedLength: length
							    errNo: ENOMSG];

	if (sender != NULL) {
	sender->length = msg.msg_namelen;
	sender->family = OFSocketAddressFamilyAppleTalk;
		sender->length = msg.msg_namelen;
		sender->family = OFSocketAddressFamilyAppleTalk;
	}

	return ret - 1;
}

- (void)sendBuffer: (const void *)buffer
	    length: (size_t)length
	  receiver: (const OFSocketAddress *)receiver