Commit 61968e31 authored by neverlord's avatar neverlord

linux compatibility

parent fb0140b7
#include "cppa/config.hpp"
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <sstream> #include <sstream>
...@@ -19,6 +21,26 @@ void erase_trailing_newline(std::string& str) ...@@ -19,6 +21,26 @@ void erase_trailing_newline(std::string& str)
} }
} }
#ifdef CPPA_MACOS
const char* s_get_uuid =
"/usr/sbin/diskutil info / | "
"/usr/bin/awk '$0 ~ /UUID/ { print $3 }'";
const char* s_get_mac =
"/usr/sbin/system_profiler SPNetworkDataType | "
"/usr/bin/grep -Fw MAC | "
"/usr/bin/grep -o '[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}' | "
"/usr/bin/head -n1";
#elif CPPA_LINUX
const char* s_get_uuid =
"/bin/egrep -o 'UUID=(([0-9a-fA-F-]+)(-[0-9a-fA-F-]+){3})\s+/\s+' "
"/etc/fstab | "
"/bin/egrep -o '([0-9a-fA-F-]+)(-[0-9a-fA-F-]+){3}'";
const char* s_get_mac =
"/sbin/ifconfig | "
"/bin/egrep -o '[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}' | "
"head -n1";
#endif
cppa::process_information compute_proc_info() cppa::process_information compute_proc_info()
{ {
cppa::process_information result; cppa::process_information result;
...@@ -26,9 +48,7 @@ cppa::process_information compute_proc_info() ...@@ -26,9 +48,7 @@ cppa::process_information compute_proc_info()
char cbuf[100]; char cbuf[100];
// fetch hd serial // fetch hd serial
std::string hd_serial; std::string hd_serial;
FILE* cmd = popen("/usr/sbin/diskutil info / | " FILE* cmd = popen(s_get_uuid, "r");
"/usr/bin/awk '$0 ~ /UUID/ { print $3 }'",
"r");
while (fgets(cbuf, 100, cmd) != 0) while (fgets(cbuf, 100, cmd) != 0)
{ {
hd_serial += cbuf; hd_serial += cbuf;
...@@ -37,11 +57,7 @@ cppa::process_information compute_proc_info() ...@@ -37,11 +57,7 @@ cppa::process_information compute_proc_info()
erase_trailing_newline(hd_serial); erase_trailing_newline(hd_serial);
// fetch mac address of first network device // fetch mac address of first network device
std::string first_mac_addr; std::string first_mac_addr;
cmd = popen("/usr/sbin/system_profiler SPNetworkDataType | " cmd = popen(s_get_mac, "r");
"/usr/bin/grep -Fw MAC | "
"/usr/bin/grep -o \"..:..:..:..:..:..\" | "
"/usr/bin/head -n1",
"r");
while (fgets(cbuf, 100, cmd) != 0) while (fgets(cbuf, 100, cmd) != 0)
{ {
first_mac_addr += cbuf; first_mac_addr += cbuf;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment