Ruby
1.9.3p429(2013-05-15revision40747)
Main Page
Modules
Data Structures
Files
File List
Globals
ext
socket
sockssocket.c
Go to the documentation of this file.
1
/************************************************
2
3
sockssocket.c -
4
5
created at: Thu Mar 31 12:21:29 JST 1994
6
7
Copyright (C) 1993-2007 Yukihiro Matsumoto
8
9
************************************************/
10
11
#include "
rubysocket.h
"
12
13
#ifdef SOCKS
14
/*
15
* call-seq:
16
* SOCKSSocket.new(host, serv) => socket
17
*
18
* Opens a SOCKS connection to +host+ via the SOCKS server +serv+.
19
*
20
*/
21
static
VALUE
22
socks_init(
VALUE
sock,
VALUE
host,
VALUE
serv)
23
{
24
static
int
init
= 0;
25
26
if
(init == 0) {
27
SOCKSinit(
"ruby"
);
28
init = 1;
29
}
30
31
return
rsock_init_inetsock
(sock, host, serv,
Qnil
,
Qnil
,
INET_SOCKS
);
32
}
33
34
#ifdef SOCKS5
35
/*
36
* Closes the SOCKS connection.
37
*
38
*/
39
static
VALUE
40
socks_s_close(
VALUE
sock)
41
{
42
rb_io_t
*fptr;
43
44
if
(
rb_safe_level
() >= 4 && !
OBJ_TAINTED
(sock)) {
45
rb_raise
(
rb_eSecurityError
,
"Insecure: can't close socket"
);
46
}
47
GetOpenFile
(sock, fptr);
48
shutdown
(fptr->
fd
, 2);
49
return
rb_io_close
(sock);
50
}
51
#endif
52
#endif
53
54
void
55
rsock_init_sockssocket
(
void
)
56
{
57
#ifdef SOCKS
58
/*
59
* Document-class: SOCKSSocket < TCPSocket
60
*
61
* SOCKS is an Internet protocol that routes packets between a client and
62
* a server through a proxy server. SOCKS5, if supported, additionally
63
* provides authentication so only authorized users may access a server.
64
*/
65
rb_cSOCKSSocket =
rb_define_class
(
"SOCKSSocket"
,
rb_cTCPSocket
);
66
rb_define_method
(rb_cSOCKSSocket,
"initialize"
, socks_init, 2);
67
#ifdef SOCKS5
68
rb_define_method
(rb_cSOCKSSocket,
"close"
, socks_s_close, 0);
69
#endif
70
#endif
71
}
72
Generated on Thu May 23 2013 20:33:06 for Ruby by
1.8.3