On 6/18/14 21:07 , Alain O'Dea via smartos-discuss wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> When I run some C code to get the MAC address of a VNIC
> sockaddr_ll->sll_addr is all zeroes.
>
> Here is the code in question with the particular line highlighted:
> https://github.com/AlainODea-haskell/network-info/blob/NetworkUnixIllumosHurd/cbits/network-unix.c#L36
>
> Is that a bad way to get the MAC address of a VNIC?
>
> The other aspects of that code seem to have no trouble getting the
> IPv4 and IPv6 addresses, but the MAC address is being elusive.
>
> This is part of the network-info Haskell library which is a dependency
> of git-annex which I am trying to make usable on SmartOS.
So, it looks like our implementation of getifaddrs() does not return
anything about AF_PACKET by default. I wrote a simple little C program
and ran it in my zone, and it only fired for IPv4/IPv6 addresses.
Instead, it appears that what's happened is that because you memset the
mac address, that's why we got all zeros.
As for a better way to do this, I'm not 100% sure off hand, but I'll try
and get an answer for you.
Here's that C program for reference, when building don't forget to link
-lnsl and -lsocket:
/*
* Test getifaddrs behavior.
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <ifaddrs.h>
#include <stdio.h>
int
main(int argc, const char *argv[])
{
struct ifaddrs *ifa, *oif;
if (getifaddrs(&ifa) != 0) {
perror("getifaddrs");
return (1);
}
oif = ifa;
while (ifa != NULL) {
printf("%s: [%d]\n", ifa->ifa_name,
ifa->ifa_addr->sa_family);
ifa = ifa->ifa_next;
}
freeifaddrs(oif);
return (0);
}
Robert
-------------------------------------------
smartos-discuss
Archives: https://www.listbox.com/member/archive/184463/=now
RSS Feed: https://www.listbox.com/member/archive/rss/184463/25769125-55cfbc00
Modify Your Subscription:
https://www.listbox.com/member/?member_id=25769125&id_secret=25769125-7688e9fb
Powered by Listbox: http://www.listbox.com