0

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

Cuong Nguyen
  • 980
  • 2
  • 9
  • 29

2 Answers2

0
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>
skytoup
  • 126
  • 1
  • 2
-1

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.

fsaint
  • 8,759
  • 3
  • 36
  • 48
Cuong Nguyen
  • 980
  • 2
  • 9
  • 29