在iOS中确定URL中的IP地址 [英] Determining IP Address from URL in iOS

查看:391
本文介绍了在iOS中确定URL中的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从iOS应用中的URL获取CDN的IP地址。从长堆栈搜索中,我已经确定了使用以下方法执行此操作的方法:

I need to get the IP address of a CDN from it's URL in an iOS app. From a long stack search, i've determined a method for doing this with the following:

struct hostent *host_entry = gethostbyname("stackoverflow.com");
char *buff;
buff = inet_ntoa(*((struct in_addr *)host_entry->h_addr_list[0]));
// buff is now equal to the IP of the stackoverflow.com server

但是,使用此代码片段时,我的应用程序无法编译并显示此警告:取消引用指向不完整类型的指针

However, when using this code snippet, my app fails to compile and presents this warning: "dereferencing pointer to incomplete type"

我不了解结构,我不知道如何解决这个问题。有什么建议吗?

I have no knowledge of structs and I do not know how to fix this. Any suggestions?

我也尝试过:

#include <ifaddrs.h>
#include <arpa/inet.h>

但结果是相同的警告。

推荐答案

使用以下内容编译代码时没有问题:

I had no problems compiling that code with the following includes:

#import <netdb.h>
#include <arpa/inet.h>

这篇关于在iOS中确定URL中的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆