Ruby  2.5.0dev(2017-10-22revision60238)
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  GetOpenFile(sock, fptr);
45  shutdown(fptr->fd, 2);
46  return rb_io_close(sock);
47 }
48 #endif
49 #endif
50 
51 void
53 {
54 #ifdef SOCKS
55  /*
56  * Document-class: SOCKSSocket < TCPSocket
57  *
58  * SOCKS is an Internet protocol that routes packets between a client and
59  * a server through a proxy server. SOCKS5, if supported, additionally
60  * provides authentication so only authorized users may access a server.
61  */
62  rb_cSOCKSSocket = rb_define_class("SOCKSSocket", rb_cTCPSocket);
63  rb_define_method(rb_cSOCKSSocket, "initialize", socks_init, 2);
64 #ifdef SOCKS5
65  rb_define_method(rb_cSOCKSSocket, "close", socks_s_close, 0);
66 #endif
67 #endif
68 }
Definition: io.h:62
#define INET_SOCKS
Definition: rubysocket.h:223
#define GetOpenFile(obj, fp)
Definition: io.h:120
VALUE rb_cTCPSocket
Definition: init.c:15
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
Definition: class.c:646
int fd
Definition: io.h:64
void rsock_init_sockssocket(void)
Definition: sockssocket.c:52
#define Qnil
Definition: ruby.h:438
VALUE rb_io_close(VALUE)
Definition: io.c:4501
unsigned long VALUE
Definition: ruby.h:85
#define shutdown(a, b)
Definition: io.c:599
VALUE rsock_init_inetsock(VALUE sock, VALUE remote_host, VALUE remote_serv, VALUE local_host, VALUE local_serv, int type)
Definition: ipsocket.c:152
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1515