Author: tom
Date: Mon Nov 17 12:16:33 2008
New Revision: 3390
URL: http://svn.slimdevices.com?rev=3390&root=Jive&view=rev
Log:
Bug: 9820
Description:
- Eliminate ipconfig and ifconfig system call (mac address now comes from C) -
only for desktop - controller still calling ifconfig for now
Modified:
7.3/trunk/squeezeplay/src/squeezeplay/VisualC/jive.vcproj
7.3/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua
7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive.h
7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework.c
7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework_linux.c
7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework_osx.c
7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework_windows.c
7.3/trunk/squeezeplay/src/squeezeplay_desktop/share/applets/DesktopJive/DesktopJiveMeta.lua
Modified: 7.3/trunk/squeezeplay/src/squeezeplay/VisualC/jive.vcproj
URL:
http://svn.slimdevices.com/7.3/trunk/squeezeplay/src/squeezeplay/VisualC/jive.vcproj?rev=3390&root=Jive&r1=3389&r2=3390&view=diff
==============================================================================
--- 7.3/trunk/squeezeplay/src/squeezeplay/VisualC/jive.vcproj (original)
+++ 7.3/trunk/squeezeplay/src/squeezeplay/VisualC/jive.vcproj Mon Nov 17
12:16:33 2008
@@ -63,7 +63,7 @@
/>
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="ws2_32.lib"
+ AdditionalDependencies="ws2_32.lib Iphlpapi.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="C:\WMSDK\WMFSDK11\lib"
GenerateDebugInformation="true"
Modified: 7.3/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua
URL:
http://svn.slimdevices.com/7.3/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua?rev=3390&root=Jive&r1=3389&r2=3390&view=diff
==============================================================================
--- 7.3/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua (original)
+++ 7.3/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua Mon Nov
17 12:16:33 2008
@@ -136,6 +136,10 @@
=head2 jive.ui.Framework:getTicks()
Return the number of milliseconds since the Jive initialization.
+
+=head2 jive.ui.Framework:getMacAddress()
+
+Return the first Mac address found on the current system.
=head2 jive.ui.Framework:getUserPath()
Modified: 7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive.h
URL:
http://svn.slimdevices.com/7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive.h?rev=3390&root=Jive&r1=3389&r2=3390&view=diff
==============================================================================
--- 7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive.h (original)
+++ 7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive.h Mon Nov 17 12:16:33 2008
@@ -261,6 +261,7 @@
extern int (*jive_sdlfilter_pump)(const SDL_Event *event);
extern void (*get_app_home_dir_platform)(char *path);
+extern void (*get_mac_address)(char *address);
void get_user_path(char *path);
void get_app_home_dir(char *path);
void jive_platform_init(lua_State *L);
Modified: 7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework.c
URL:
http://svn.slimdevices.com/7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework.c?rev=3390&root=Jive&r1=3389&r2=3390&view=diff
==============================================================================
--- 7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework.c (original)
+++ 7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework.c Mon Nov 17
12:16:33 2008
@@ -15,6 +15,7 @@
int (*jive_sdlevent_pump)(lua_State *L);
int (*jive_sdlfilter_pump)(const SDL_Event *event);
void (*get_app_home_dir_platform)(char *path);
+void (*get_mac_address)(char *address);
char *jive_resource_path = NULL;
@@ -848,6 +849,18 @@
int jiveL_get_ticks(lua_State *L) {
lua_pushinteger(L, SDL_GetTicks());
+ return 1;
+}
+
+int jiveL_get_mac_address(lua_State *L) {
+
+ char *macaddress = malloc(100);
+
+ get_mac_address(macaddress);
+
+ lua_pushstring(L, macaddress);
+ free(macaddress);
+
return 1;
}
@@ -1471,6 +1484,7 @@
{ "perfwarn", jiveL_perfwarn },
{ "_event", jiveL_event },
{ "getUserPath", jiveL_get_user_path },
+ { "getMacAddress", jiveL_get_mac_address },
{ NULL, NULL }
};
Modified: 7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework_linux.c
URL:
http://svn.slimdevices.com/7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework_linux.c?rev=3390&root=Jive&r1=3389&r2=3390&view=diff
==============================================================================
--- 7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework_linux.c
(original)
+++ 7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework_linux.c Mon Nov
17 12:16:33 2008
@@ -7,17 +7,59 @@
#include "common.h"
#include "jive.h"
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <linux/if.h>
static void linux_get_app_home_dir(char *path);
+void linux_get_mac_address(char *address);
static void linux_get_app_home_dir(char *path) {
const char *home = getenv("HOME");
strcpy(path, home);
strcat(path, "/.squeezeplay");
}
+void linux_get_mac_address(char *address) {
+ struct ifreq ifr;
+ struct ifreq *IFR;
+ struct ifconf ifc;
+ char buf[1024];
+ int s, i;
+
+ s = socket(AF_INET, SOCK_DGRAM, 0);
+ if (s==-1) {
+ return ;
+ }
+
+ ifc.ifc_len = sizeof(buf);
+ ifc.ifc_buf = buf;
+ ioctl(s, SIOCGIFCONF, &ifc);
+
+ IFR = ifc.ifc_req;
+ for (i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; IFR++) {
+
+ strcpy(ifr.ifr_name, IFR->ifr_name);
+ if (ioctl(s, SIOCGIFFLAGS, &ifr) == 0) {
+ if (! (ifr.ifr_flags & IFF_LOOPBACK)) {
+ if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0) {
+ //take the first found address.
+ //todo: can we be smarter about which is the correct
address
+ unsigned char * ptr = (unsigned char *)
ifr.ifr_hwaddr.sa_data;
+ sprintf(address, "%02x:%02x:%02x:%02x:%02x:%02x",
*ptr,*(ptr+1), *(ptr+2),*(ptr+3), *(ptr+4), *(ptr+5));
+ break;
+ }
+ }
+ }
+ }
+
+ close(s);
+}
void jive_platform_init(lua_State *L) {
get_app_home_dir_platform = linux_get_app_home_dir;
+ get_mac_address = linux_get_mac_address;
}
#endif
Modified: 7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework_osx.c
URL:
http://svn.slimdevices.com/7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework_osx.c?rev=3390&root=Jive&r1=3389&r2=3390&view=diff
==============================================================================
--- 7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework_osx.c (original)
+++ 7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework_osx.c Mon Nov
17 12:16:33 2008
@@ -8,8 +8,14 @@
#include "common.h"
#include "jive.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <net/if_dl.h>
+#include <ifaddrs.h>
+#include <net/if_types.h>
static void osx_get_app_home_dir(char *path);
+void osx_get_mac_address(char *address);
static void osx_get_app_home_dir(char *path) {
const char *home = getenv("HOME");
@@ -17,8 +23,33 @@
strcat(path, "/Library/Preferences/SqueezePlay");
}
+void osx_get_mac_address(char *address) {
+ struct ifaddrs* ifaphead;
+ struct ifaddrs* ifap;
+ if ( getifaddrs( &ifaphead ) != 0 )
+ return;
+
+ // iterate over the net interfaces
+ for ( ifap = ifaphead; ifap; ifap = ifap->ifa_next )
+ {
+ struct sockaddr_dl* sdl = (struct sockaddr_dl*)ifap->ifa_addr;
+ if ( sdl && ( sdl->sdl_family == AF_LINK ) && ( sdl->sdl_type ==
IFT_ETHER ))
+ {
+ //take the first found address.
+ //todo: can we be smarter about which is the correct address
+ unsigned char * ptr = (unsigned char *)LLADDR(sdl);
+ sprintf(address, "%02x:%02x:%02x:%02x:%02x:%02x", *ptr,*(ptr+1),
*(ptr+2),*(ptr+3), *(ptr+4), *(ptr+5));
+ break;
+ }
+ }
+
+ freeifaddrs( ifaphead );
+}
+
+
void jive_platform_init(lua_State *L) {
get_app_home_dir_platform = osx_get_app_home_dir;
+ get_mac_address = osx_get_mac_address;
}
#endif
Modified: 7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework_windows.c
URL:
http://svn.slimdevices.com/7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework_windows.c?rev=3390&root=Jive&r1=3389&r2=3390&view=diff
==============================================================================
--- 7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework_windows.c
(original)
+++ 7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework_windows.c Mon
Nov 17 12:16:33 2008
@@ -15,11 +15,33 @@
#endif
static int windows_filter_pump(const SDL_Event *event);
static void windows_get_app_home_dir(char *path);
+void windows_get_mac_address(char *address);
static void windows_get_app_home_dir(char *path) {
const char *home = getenv("APPDATA");
strcpy(path, home);
strcat(path, "/SqueezePlay");
+}
+
+void windows_get_mac_address(char *address) {
+ PIP_ADAPTER_INFO pAdapterInfo;
+ IP_ADAPTER_INFO AdapterInfo[32];
+ DWORD dwBufLen = sizeof( AdapterInfo );
+
+ DWORD dwStatus = GetAdaptersInfo( AdapterInfo, &dwBufLen );
+ if ( dwStatus != ERROR_SUCCESS )
+ return; // no adapters.
+
+ pAdapterInfo = AdapterInfo;
+ while ( pAdapterInfo )
+ {
+ //take the first found address.
+ //todo: can we be smarter about which is the correct address
+ unsigned char * ptr = (unsigned char *) pAdapterInfo->Address;
+ sprintf(address, "%02x:%02x:%02x:%02x:%02x:%02x", *ptr,*(ptr+1),
*(ptr+2),*(ptr+3), *(ptr+4), *(ptr+5));
+ break;
+ //pAdapterInfo = pAdapterInfo->Next;
+ }
}
static int windows_filter_pump(const SDL_Event *event) {
@@ -59,4 +81,5 @@
void jive_platform_init(lua_State *L) {
jive_sdlfilter_pump = windows_filter_pump;
get_app_home_dir_platform = windows_get_app_home_dir;
+ get_mac_address = windows_get_mac_address;
}
Modified:
7.3/trunk/squeezeplay/src/squeezeplay_desktop/share/applets/DesktopJive/DesktopJiveMeta.lua
URL:
http://svn.slimdevices.com/7.3/trunk/squeezeplay/src/squeezeplay_desktop/share/applets/DesktopJive/DesktopJiveMeta.lua?rev=3390&root=Jive&r1=3389&r2=3390&view=diff
==============================================================================
---
7.3/trunk/squeezeplay/src/squeezeplay_desktop/share/applets/DesktopJive/DesktopJiveMeta.lua
(original)
+++
7.3/trunk/squeezeplay/src/squeezeplay_desktop/share/applets/DesktopJive/DesktopJiveMeta.lua
Mon Nov 17 12:16:33 2008
@@ -6,6 +6,7 @@
local table = require("jive.utils.table")
local AppletMeta = require("jive.AppletMeta")
+local Framework = require("jive.ui.Framework")
local appletManager = appletManager
local jiveMain = jiveMain
@@ -47,29 +48,11 @@
end
if not settings.mac then
- local f = io.popen("ifconfig")
- if f then
- local ifconfig = f:read("*a")
- f:close()
-
+ local mac = Framework:getMacAddress()
+ if mac then
store = true
- settings.mac = string.match(ifconfig,
"HWaddr%s([%x:]+)")
- end
- end
-
- if not settings.mac then
- local f = io.popen("ipconfig /all")
- if f then
- local ipconfig = f:read("*a")
- f:close()
-
- store = true
- local mac = string.match(ipconfig, "Physical Address[
%.%-]-:%s([%x%-]+)")
-
- if mac then
- settings.mac = string.gsub(mac, "%-", ":")
- end
- end
+ settings.mac = mac
+ end
end
if not settings.mac then
@@ -84,6 +67,8 @@
end
if store then
+ log:debug("UUID: ", settings.uuid)
+ log:debug("Mac Address: ", settings.mac)
meta:storeSettings()
end
_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins