︙ | | | ︙ | |
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#import "socket_helpers.h"
/* Reference for static linking */
int _OFTCPSocket_SOCKS5_reference;
static void
send_or_exception(OFTCPSocket *self, of_socket_t sock, char *buffer,
int length)
{
#ifndef OF_WINDOWS
ssize_t bytesWritten;
#else
int bytesWritten;
#endif
|
|
<
|
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#import "socket_helpers.h"
/* Reference for static linking */
int _OFTCPSocket_SOCKS5_reference;
static void
sendOrThrow(OFTCPSocket *self, of_socket_t sock, char *buffer, int length)
{
#ifndef OF_WINDOWS
ssize_t bytesWritten;
#else
int bytesWritten;
#endif
|
︙ | | | ︙ | |
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length
bytesWritten: bytesWritten
errNo: 0];
}
static void
recv_exact(OFTCPSocket *self, of_socket_t sock, char *buffer, int length)
{
while (length > 0) {
ssize_t ret = recv(sock, (void *)buffer, length, 0);
if (ret < 0)
@throw [OFReadFailedException
exceptionWithObject: self
|
|
|
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length
bytesWritten: bytesWritten
errNo: 0];
}
static void
recvExact(OFTCPSocket *self, of_socket_t sock, char *buffer, int length)
{
while (length > 0) {
ssize_t ret = recv(sock, (void *)buffer, length, 0);
if (ret < 0)
@throw [OFReadFailedException
exceptionWithObject: self
|
︙ | | | ︙ | |
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
void *pool;
OFMutableData *connectRequest;
if ([host UTF8StringLength] > 255)
@throw [OFOutOfRangeException exception];
/* 5 1 0 -> no authentication */
send_or_exception(self, _socket, request, 3);
recv_exact(self, _socket, reply, 2);
if (reply[0] != 5 || reply[1] != 0) {
[self close];
@throw [OFConnectionFailedException
exceptionWithHost: host
port: port
socket: self
|
|
|
|
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
void *pool;
OFMutableData *connectRequest;
if ([host UTF8StringLength] > 255)
@throw [OFOutOfRangeException exception];
/* 5 1 0 -> no authentication */
sendOrThrow(self, _socket, request, 3);
recvExact(self, _socket, reply, 2);
if (reply[0] != 5 || reply[1] != 0) {
[self close];
@throw [OFConnectionFailedException
exceptionWithHost: host
port: port
socket: self
|
︙ | | | ︙ | |
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
request[1] = port & 0xFF;
[connectRequest addItems: request
count: 2];
if ([connectRequest count] > INT_MAX)
@throw [OFOutOfRangeException exception];
send_or_exception(self, _socket,
[connectRequest items], (int)[connectRequest count]);
objc_autoreleasePoolPop(pool);
recv_exact(self, _socket, reply, 4);
if (reply[0] != 5 || reply[2] != 0) {
[self close];
@throw [OFConnectionFailedException
exceptionWithHost: host
port: port
socket: self
|
|
|
|
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
request[1] = port & 0xFF;
[connectRequest addItems: request
count: 2];
if ([connectRequest count] > INT_MAX)
@throw [OFOutOfRangeException exception];
sendOrThrow(self, _socket,
[connectRequest items], (int)[connectRequest count]);
objc_autoreleasePoolPop(pool);
recvExact(self, _socket, reply, 4);
if (reply[0] != 5 || reply[2] != 0) {
[self close];
@throw [OFConnectionFailedException
exceptionWithHost: host
port: port
socket: self
|
︙ | | | ︙ | |
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
|
socket: self
errNo: errNo];
}
/* Skip the rest of the reply */
switch (reply[3]) {
case 1: /* IPv4 */
recv_exact(self, _socket, reply, 4);
break;
case 3: /* Domain name */
recv_exact(self, _socket, reply, 1);
recv_exact(self, _socket, reply, reply[0]);
break;
case 4: /* IPv6 */
recv_exact(self, _socket, reply, 16);
break;
default:
[self close];
@throw [OFConnectionFailedException
exceptionWithHost: host
port: port
socket: self
errNo: EPROTONOSUPPORT];
}
recv_exact(self, _socket, reply, 2);
}
@end
|
|
|
|
|
|
|
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
|
socket: self
errNo: errNo];
}
/* Skip the rest of the reply */
switch (reply[3]) {
case 1: /* IPv4 */
recvExact(self, _socket, reply, 4);
break;
case 3: /* Domain name */
recvExact(self, _socket, reply, 1);
recvExact(self, _socket, reply, reply[0]);
break;
case 4: /* IPv6 */
recvExact(self, _socket, reply, 16);
break;
default:
[self close];
@throw [OFConnectionFailedException
exceptionWithHost: host
port: port
socket: self
errNo: EPROTONOSUPPORT];
}
recvExact(self, _socket, reply, 2);
}
@end
|