IP地址的可达性不起作用. [英] Reachability with IP address won't work.

查看:81
本文介绍了IP地址的可达性不起作用.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在输入Apple提供的Rechability类之后. 同样在输入此内容之后,可到达性reachabilityWithAddress:(const struct sockaddr_in *)hostAddress.我们应该如何在该行中输入要检查的IP地址? 这是我真正迷失的部分.

After inputting the Rechability classes Apple provided. Also after inputting this, Reachability reachabilityWithAddress:(const struct sockaddr_in *)hostAddress. How should we input the IP address we want to check into this line? This is the part where i'm really lost at.

推荐答案

struct sockaddr_in是BSD套接字使用的低级套接字地址"类型.我们通常不会在Cocoa级别上与它们打交道,但它们会不时地出现,包括在Apple的演示课程中.之所以这样,是因为SCNetworkReachability在其创建函数之一中使用了struct sockaddr_in.

struct sockaddr_in is a low-level "socket address" type used by BSD sockets. We generally don't deal with them at the Cocoa level, but they can creep up from time to time, including in Apple's demo class. The reason there is because SCNetworkReachability uses a struct sockaddr_in in one of its creation functions.

但是,幸运的是,您可以使用+reachabilityWithHostName:方法提供一个字符串来代替,该字符串包括IP地址(与主机名一样,底层的网络API会自动为您解析).

Fortunately for you, however, you can supply a string instead with the +reachabilityWithHostName: method, and that includes IP addresses (which, like hostnames, will be resolved automatically for you by the underlying network APIs.)

Reachability *r = [Reachability reachabilityWithHostName:@"1.2.3.4"];

这篇关于IP地址的可达性不起作用.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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