|
70 | 70 | #include <sys/sockio.h> |
71 | 71 | #endif |
72 | 72 |
|
| 73 | +#if defined(OS_APPLE) |
| 74 | +#include <arpa/inet.h> |
| 75 | +#include <ifaddrs.h> |
| 76 | +#include <net/if.h> |
| 77 | +#include <net/if_dl.h> |
| 78 | +#include <netdb.h> |
| 79 | +#include <netinet/in.h> |
| 80 | +#include <sys/socket.h> |
| 81 | +#endif |
| 82 | + |
73 | 83 | #include "item.h" |
74 | 84 | #include "helpers.h" |
75 | 85 | #include "xccdf_impl.h" |
@@ -468,6 +478,58 @@ void xccdf_result_fill_sysinfo(struct xccdf_result *result) |
468 | 478 | out1: |
469 | 479 | freeifaddrs(ifaddr); |
470 | 480 | } |
| 481 | +#elif defined(OS_APPLE) |
| 482 | + if (!probe_root) { |
| 483 | + struct ifaddrs *ifaddr, *ifa; |
| 484 | + if (getifaddrs(&ifaddr) == -1) |
| 485 | + return; |
| 486 | + for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { |
| 487 | + int family; |
| 488 | + char hostip[NI_MAXHOST]; |
| 489 | + |
| 490 | + if (!ifa->ifa_addr) |
| 491 | + continue; |
| 492 | + family = ifa->ifa_addr->sa_family; |
| 493 | + |
| 494 | + if (family == AF_INET || family == AF_INET6) { |
| 495 | + if (family == AF_INET) { |
| 496 | + if (getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), |
| 497 | + hostip, sizeof(hostip), NULL, 0, NI_NUMERICHOST)) |
| 498 | + continue; |
| 499 | + } else { |
| 500 | + struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)ifa->ifa_addr; |
| 501 | + if (!inet_ntop(family, &sin6->sin6_addr, hostip, sizeof(hostip))) |
| 502 | + continue; |
| 503 | + } |
| 504 | + xccdf_result_add_target_address(result, hostip); |
| 505 | + fact = xccdf_target_fact_new(); |
| 506 | + xccdf_target_fact_set_name(fact, family == AF_INET ? |
| 507 | + "urn:xccdf:fact:asset:identifier:ipv4" : |
| 508 | + "urn:xccdf:fact:asset:identifier:ipv6"); |
| 509 | + xccdf_target_fact_set_string(fact, hostip); |
| 510 | + _xccdf_result_add_target_fact_uniq(result, fact); |
| 511 | + } else if (family == AF_LINK) { |
| 512 | + /* macOS exposes MAC addresses as AF_LINK entries in getifaddrs */ |
| 513 | + struct sockaddr_dl *sdl = (struct sockaddr_dl *)ifa->ifa_addr; |
| 514 | + if (sdl->sdl_alen == 6) { |
| 515 | + unsigned char *mac = (unsigned char *)LLADDR(sdl); |
| 516 | + char macbuf[20]; |
| 517 | + snprintf(macbuf, sizeof(macbuf), |
| 518 | + "%02X:%02X:%02X:%02X:%02X:%02X", |
| 519 | + mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); |
| 520 | + fact = xccdf_target_fact_new(); |
| 521 | + xccdf_target_fact_set_name(fact, "urn:xccdf:fact:ethernet:MAC"); |
| 522 | + xccdf_target_fact_set_string(fact, macbuf); |
| 523 | + _xccdf_result_add_target_fact_uniq(result, fact); |
| 524 | + fact = xccdf_target_fact_new(); |
| 525 | + xccdf_target_fact_set_name(fact, "urn:xccdf:fact:asset:identifier:mac"); |
| 526 | + xccdf_target_fact_set_string(fact, macbuf); |
| 527 | + _xccdf_result_add_target_fact_uniq(result, fact); |
| 528 | + } |
| 529 | + } |
| 530 | + } |
| 531 | + freeifaddrs(ifaddr); |
| 532 | + } |
471 | 533 | #elif defined(OS_WINDOWS) |
472 | 534 |
|
473 | 535 | #define VERSION_LEN 32 |
|
0 commit comments