mirror of https://github.com/axmolengine/axmol.git
48 lines
1.2 KiB
Plaintext
48 lines
1.2 KiB
Plaintext
|
|
||
|
#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 "";
|
||
|
}
|