Re: MAC address for Ethernet interface
On 12 Dec 2003 08:31:32 -0000
"anil garrepally" <anilgarrepally@xxxxxxxxxxxxxx> wrote:
> Hi,
>
> Is there any system call available for getting the MAC address of
> ethernet interface. I need it in my program.
>
> Anil.
Sure,
You can make a "SIOCGIFHWADDR" ioctl call on an open socket.
Here's a small example _without_ proper error checking:
#include <sys/socket.h>
#include <linux/sockios.h>
#include <linux/if.h>
main()
{
int sd, i;
struct ifreq buff;
sd = socket(PF_INET,SOCK_DGRAM,0);
strncpy(buff.ifr_name, "eth0", IFNAMSIZ);
ioctl(sd,SIOCGIFHWADDR,&buff);
for (i=0; i < 6; i++)
printf("%02X:", (unsigned char)buff.ifr_hwaddr.sa_data[i]);
printf("\n");
}
Regards,
Sean
_______________________________________________
Redhat-devel-list mailing list
Redhat-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/redhat-devel-list
[Kernel Newbies]
[Red Hat General]
[Fedora]
[Red Hat Install]
[Linux Kernel Development]
[Yosemite News]