Hi, I'm new here, I need some little help here, I have this code and I need get the MAC ADDRESS too, I tried few ways, but I dont had lucky.
Code:
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/if.h>
int main()
{
struct ifconf conf;
struct sockaddr_in *s_in;
int sock, i, count;
// Abrir um socket nulo
if ((sock = socket(PF_INET, SOCK_DGRAM, 0)) == -1)
{
perror("erro ao abrir o socket.");
return -1;
}
// Pega lista de interfaces de rede, so os 10 primeiros.
memset(&conf, 0, sizeof(conf));
conf.ifc_len = sizeof(struct ifreq) * 10;
conf.ifc_buf = (char*) malloc(conf.ifc_len);
if (ioctl(sock, SIOCGIFCONF, &conf) == -1)
{
perror("falha ao pegar a lista de interfaces de rede");
return -1;
}
count = conf.ifc_len / sizeof(struct ifreq);
for (i = 0; i < count; i++)
{
s_in = (struct sockaddr_in*) &conf.ifc_req[i].ifr_addr;
printf("%s %s\n", conf.ifc_req[i].ifr_name,
inet_ntoa(s_in->sin_addr));
}
free(conf.ifc_buf);
return 0;
}
thanks in advance.