JRuby

how to get mac address, gem uuidtools 1.0.2 not working

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: JRuby 1.1RC2
  • Fix Version/s: JRuby 1.1RC1
  • Component/s: None
  • Labels:
    None
  • Environment:
    MacOS X 10.4.11, JRuby trunk r5456, Java 1.5.0_13
  • Number of attachments :
    0

Description

The gen uuidtools produces uuids of various types and one of the inputs is the local computer's MAC address.

Using this gem produces an error

irb(main):001:0> require 'uuidtools'
=> true
irb(main):002:0> UUID.timestamp_create().to_s
ifconfig: interface 2>&1 does not exist
usage: ifconfig [-L] interface address_family [address [dest_address]]
                [parameters]
       ifconfig interface create
       ifconfig -a [-L] [-d] [-m] [-u] [address_family]
       ifconfig -l [-d] [-u] [address_family]
       ifconfig [-L] [-d] [-m] [-u]
ifconfig: interface | does not exist
StandardError: MAC address could not be autodetected.  Set the MAC address manually.
        from /Users/stephen/dev/jruby_trunk/jruby/lib/ruby/gems/1.8/gems/uuidtools-1.0.2/lib/uuidtools.rb:238:in `timestamp_create'
        from /Users/stephen/dev/jruby_trunk/jruby/lib/ruby/gems/1.8/gems/uuidtools-1.0.2/lib/uuidtools.rb:226:in `synchronize'
        from /Users/stephen/dev/jruby_trunk/jruby/lib/ruby/gems/1.8/gems/uuidtools-1.0.2/lib/uuidtools.rb:226:in `timestamp_create'
        from /Users/stephen/dev/jruby_trunk/jruby/lib/ruby/gems/1.8/gems/uuidtools-1.0.2/lib/uuidtools.rb:226:in `signal_status'
irb(main):003:0> RUBY_PLATFORM
=> "java"

The gem itself uses a platform-dependent call to ifconfig to determine the MAC address. Currently the gem does not check for:

RUBY_PLATFORM == "java"

What mechanism can be used from JRuby to get the MAC address?

UUIDTools home page: http://sporkmonger.com/projects/uuidtools

See JRUBY-1676 and JRUBY-1557 for descriptions of problems passing parameters to shell commands like ifconfig.

Activity

Hide
Stephen Bannasch added a comment -

As of r5478 Ara Howard's macaddr-0.0.2 gem works:

$ jirb
irb(main):001:0> require 'macaddr'
=> true
irb(main):002:0> Mac.addr
=> "00:1b:63:1e:b2:da"

I'll look into getting the uuidtools gem to depend on macaddr gem.

Here are some interesting puzzles however. The following tests are on MacOS X 10.4.11:

From the shell:

$ /sbin/ifconfig 2> /dev/null
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
        inet6 ::1 prefixlen 128 
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
        inet 127.0.0.1 netmask 0xff000000 
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        inet6 fe80::21b:63ff:fe1e:b2da%en0 prefixlen 64 scopeid 0x4 
        inet 63.138.152.125 netmask 0xffffff00 broadcast 63.138.152.255
        ether 00:1b:63:1e:b2:da 
        media: autoselect (1000baseT <full-duplex>) status: active
        supported media: autoselect 10baseT/UTP <half-duplex> 10baseT/UTP <full-duplex> 10baseT/UTP <full-duplex,hw-loopback> 10baseT/UTP <full-duplex,flow-control> 100baseTX <half-duplex> 100baseTX <full-duplex> 100baseTX <full-duplex,hw-loopback> 100baseTX <full-duplex,flow-control> 1000baseT <full-duplex> 1000baseT <full-duplex,hw-loopback> 1000baseT <full-duplex,flow-control> none
en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        inet6 fe80::21b:63ff:febf:4a9d%en1 prefixlen 64 scopeid 0x5 
        inet 63.138.152.170 netmask 0xffffff00 broadcast 63.138.152.255
        ether 00:1b:63:bf:4a:9d 
        media: autoselect status: active
        supported media: autoselect
wlt1: flags=41<UP,RUNNING> mtu 1500
fw1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 494
        lladdr 00:1b:63:ff:fe:67:cc:4c 
        media: autoselect <full-duplex> status: inactive
        supported media: autoselect <full-duplex>

From jirb using backtic:

irb(main):003:0> `/sbin/ifconfig 2> /dev/null`
ifconfig: interface 2> does not exist
=> ""

from jirb using IO.popen

irb(main):004:0> IO.popen("/sbin/ifconfig 2> /dev/null") {|fd| fd.readlines}
=> []

from jirb using IO.popen (but relying on my path to find ifconfig – which is in /sbin/ifconfig).

irb(main):006:0> stdout = IO.popen("ifconfig 2> /dev/null") {|fd| fd.readlines}      
=> ["lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384\n",  ...
Show
Stephen Bannasch added a comment - As of r5478 Ara Howard's macaddr-0.0.2 gem works:
$ jirb
irb(main):001:0> require 'macaddr'
=> true
irb(main):002:0> Mac.addr
=> "00:1b:63:1e:b2:da"
I'll look into getting the uuidtools gem to depend on macaddr gem. Here are some interesting puzzles however. The following tests are on MacOS X 10.4.11: From the shell:
$ /sbin/ifconfig 2> /dev/null
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
        inet6 ::1 prefixlen 128 
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
        inet 127.0.0.1 netmask 0xff000000 
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        inet6 fe80::21b:63ff:fe1e:b2da%en0 prefixlen 64 scopeid 0x4 
        inet 63.138.152.125 netmask 0xffffff00 broadcast 63.138.152.255
        ether 00:1b:63:1e:b2:da 
        media: autoselect (1000baseT <full-duplex>) status: active
        supported media: autoselect 10baseT/UTP <half-duplex> 10baseT/UTP <full-duplex> 10baseT/UTP <full-duplex,hw-loopback> 10baseT/UTP <full-duplex,flow-control> 100baseTX <half-duplex> 100baseTX <full-duplex> 100baseTX <full-duplex,hw-loopback> 100baseTX <full-duplex,flow-control> 1000baseT <full-duplex> 1000baseT <full-duplex,hw-loopback> 1000baseT <full-duplex,flow-control> none
en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        inet6 fe80::21b:63ff:febf:4a9d%en1 prefixlen 64 scopeid 0x5 
        inet 63.138.152.170 netmask 0xffffff00 broadcast 63.138.152.255
        ether 00:1b:63:bf:4a:9d 
        media: autoselect status: active
        supported media: autoselect
wlt1: flags=41<UP,RUNNING> mtu 1500
fw1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 494
        lladdr 00:1b:63:ff:fe:67:cc:4c 
        media: autoselect <full-duplex> status: inactive
        supported media: autoselect <full-duplex>
From jirb using backtic:
irb(main):003:0> `/sbin/ifconfig 2> /dev/null`
ifconfig: interface 2> does not exist
=> ""
from jirb using IO.popen
irb(main):004:0> IO.popen("/sbin/ifconfig 2> /dev/null") {|fd| fd.readlines}
=> []
from jirb using IO.popen (but relying on my path to find ifconfig – which is in /sbin/ifconfig).
irb(main):006:0> stdout = IO.popen("ifconfig 2> /dev/null") {|fd| fd.readlines}      
=> ["lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384\n",  ...
Hide
Charles Oliver Nutter added a comment -

Seems like recent updates have fixed this. I'm marking it resolved, since there's another bug for the backtick/system/exec shell redirect stuff.

Show
Charles Oliver Nutter added a comment - Seems like recent updates have fixed this. I'm marking it resolved, since there's another bug for the backtick/system/exec shell redirect stuff.
Hide
Stephen Bannasch added a comment -

uuidtools gem updated to v1.0.3
now works with JRuby trunk

Show
Stephen Bannasch added a comment - uuidtools gem updated to v1.0.3 now works with JRuby trunk

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: