axmol/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/Runtime_ios-mac.mm

48 lines
1.2 KiB
Plaintext
Raw Normal View History

2014-03-10 19:33:57 +08:00
#include <ifaddrs.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <string>
#include <vector>
using namespace std;
string getProjSearchPath()
{
NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
if (bundlePath != nil) {
return [bundlePath UTF8String];
}
return "";
}
vector<string> getSearchPath()
{
vector<string> searchPathArray;
return searchPathArray;
}
string getIPAddress()
{
BOOL success;
struct ifaddrs * addrs;
const struct ifaddrs * cursor;
success = getifaddrs(&addrs) == 0;
if (success) {
cursor = addrs;
while (cursor != NULL) {
// the second test keeps from picking up the loopback address
if (cursor->ifa_addr->sa_family == AF_INET && (cursor->ifa_flags & IFF_LOOPBACK) == 0)
{
NSString *name = [NSString stringWithUTF8String:cursor->ifa_name];
if ([name isEqualToString:@"en0"]) // Wi-Fi adapter
return [[NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)cursor->ifa_addr)->sin_addr)]UTF8String];
}
cursor = cursor->ifa_next;
}
freeifaddrs(addrs);
}
return "";
}