STUN-iOS project can not show public IP

450 views Asked by At

Now I have a problem with STUN protocol on iOS. I downloaded the project on Github https://github.com/soulfly/STUN-iOS However, when I running the project. It has just show log

2015-06-19 15:55:08.245 STUN[4669:607] STUN server: stunserver.org 2015-06-19 15:55:08.247 STUN[4669:607] STUN Binding Request=<00010000 2112a442 ab8b1ef9 7347bf10 e98c817b> 2015-06-19 15:55:08.275 STUN[4669:607] STUN didSendDataWithTag=1002

I can not show public IP that I need.

Please give me the advice to solve the problem. Many thanks

2

There are 2 answers

0
Cuong Nguyen On BEST ANSWER

I found the reason why "STUN-iOS project" can not show public IP when we are running.

Reason: The server stunsever.org does not work.

Solution: In the file STUNClient.h you just change code #define STUNServer @"stunserver.org" to #define STUNServer @"stun.services.mozilla.com". It works fine.

2
skytoup On
NSString *hostN = @"stunserver.org";
struct hostent* phot;
phot = gethostbyname(hostN.UTF8String);
if(phot) {
    struct in_addr ip_addr;
    memcpy(&ip_addr, phot->h_addr_list[0], 4);
    char *ip = (char*)malloc(sizeof(char)*20);
    inet_ntop(AF_INET, &ip_addr, ip, 20);
    NSString *ipStr = [NSString stringWithUTF8String:ip];
    free(ip);
    NSLog(@"ip:%@", ipStr);
}

and include some head file

#include <netdb.h>
#include <sys/socket.h>
#include <arpa/inet.h>