POSIX way to get MAC address of host - Unix

This is a discussion on POSIX way to get MAC address of host - Unix ; 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 ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: POSIX way to get MAC address of host

  1. POSIX way to get MAC address of host




    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'

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



  2. Re: POSIX way to get MAC address of host

    Michael Hopkins 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...

  3. Re: POSIX way to get MAC address of host

    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 research.com> wrote:
    > 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.



+ Reply to Thread