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
|
@implementation OFTCPSocket (SOCKS5)
- (void)OF_SOCKS5ConnectToHost: (OFString*)host
port: (uint16_t)port
{
const char request[] = { 5, 1, 0, 3 };
char reply[256];
bool wasWriteBufferEnabled;
/* 5 1 0 -> no authentication */
[self writeBuffer: request
length: 3];
[self readIntoBuffer: reply
exactLength: 2];
if (reply[0] != 5 || reply[1] != 0) {
[self close];
@throw [OFConnectionFailedException exceptionWithHost: host
port: port
socket: self];
}
wasWriteBufferEnabled = [self isWriteBufferEnabled];
[self setWriteBufferEnabled: true];
/* CONNECT request */
[self writeBuffer: request
length: 4];
[self writeInt8: [host UTF8StringLength]];
[self writeBuffer: [host UTF8String]
length: [host UTF8StringLength]];
[self writeBigEndianInt16: port];
[self flushWriteBuffer];
[self setWriteBufferEnabled: wasWriteBufferEnabled];
[self readIntoBuffer: reply
exactLength: 4];
if (reply[0] != 5 || reply[1] != 0 || reply[2] != 0) {
[self close];
@throw [OFConnectionFailedException exceptionWithHost: host
|
|
|
|
|
|
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
|
@implementation OFTCPSocket (SOCKS5)
- (void)OF_SOCKS5ConnectToHost: (OFString*)host
port: (uint16_t)port
{
const char request[] = { 5, 1, 0, 3 };
char reply[256];
bool wasWriteBuffered;
/* 5 1 0 -> no authentication */
[self writeBuffer: request
length: 3];
[self readIntoBuffer: reply
exactLength: 2];
if (reply[0] != 5 || reply[1] != 0) {
[self close];
@throw [OFConnectionFailedException exceptionWithHost: host
port: port
socket: self];
}
wasWriteBuffered = [self isWriteBuffered];
[self setWriteBuffered: true];
/* CONNECT request */
[self writeBuffer: request
length: 4];
[self writeInt8: [host UTF8StringLength]];
[self writeBuffer: [host UTF8String]
length: [host UTF8StringLength]];
[self writeBigEndianInt16: port];
[self flushWriteBuffer];
[self setWriteBuffered: wasWriteBuffered];
[self readIntoBuffer: reply
exactLength: 4];
if (reply[0] != 5 || reply[1] != 0 || reply[2] != 0) {
[self close];
@throw [OFConnectionFailedException exceptionWithHost: host
|