POSIX way to get MAC address of host
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > POSIX way to get MAC address of host




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    POSIX way to get MAC address of host  
Michael Hopkins


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-22-07 12:20 AM




Hi all

Trying to find out if there is a POSIX-compliant way to get the MAC address
of a host machine.  Want it to work the same way on Mac/*nix/Windows hence
the POSIX requirement, however if there is another way that doesn't require
too much alteration between platforms then that is of interest also.

Have so far looked at getaddrinfo() and ioctl() but the documentation for
both is a little scary and I'm not sure enough that they are the correct
direction to dig further at the moment.

Any thoughts appreciated & please feel free to CC me

Thx

Michael


_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

_/    _/   _/_/_/             Hopkins Research Ltd
_/    _/   _/    _/
_/_/_/_/   _/_/_/          http://www.hopkins-research.com/
_/    _/   _/   _/
_/    _/   _/     _/               'touch the future'

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/







[ Post a follow-up to this message ]



    Re: POSIX way to get MAC address of host  
Rick Jones


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-22-07 12:20 AM

Michael Hopkins <michael.hopkins@hopkins-research.com> wrote:
> Trying to find out if there is a POSIX-compliant way to get the MAC
> address of a host machine.  Want it to work the same way on
> Mac/*nix/Windows hence the POSIX requirement, however if there is
> another way that doesn't require too much alteration between
> platforms then that is of interest also.

There is none.  POSIX does not deign to dabble in such proletarian
matters...  And if you think that POSIX makes your life better under
Windows I would be quite happy to sell you either a bridge, or some
water-front property.

> Have so far looked at getaddrinfo() and ioctl() but the
> documentation for both is a little scary and I'm not sure enough
> that they are the correct direction to dig further at the moment.

The getaddrinfo() call is only for mapping names to ip
addresses/services, it neither knows, nor is ever likely to know
anything about MAC addresses.

Now, we have to ask - "Who's MAC address do you want?"

If you want the MAC address of an interface or interfaces on the
system on which this code is running, then some variation on the ioctl
theme will be in order, or if the system supports DLPI, you could use
DLPI methods (There is a DLPI manual for HP-UX on docs.hp.com
someplace).  If not DLPI then it will be platform-specific as to what
you do, and I'll bet euros to berliners that on Windows it ain't an
ioctl().

If you want the MAC address of _another_ system then we are talking
about poking around the ARP cache (typically ioctls under *nix) on the
system on which this application is running, or this application
sending ARP requests and looking for the ARP replies.

However, just as with the famous Ginsu knife commercial, this method
will not always work with a tomato - if the other system is on the far
side of a router, there will either be no entry in the local system's
ARP cache, or if there is an entry, it will have the MAC address of
the router.

For that situation, you need some sort of network management call -
say a query of a suitable MIB on the remote system via SNMP.

rick jones
--
Process shall set you free from the need for rational thought.
these opinions are mine, all mine; HP might not want them anyway... 
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...





[ Post a follow-up to this message ]



    Re: POSIX way to get MAC address of host  
Maxim Yegorushkin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-22-07 12:30 PM

Please bear in mind there may be several network adapters on the host.

One way to get all local MAC addresses is to write a wrapper script
over ifconfig (Linux, Solaris) and ipconfig (windoze).

On 21 Mar, 23:29, Michael Hopkins <michael.hopk...@hopkins-
research.com> wrote:
> Hi all
>
> Trying to find out if there is a POSIX-compliant way to get the MAC addres
s
> of a host machine.  Want it to work the same way on Mac/*nix/Windows hence
> the POSIX requirement, however if there is another way that doesn't requir
e
> too much alteration between platforms then that is of interest also.
>
> Have so far looked at getaddrinfo() and ioctl() but the documentation for
> both is a little scary and I'm not sure enough that they are the correct
> direction to dig further at the moment.






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 07:43 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register