Uninitialized constant SOCKSSocket

I am running ruby 1.9.3 on a linux box. I would like to use
SOCKSSocket, however, I continue to run into the following error:

uninitialized constant SOCKSSocket

simple test using IRB
irb(main):001:0> require 'resolv-replace'
=> true
irb(main):002:0> SOCKSSocket
NameError: uninitialized constant SOCKSSocket
  from (irb):2
  from /usr/local/bin/irb:12:in `<main>'

here is the source code directly from resolv-replace.rb
class SOCKSSocket < TCPSocket
  # :stopdoc:
  alias original_resolv_initialize initialize
  # :startdoc:
  def initialize(host, serv)
    original_resolv_initialize(IPSocket.getaddress(host), port)
  end
end if defined? SOCKSSocket

I can't help but think that I need to install some dependency needed to
enable socks or something. Anything would be helpful.

···

--
Posted via http://www.ruby-forum.com/.

It appears the class is only being defined if it's already defined.
Maybe change the last line's "if" to "unless" ..?

···

On 29/03/2012, Resident Moron <lists@ruby-forum.com> wrote:

I am running ruby 1.9.3 on a linux box. I would like to use
SOCKSSocket, however, I continue to run into the following error:

uninitialized constant SOCKSSocket

simple test using IRB
irb(main):001:0> require 'resolv-replace'
=> true
irb(main):002:0> SOCKSSocket
NameError: uninitialized constant SOCKSSocket
  from (irb):2
  from /usr/local/bin/irb:12:in `<main>'

here is the source code directly from resolv-replace.rb
class SOCKSSocket < TCPSocket
  # :stopdoc:
  alias original_resolv_initialize initialize
  # :startdoc:
  def initialize(host, serv)
    original_resolv_initialize(IPSocket.getaddress(host), port)
  end
end if defined? SOCKSSocket

I can't help but think that I need to install some dependency needed to
enable socks or something. Anything would be helpful.

--
Posted via http://www.ruby-forum.com/.

--
  Matthew Kerwin, B.Sc (CompSci) (Hons)
  http://matthew.kerwin.net.au/

  "You'll never find a programming language that frees
  you from the burden of clarifying your ideas." - xkcd

Ok, it seems the configure script does not have --enable-socks as part
of it's list of valid options and that is the reason for the WARNING:
unrecognized options ...

I did not track down how to add --enable-socks to the list of valid
options, however, I did rig the script.

Edit: configure

find the section: Initialize some vars... and add
enable_option_checking=no
# Initialize some variables set by options.
enable_option_checking=no

Now, run:
./configure --prefix=/usr/local --enable-socks
make
sudo make install

ruby --version

ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-linux]

then, try it out in irb
irb(main):001:0> require 'socket'
=> true
irb(main):002:0> require 'resolv-replace'
=> true
irb(main):003:0> SOCKSSocket
=> SOCKSSocket
irb(main):004:0>

I haven't done anything using SOCKSSocket yet, however, at least now it
looks like I have it accessible to my code. Also, I assume there is
some ENV var to disable option checking or a better way around it. I
just did not track that down.

Thanks for your help!!

···

--
Posted via http://www.ruby-forum.com/.

Oh and be sure to stringify/symbolify that undefined const:

...
end unless defined? :SOCKSSocket

···

On 29/03/2012, Matthew Kerwin <matthew@kerwin.net.au> wrote:

It appears the class is only being defined if it's already defined.
Maybe change the last line's "if" to "unless" ..?

On 29/03/2012, Resident Moron <lists@ruby-forum.com> wrote:

I am running ruby 1.9.3 on a linux box. I would like to use
SOCKSSocket, however, I continue to run into the following error:

uninitialized constant SOCKSSocket

simple test using IRB
irb(main):001:0> require 'resolv-replace'
=> true
irb(main):002:0> SOCKSSocket
NameError: uninitialized constant SOCKSSocket
  from (irb):2
  from /usr/local/bin/irb:12:in `<main>'

here is the source code directly from resolv-replace.rb
class SOCKSSocket < TCPSocket
  # :stopdoc:
  alias original_resolv_initialize initialize
  # :startdoc:
  def initialize(host, serv)
    original_resolv_initialize(IPSocket.getaddress(host), port)
  end
end if defined? SOCKSSocket

I can't help but think that I need to install some dependency needed to
enable socks or something. Anything would be helpful.

--
Posted via http://www.ruby-forum.com/.

--
  Matthew Kerwin, B.Sc (CompSci) (Hons)
  http://matthew.kerwin.net.au/

  "You'll never find a programming language that frees
  you from the burden of clarifying your ideas." - xkcd

--
  Matthew Kerwin, B.Sc (CompSci) (Hons)
  http://matthew.kerwin.net.au/

  "You'll never find a programming language that frees
  you from the burden of clarifying your ideas." - xkcd

Actually, no, sorry, I just said a silly thing. Sorry, been writing
too much perl lately, my ruby is suffering.

...
end unless defined? SOCKSSocket

···

On 29/03/2012, Matthew Kerwin <matthew@kerwin.net.au> wrote:

Oh and be sure to stringify/symbolify that undefined const:

...
end unless defined? :SOCKSSocket

On 29/03/2012, Matthew Kerwin <matthew@kerwin.net.au> wrote:

It appears the class is only being defined if it's already defined.
Maybe change the last line's "if" to "unless" ..?

On 29/03/2012, Resident Moron <lists@ruby-forum.com> wrote:

I am running ruby 1.9.3 on a linux box. I would like to use
SOCKSSocket, however, I continue to run into the following error:

uninitialized constant SOCKSSocket

simple test using IRB
irb(main):001:0> require 'resolv-replace'
=> true
irb(main):002:0> SOCKSSocket
NameError: uninitialized constant SOCKSSocket
  from (irb):2
  from /usr/local/bin/irb:12:in `<main>'

here is the source code directly from resolv-replace.rb
class SOCKSSocket < TCPSocket
  # :stopdoc:
  alias original_resolv_initialize initialize
  # :startdoc:
  def initialize(host, serv)
    original_resolv_initialize(IPSocket.getaddress(host), port)
  end
end if defined? SOCKSSocket

I can't help but think that I need to install some dependency needed to
enable socks or something. Anything would be helpful.

--
Posted via http://www.ruby-forum.com/.

--
  Matthew Kerwin, B.Sc (CompSci) (Hons)
  http://matthew.kerwin.net.au/

  "You'll never find a programming language that frees
  you from the burden of clarifying your ideas." - xkcd

--
  Matthew Kerwin, B.Sc (CompSci) (Hons)
  http://matthew.kerwin.net.au/

  "You'll never find a programming language that frees
  you from the burden of clarifying your ideas." - xkcd

--
  Matthew Kerwin, B.Sc (CompSci) (Hons)
  http://matthew.kerwin.net.au/

  "You'll never find a programming language that frees
  you from the burden of clarifying your ideas." - xkcd

Matthew Kerwin wrote in post #1053913:

Actually, no, sorry, I just said a silly thing. Sorry, been writing
too much perl lately, my ruby is suffering.

...
end unless defined? SOCKSSocket

I am running ruby 1.9.3 on a linux box. I would like to use
  from /usr/local/bin/irb:12:in `<main>'

  Matthew Kerwin, B.Sc (CompSci) (Hons)

  http://matthew.kerwin.net.au/

  "You'll never find a programming language that frees
  you from the burden of clarifying your ideas." - xkcd

--
  Matthew Kerwin, B.Sc (CompSci) (Hons)
  http://matthew.kerwin.net.au/

  "You'll never find a programming language that frees
  you from the burden of clarifying your ideas." - xkcd

That source code is taken directly from resolv-replace.rb, which is part
of Ruby. I didn't write it.

On my linux box, the path to the file is:
/usr/local/lib/ruby/1.9.1/resolv-replace.rb

···

On 29/03/2012, Matthew Kerwin <matthew@kerwin.net.au> wrote:

--
Posted via http://www.ruby-forum.com/.

Ok, please forget everything I said before. My brain wasn't working
and I should have known better than to say anything on the internet in
that state.

SOCKSSocket appears to be an optional component of ruby. That's why
resolv-replace only monkey-patches the class if it already exists.

As an illustration, 'net/ftp' defines the following method:

    def open_socket(host, port)
      if defined? SOCKSSocket and ENV["SOCKS_SERVER"]
        @passive = true
        return SOCKSSocket.open(host, port)
      else
        return TCPSocket.open(host, port)
      end
    end

Perhaps you could do something similar (i.e. create a SOCKS socket if
you have SOCKS enabled, otherwise create a boring old TCP socket).

And if you really need the proxy behaviour, a quick google search
revealed the following gem: http://socksify.rubyforge.org/ which
*might* be useful.

···

--
Matthew Kerwin, B.Sc (CompSci) (Hons)
http://matthew.kerwin.net.au/
ABN: 59-013-727-651

"You'll never find a programming language that frees
you from the burden of clarifying your ideas." - xkcd

Matthew Kerwin wrote in post #1054099:

Ok, please forget everything I said before. My brain wasn't working
and I should have known better than to say anything on the internet in
that state.

SOCKSSocket appears to be an optional component of ruby. That's why
resolv-replace only monkey-patches the class if it already exists.

As an illustration, 'net/ftp' defines the following method:

    def open_socket(host, port)
      if defined? SOCKSSocket and ENV["SOCKS_SERVER"]
        @passive = true
        return SOCKSSocket.open(host, port)
      else
        return TCPSocket.open(host, port)
      end
    end

Perhaps you could do something similar (i.e. create a SOCKS socket if
you have SOCKS enabled, otherwise create a boring old TCP socket).

And if you really need the proxy behaviour, a quick google search
revealed the following gem: http://socksify.rubyforge.org/ which
*might* be useful.

--
Matthew Kerwin, B.Sc (CompSci) (Hons)
http://matthew.kerwin.net.au/
ABN: 59-013-727-651

"You'll never find a programming language that frees
you from the burden of clarifying your ideas." - xkcd

Ya know, it is a funny thing. I dug around in the ruby source code and
found all sorts of clues and my initial assumption as stated at the
beginning of this thread is some type of dependency or maybe I should
have said optional component. Anyway, I tried:

./configure --prefix=/usr/local --enable-socks

and

./configure --prefix=/usr/local --enable-socks=true

both result in a warning:

configure: WARNING: unrecognized options: --enable-socks

At this point, I don't understand why that option does not work. On the
surface, --enable-socks appears to be the right thing to do, however, I
haven't figured it out yet. Still looking.

Any ideas??

···

--
Posted via http://www.ruby-forum.com/.

The only things I've seen hinted at (I can't try right now because I'm
at work) are:

1) put another hyphen before enable socks:

  ./configure --prefix=/usr/local - --enable-socks

2) make sure libsocks is installed properly in your machine.

···

--
Matthew Kerwin, B.Sc (CompSci) (Hons)
http://matthew.kerwin.net.au/
ABN: 59-013-727-651

"You'll never find a programming language that frees
you from the burden of clarifying your ideas." - xkcd

Matthew Kerwin wrote in post #1054106:

The only things I've seen hinted at (I can't try right now because I'm
at work) are:

1) put another hyphen before enable socks:

  ./configure --prefix=/usr/local - --enable-socks

2) make sure libsocks is installed properly in your machine.

--
Matthew Kerwin, B.Sc (CompSci) (Hons)
http://matthew.kerwin.net.au/
ABN: 59-013-727-651

"You'll never find a programming language that frees
you from the burden of clarifying your ideas." - xkcd

Confirmed that libsocks is installed and the script complained about the
extra hyphen.

configure: error: unrecognized option: `-'

Something tells me it is going to be something incredibly simple and I'm
going to get a bad mark on my report card and mom is going to be very
mad!!

···

--
Posted via http://www.ruby-forum.com/.