Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
macaddress
int get_mac_address(char *ifaddr_name) { char buf[1024]; int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP); int success = 0; struct ifreq ifr; struct ifconf ifc; if (sock == -1) { /* TODO Handle Error! */ } ifc.ifc_len = sizeof(buf); ifc.ifc_buf = buf; if (ioctl(sock, SIOCGIFCONF, &ifc) == -1) { /* TODO Handle Error! */ } struct ifreq* it = ifc.ifc_req; const struct ifreq* const end = it + (ifc.ifc_len / sizeof(struct ifreq)); for (; it != end; ++it) { strcpy(ifr.ifr_name, it->ifr_name); /* * Was done this way to reduce nesting. */ if (ioctl(sock, SIOCGIFFLAGS, &ifr) != 0) { /* TODO Handle Error! */ continue; } if ((ifr.ifr_flags & IFF_LOOPBACK)) { /* TODO Handle Error! */ continue; } if (ioctl(sock, SIOCGIFHWADDR, &ifr) != 0) { /* TODO Handle Error! */ continue; } success = 1; break; } unsigned char mac_address[6]; if (success) { memcpy(mac_address, ifr.ifr_hwaddr.sa_data, 6); } printf("%s\n", mac_address); int i; for (i = 0; i < 6; i++) { if (i > 0) { printf(":"); } printf("%02X", buf[i]); } return 0; }
run
|
edit
|
history
|
help
0
2.1.2 Sum of all the elements in a one dimensional array A using reduction.
Swiss Infotech Tutorial
a1
problem4 review fundamentos
Nice1
recurtion
Assignment 7
AVANCE PREGUNTA 10 DE CADENAS
FILE_Access
888 BONUS LAB 1