|
Home > Archive > Unix Programming > October 2004 > Unique hardware id (hw address of nic, etc)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Unique hardware id (hw address of nic, etc)
|
|
|
| Hi,
I'm trying to generate a (possibly) unique id for a machine. For that,
I'd like to include the hardware address of the first nic on the
system. Is there a (if possible portable) way to programmatically (C)
find this address?
I searched on this newsgroup for this topic and found references to
first pinging and then using arp -a, but that would be difficult to do
from within a C program and would not be portable (as the output
format of arp would differ on different OSs or systems).
What other things could I possibly include in the unique id. Is there
a good way to programmatically find an ID (or some other unique thing)
about the (first) hard-disk on the system?
Thanks for help.
Uni.
| |
| Robert Harris 2004-10-27, 5:52 pm |
| Uni wrote:
> Hi,
>
> I'm trying to generate a (possibly) unique id for a machine. For that,
> I'd like to include the hardware address of the first nic on the
> system. Is there a (if possible portable) way to programmatically (C)
> find this address?
"ifconfig eth0" usually finds it
>
> I searched on this newsgroup for this topic and found references to
> first pinging and then using arp -a, but that would be difficult to do
> from within a C program and would not be portable (as the output
> format of arp would differ on different OSs or systems).
>
> What other things could I possibly include in the unique id. Is there
> a good way to programmatically find an ID (or some other unique thing)
> about the (first) hard-disk on the system?
Well, unique machine IDs aren't normally necessary!
>
> Thanks for help.
> Uni.
| |
| Måns Rullgård 2004-10-27, 5:52 pm |
| Robert Harris <robertdotfdotharris@blueyonder.co.uk> writes:
> Uni wrote:
> "ifconfig eth0" usually finds it
True on Linux systems, false on many others. On Tru64, the network
interfaces are usually named tu0, tu1, etc. Solaris often calls them
hme0, hme1. Furthermore, the output format of ifconfig varies wildly.
--
Måns Rullgård
mru@inprovide.com
| |
|
| "Måns Rullgård" <mru@mru.ath.cx> wrote in message
news:yw1xlldsp5s1.fsf@mru.ath.cx...
> Robert Harris <robertdotfdotharris@blueyonder.co.uk> writes:
>
>
> True on Linux systems, false on many others. On Tru64, the network
> interfaces are usually named tu0, tu1, etc. Solaris often calls them
> hme0, hme1. Furthermore, the output format of ifconfig varies wildly.
>
> --
> Måns Rullgård
> mru@inprovide.com
The hw address of the NICs can be found using an ioctl call (ioctl (sock,
SIOCGIFHWADDR, &st), where st is of type struct ifreq).
I'm not sure how can one go about finding the hard disk id through C code.
Any suggestions anyone?
| |
| Måns Rullgård 2004-10-27, 5:52 pm |
| "A" <ashusharma1980@yahoo.co.uk> writes:
> "Måns Rullgård" <mru@mru.ath.cx> wrote in message
> news:yw1xlldsp5s1.fsf@mru.ath.cx...
>
> The hw address of the NICs can be found using an ioctl call (ioctl (sock,
> SIOCGIFHWADDR, &st), where st is of type struct ifreq).
That's the easy part. The hard part is that the definition of struct
ifreq varies. On Linux, the hw address is in ifreq.ifr_hwaddr, on
Solaris it's called ifrec.ifr_enaddr. Furthermore, the Solaris header
file tells me struct ifrec is obsoleted by struct lifrec.
--
Måns Rullgård
mru@inprovide.com
| |
| Mark Rafn 2004-10-27, 5:52 pm |
| Uni <unilever1900@yahoo.com> wrote:
>I'm trying to generate a (possibly) unique id for a machine. For that,
>I'd like to include the hardware address of the first nic on the
>system.
Sure. Recognize that these can be spoofed, though, both inside the system and
on the network.
>Is there a (if possible portable) way to programmatically (C)
>find this address?
Yes, but it's different for each platform. Parsing the ouput of "ifconfig -a"
is going to get you pretty close, but still won't be terribly portable.
>What other things could I possibly include in the unique id. Is there
>a good way to programmatically find an ID (or some other unique thing)
>about the (first) hard-disk on the system?
Please give a little more background on why you need this.
The best way is to not use a protocol that requires a global static unique ID.
If you need an ID, use one that's guaranteed to be unique-enough (like IP
address is local to that network), or one that's guaranteed to be
stable-enough (like a generated random key, stored in a file).
If you're trying to do this for copy protection purposes, give up on having it
work fully on anything but very closed hardware and OSs. You can probably get
close by testing a combination of things which you don't tell your customers,
and taking the sum of all the things you've tested. Prepare for the support
calls when your product breaks due to upgrades or config changes.
--
Mark Rafn dagon@dagon.net <http://www.dagon.net/>
|
|
|
|
|