ObjFW  Check-in [e5075e42ab]

Overview
Comment:OFDDPSocket: Return correct bound address on macOS
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e5075e42ab295e6e00a5374f935619e099bad82aa10f8d7813373413b4ee742d
User & Date: js on 2022-11-01 23:23:42
Other Links: manifest | tags
Context
2022-11-02
20:26
Use native endian for AppleTalk network on Windows check-in: 4571eada47 user: js tags: trunk
2022-11-01
23:23
OFDDPSocket: Return correct bound address on macOS check-in: e5075e42ab user: js tags: trunk
22:18
Implement OFDDPSocket using SOCK_RAW on macOS check-in: 41535b41da user: js tags: trunk
Changes

Modified src/OFDDPSocket.m from [0702a801d8] to [5573556d55].

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
#import "OFBindDDPSocketFailedException.h"
#import "OFNotOpenException.h"
#import "OFReadFailedException.h"
#import "OFWriteFailedException.h"

#ifdef OF_HAVE_NETAT_APPLETALK_H
# include <netat/ddp.h>










#endif

@implementation OFDDPSocket
@dynamic delegate;

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

#endif
	OFSocketAddress address;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
	int flags;
#endif

	if (_socket != OFInvalidSocketHandle)







>
>
>
>
>
>
>
>
>
>











>







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
#import "OFBindDDPSocketFailedException.h"
#import "OFNotOpenException.h"
#import "OFReadFailedException.h"
#import "OFWriteFailedException.h"

#ifdef OF_HAVE_NETAT_APPLETALK_H
# include <netat/ddp.h>
# include <sys/ioctl.h>

/* Unfortulately, there is no struct for the following in userland headers */
struct ATInterfaceConfig {
	char interfaceName[16];
	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
{
#ifdef OF_MACOS
	const int one = 1;
	struct ATInterfaceConfig config = { { 0 } };
#endif
	OFSocketAddress address;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
	int flags;
#endif

	if (_socket != OFInvalidSocketHandle)
119
120
121
122
123
124
125
126


127
128
129
130
131
132
133



134
135
136
137
138
139
140
				    node: node
				    port: port
				  socket: self
				   errNo: EAFNOSUPPORT];
	}

#ifdef OF_MACOS
	if (setsockopt(_socket, ATPROTO_NONE, DDP_HDRINCL, &one,


	    sizeof(one)) != 0)
		@throw [OFBindDDPSocketFailedException
		    exceptionWithNetwork: network
				    node: node
				    port: port
				  socket: self
				   errNo: OFSocketErrNo()];



#endif

	return address;
}

#ifdef OF_MACOS
- (size_t)receiveIntoBuffer: (void *)buffer







|
>
>
|






>
>
>







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
				    node: node
				    port: port
				  socket: self
				   errNo: EAFNOSUPPORT];
	}

#ifdef OF_MACOS
	if (setsockopt(_socket, ATPROTO_NONE, DDP_HDRINCL, &one, sizeof(one)) !=
	    0 ||
	    ioctl(_socket, _IOWR('a', 2, struct ATInterfaceConfig), &config) !=
	    0)
		@throw [OFBindDDPSocketFailedException
		    exceptionWithNetwork: network
				    node: node
				    port: port
				  socket: self
				   errNo: OFSocketErrNo()];

	OFSocketAddressSetAppleTalkNetwork(&address, config.address.s_net);
	OFSocketAddressSetAppleTalkNode(&address, config.address.s_node);
#endif

	return address;
}

#ifdef OF_MACOS
- (size_t)receiveIntoBuffer: (void *)buffer