diff --git a/cmake/ConkyPlatformChecks.cmake b/cmake/ConkyPlatformChecks.cmake index 7c6415714c..958d0dcc2e 100644 --- a/cmake/ConkyPlatformChecks.cmake +++ b/cmake/ConkyPlatformChecks.cmake @@ -146,6 +146,11 @@ if(OS_DARWIN AND BUILD_IPGFREQ) set(conky_libs ${conky_libs} ${IPG}) endif(OS_DARWIN AND BUILD_IPGFREQ) +if(BUILD_WLAN AND OS_DARWIN) + find_library(CF CoreFoundation) + set(conky_libs ${conky_libs} ${CF}) +endif(BUILD_WLAN AND OS_DARWIN) + if(BUILD_ICAL) check_include_files(libical/ical.h ICAL_H_) if(NOT ICAL_H_) diff --git a/src/darwin.cc b/src/darwin.cc index d664986092..8a9c39762b 100644 --- a/src/darwin.cc +++ b/src/darwin.cc @@ -72,6 +72,11 @@ #include #endif +#ifdef BUILD_WLAN +#include +#include +#endif + /* clock_gettime includes */ #ifndef HAVE_CLOCK_GETTIME #include @@ -636,6 +641,69 @@ int update_meminfo() { return 0; } +void update_wifi_stats_for_interface(struct net_stat *ns) +{ + void *libHandle = nullptr; + void *airportHandle = nullptr; + + int (*apple80211Open)(void *) = nullptr; + int (*apple80211Bind)(void *, CFStringRef) = nullptr; + int (*apple80211Close)(void *) = nullptr; + int (*apple80211GetInfoCopy)(void *, CFDictionaryRef *) = nullptr; + + CFDictionaryRef info = nullptr; + + static bool initialise = false; + + if (!initialise) { + libHandle = dlopen("/System/Library/PrivateFrameworks/Apple80211.framework/Apple80211", RTLD_LAZY); + + char *dlerror_error; + + if (libHandle == nullptr && (dlerror_error = dlerror()) != nullptr) { + printf("%s", dlerror_error); + } + + /* + * Set the functions + */ + apple80211Open = reinterpret_cast(dlsym(libHandle, "Apple80211Open")); + apple80211Bind = reinterpret_cast(dlsym(libHandle, "Apple80211BindToInterface")); + apple80211Close = reinterpret_cast(dlsym(libHandle, "Apple80211Close")); + apple80211GetInfoCopy = reinterpret_cast(dlsym(libHandle, "Apple80211GetInfoCopy")); + + if (!apple80211Open || !apple80211Bind || !apple80211Close || !apple80211GetInfoCopy) + { + printf("%s", dlerror()); + return; + } + + initialise = true; + } + + /* + * Get the handle + */ + apple80211Open(&airportHandle); + + /* + * Get wireless data + */ + apple80211Bind(airportHandle, CFStringCreateWithCString(CFAllocatorGetDefault(), ns->dev, kCFStringEncodingUTF8)); + + apple80211GetInfoCopy(airportHandle, &info); + + /* + * Update + */ + memcpy(&(ns->essid), CFDictionaryGetValue(info, "SSID"), sizeof(char)*4); + + /* + * Close + */ + apple80211Close(airportHandle); +} + int update_net_stats() { struct net_stat *ns; double delta; @@ -655,6 +723,9 @@ int update_net_stats() { if ((ifa->ifa_flags & IFF_UP) != 0u) { struct ifaddrs *iftmp; + // XXX if interface is WLAN do: + update_wifi_stats_for_interface(ns); + ns->up = 1; last_recv = ns->recv; last_trans = ns->trans;