Link to home
Start Free TrialLog in
Avatar of egono
egono

asked on

Create a UUID without JNI

howto?
Avatar of girionis
girionis
Flag of Greece image

 Take a look here: http://www.jguru.com/faq/view.jsp?EID=261286 it might come in handy.

  Hope it helps.
Avatar of egono
egono

ASKER

thanks - but I said: "without JNI"

I already know this one http://www.jguru.com/forums/view.jsp?EID=707121 but I'm not sure if it's free.
 Oops.. Sorry, I thought you said with. Sorry again.
Avatar of egono

ASKER

no problem :-)

in the meantime I've found http://www.doomdark.org/doomdark/proj/jug/index.html

the only downside is, that it uses a faked ethernet address, but it seems to be impossible to get the mac address without JNI

 Why would you not want to use JNI?
Avatar of egono

ASKER

it should run on several platforms (mainly win and linux) and I may get it work on windows but I have absolutely no clue about linux :-(
For what do you need a UUID?
What about using the ObjID class of java.rmi.server? From the Javadoc:

"The ObjID() constructor can be used to generate a unique object identifier. Such an ObjID is unique over time with respect to the host it is generated on."

This is pure Java (JDK 1.1).
From an expired Internet draft:

----- 8< snip 8< -----
4. Node IDs when no IEEE 802 network card is available

  If a system wants to generate UUIDs but has no IEE 802 compliant
  network card or other source of IEEE 802 addresses, then this section
  describes how to generate one.

  The ideal solution is to obtain a 47 bit cryptographic quality random
  number, and use it as the low 47 bits of the node ID, with the most
  significant bit of the first octet of the node ID set to 1. This bit
  is the unicast/multicast bit, which will never be set in IEEE 802
  addresses obtained from network cards; hence, there can never be a
  conflict between UUIDs generated by machines with and without network
  cards.
----- 8< snip 8< -----

You'll find the whole draft at http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt, which describes the format of UUIDs in detail.

Note that getting the host's real MAC address from Java will likely require JNI or running an external program.  I've seen in some reference material that it may also be possible if the host is running an SNMP agent, which can be queried.

I suggest you create your GUID using whatever way is best on your primary target platforms, and then use the above method as a fallback.

ASKER CERTIFIED SOLUTION
Avatar of Jim Cakalic
Jim Cakalic
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of egono

ASKER

thanks to all!

Jim Cakalic - I would accept your comment as answer, but my linux server says "command not found" on the ifconfig command. I found the program on "/sbin/ifconfig", it seems my PATH envirnoment varaible doesn't contain /sbin/, so would like to know if the ifconfig program is always on /sbin/ ?
If yes then I would set the ifconfig command to "/sbin/ifconfig"

thanks again
Change the path to point there by doing:

export PATH=$PATH:/sbin

  You can have you r path reloaded automaticalyl every time you turn on your computer by putting the PATH line in your .bashrc file.

  Hope it helps.
/sbin is the system binaries directory. I hadn't thought much about it before, but all info that I have been able to find indicates that ifconfig will be present there on linux systems. Of course, there are many variants of Unix that have been derived over the years. Another common (historical) path for ifconfig is /etc.

Should you be worried about accessibility, one document I found states: "The division between /bin and /sbin was not created for security reasons or to prevent users from seeing the operating system, but to provide a good partition between binaries that everyone uses and ones that are primarily used for administration tasks. There is no inherent security advantage in making /sbin off-limits for users."

Jim
Avatar of egono

ASKER

sorry for the delay ...

thanks again!
Avatar of egono

ASKER

btw - I'm using this implementation

 http://www.doomdark.org/doomdark/proj/jug/index.html

with jim's code to get the MAC address