code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| #include "protocol.h"
int get_mac_addr(char *arg, char *mac) { int sock; struct ifreq ifr; uint8_t mac_addr[6] = {0,};
if((sock = socket(PF_INET,SOCK_STREAM, 0)) < 0) { perror("socket "); return -1; }
strcpy(ifr.ifr_name, arg); if(ioctl(sock, SIOCGIFHWADDR, &ifr) < 0) { perror("ioctl() - get mac"); close(sock); return -1; }
memcpy(mac, ifr.ifr_hwaddr.sa_data, 6);
close(sock); return 0; }
|
Author:
Slay
Permalink:
http://sean-baek.github.io/2022/08/21/2022-08-21-get-mac-addr-function/
License:
Copyright (c) 2021 CC-BY-NC-4.0 LICENSE
Slogan:
Do you believe in DESTINY?