Skip to content

Commit

Permalink
More work for #17
Browse files Browse the repository at this point in the history
  • Loading branch information
npyl committed Jul 30, 2018
1 parent aa69475 commit 082076a
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmake/ConkyPlatformChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
Expand Down
71 changes: 71 additions & 0 deletions src/darwin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
#include <IntelPowerGadget/EnergyLib.h>
#endif

#ifdef BUILD_WLAN
#include <CoreFoundation/CoreFoundation.h>
#include <dlfcn.h>
#endif

/* clock_gettime includes */
#ifndef HAVE_CLOCK_GETTIME
#include <errno.h>
Expand Down Expand Up @@ -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<int (*)(void *)>(dlsym(libHandle, "Apple80211Open"));
apple80211Bind = reinterpret_cast<int (*)(void *, CFStringRef)>(dlsym(libHandle, "Apple80211BindToInterface"));
apple80211Close = reinterpret_cast<int (*)(void *)>(dlsym(libHandle, "Apple80211Close"));
apple80211GetInfoCopy = reinterpret_cast<int (*)(void *, CFDictionaryRef *)>(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;
Expand All @@ -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;
Expand Down

0 comments on commit 082076a

Please sign in to comment.