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 ]
|