JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-4672

Socket.getservbyname fails even if the service is defined in /etc/services

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.4, JRuby 1.5
    • Fix Version/s: None
    • Component/s: Extensions
    • Labels:
      None
    • Environment:
      github trunk, Java 6, Mac OS X 10.6.2
    • Number of attachments :
      0

      Description

      Consider:

      aotearoa:~$ ruby -rsocket -e 'p Socket.getservbyname("blp5")'
      48129
      aotearoa:~$ jruby -rsocket -e 'p Socket.getservbyname("blp5")'
      -e:1: no such service blp5/tcp (SocketError)
      aotearoa:~$ grep 48129 /etc/services 
      blp5            48129/tcp   # Bloomberg locator
      blp5            48129/udp   # Bloomberg locator
      

      There is no Java API that can do what getservbyname can do (see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4071389), so we are currently simply looking up a map in IANA.java. Obviously, this is not a very elegant solution.

      Perhaps we can use FFI here.

        Activity

        Hide
        Wayne Meissner added a comment -

        Given this functionality is probably needed by Jython as well, it could be put in a separate java library.

        It could use the native getservent/getservbyname() api if available, else it could fall back to parsing /etc/services, with a final fallback to a hardcoded table as in IANA.java

        Show
        Wayne Meissner added a comment - Given this functionality is probably needed by Jython as well, it could be put in a separate java library. It could use the native getservent/getservbyname() api if available, else it could fall back to parsing /etc/services, with a final fallback to a hardcoded table as in IANA.java
        Hide
        Wayne Meissner added a comment -

        And it is done: http://github.com/wmeissner/jnr-netdb

        That will try and access the native getservbyname/getservbyport functions and use them if it can. If it cannot, it will fallback to the same table as contained in IANA.java in jruby.

        Its not wired in to JRuby yet, but that won't be too hard.

        Show
        Wayne Meissner added a comment - And it is done: http://github.com/wmeissner/jnr-netdb That will try and access the native getservbyname/getservbyport functions and use them if it can. If it cannot, it will fallback to the same table as contained in IANA.java in jruby. Its not wired in to JRuby yet, but that won't be too hard.
        Hide
        Wayne Meissner added a comment -

        Fixed in commit f8f8526605de73c2162197f6422e670e2afbec65

        Show
        Wayne Meissner added a comment - Fixed in commit f8f8526605de73c2162197f6422e670e2afbec65
        Hide
        Hiro Asari added a comment -

        It looks like the value is signed.

        $ jruby -v -rsocket -e 'p Socket.getservbyname("blp5")'
        jruby 1.5.0.dev (ruby 1.8.7 patchlevel 174) (2010-03-25 d15a53c) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_17) [x86_64-java]
        -17407
        

        This value should be 48129.

        Show
        Hiro Asari added a comment - It looks like the value is signed. $ jruby -v -rsocket -e 'p Socket.getservbyname("blp5")' jruby 1.5.0.dev (ruby 1.8.7 patchlevel 174) (2010-03-25 d15a53c) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_17) [x86_64-java] -17407 This value should be 48129.
        Hide
        Wayne Meissner added a comment -

        That should be fixed in jnr-netdb now. You'll need to build it from source to verify that it is fixed.

        Show
        Wayne Meissner added a comment - That should be fixed in jnr-netdb now. You'll need to build it from source to verify that it is fixed.
        Hide
        Mikael From added a comment -

        Commit f8f8526605de73c2162197f6422e670e2afbec65 results in following failure when I run
        'ant test' on Windows XP SP3.

        C:\NBProjects\jruby>jruby -v
        jruby 1.5.0.dev (ruby 1.8.7 patchlevel 174) (2010-03-26 f8f8526) (Java HotSpot(TM) Client VM 1.6.0_13) [x86-java]

        run-junit-interpreted-short:
        [echo] compile=OFF, jit.threshold=20, jit.maxsize=1000000000, jit.max=-1, objectspace=true threadpool=false reflection=false version=ruby1_8
        [junit] Testsuite: org.jruby.test.ScriptTestSuite
        [junit] EXCEPTION raised 18 –
        [junit] Exception: no such service http/tcp
        [junit] ./test/testSocket.rb:136
        [junit] ./test/testSocket.rb:99:in `load'
        [junit] ./test/minirunit.rb:99:in `test_load'
        [junit] test\testSocket.rb_generated_test.rb:3)
        [junit] Tests run: 56, Failures: 1, Errors: 0, Time elapsed: 5,14 sec
        [junit]
        [junit] Testcase: testSocket.rb(org.jruby.test.ScriptTestSuite$ScriptTest):FAILED

        JIRB session with corresponding test:
        C:\NBProjects\jruby>jirb
        irb(main):001:0> require 'socket'
        => true
        irb(main):002:0> #JRUBY-2666
        irb(main):003:0* empty_host_addr_info = Socket::getaddrinfo("", "http",
        irb(main):004:1* Socket::AF_INET,
        irb(main):005:1* Socket::SOCK_STREAM,
        irb(main):006:1* Socket::IPPROTO_TCP,
        irb(main):007:1* Socket::AI_PASSIVE)
        SocketError: no such service http/tcp
        from (irb):4
        irb(main):008:0>

        Show
        Mikael From added a comment - Commit f8f8526605de73c2162197f6422e670e2afbec65 results in following failure when I run 'ant test' on Windows XP SP3. C:\NBProjects\jruby>jruby -v jruby 1.5.0.dev (ruby 1.8.7 patchlevel 174) (2010-03-26 f8f8526) (Java HotSpot(TM) Client VM 1.6.0_13) [x86-java] run-junit-interpreted-short: [echo] compile=OFF, jit.threshold=20, jit.maxsize=1000000000, jit.max=-1, objectspace=true threadpool=false reflection=false version=ruby1_8 [junit] Testsuite: org.jruby.test.ScriptTestSuite [junit] EXCEPTION raised 18 – [junit] Exception: no such service http/tcp [junit] ./test/testSocket.rb:136 [junit] ./test/testSocket.rb:99:in `load' [junit] ./test/minirunit.rb:99:in `test_load' [junit] test\testSocket.rb_generated_test.rb:3) [junit] Tests run: 56, Failures: 1, Errors: 0, Time elapsed: 5,14 sec [junit] [junit] Testcase: testSocket.rb(org.jruby.test.ScriptTestSuite$ScriptTest):FAILED JIRB session with corresponding test: C:\NBProjects\jruby>jirb irb(main):001:0> require 'socket' => true irb(main):002:0> # JRUBY-2666 irb(main):003:0* empty_host_addr_info = Socket::getaddrinfo("", "http", irb(main):004:1* Socket::AF_INET, irb(main):005:1* Socket::SOCK_STREAM, irb(main):006:1* Socket::IPPROTO_TCP, irb(main):007:1* Socket::AI_PASSIVE) SocketError: no such service http/tcp from (irb):4 irb(main):008:0>
        Hide
        Mikael From added a comment -

        Previous commit gives following result in JIRB:

        => [["AF_INET", 80, "0.0.0.0", "0.0.0.0", 4, 1, 6]]

        Show
        Mikael From added a comment - Previous commit gives following result in JIRB: => [ ["AF_INET", 80, "0.0.0.0", "0.0.0.0", 4, 1, 6] ]
        Hide
        Vladimir Sizikov added a comment -

        I've committed some fixes to jnr-netdb to resolve failures on Windows and 'ant test' passes with updated jnr-netdb.jar. We just need to wait till the updated version is integrated into jruby proper.

        So, Windows problem is resolved.

        BUT, the issue with negative values is not yet fully fixed, I see that on Windows and Linux.

        Show
        Vladimir Sizikov added a comment - I've committed some fixes to jnr-netdb to resolve failures on Windows and 'ant test' passes with updated jnr-netdb.jar. We just need to wait till the updated version is integrated into jruby proper. So, Windows problem is resolved. BUT , the issue with negative values is not yet fully fixed, I see that on Windows and Linux.
        Hide
        Hiro Asari added a comment -

        This is fixed in b4133c9.

        Show
        Hiro Asari added a comment - This is fixed in b4133c9.

          People

          • Assignee:
            Wayne Meissner
            Reporter:
            Hiro Asari
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: