我正在尝试确定 iphone 是否可以使用以下代码连接到特定的 IP 地址(简单 ping):
struct sockaddr_in server_address;
server_address.sin_len = sizeof(server_address);
server_address.sin_family = AF_INET;
server_address.sin_port = htons(8888);
server_address.sin_addr.s_addr = inet_addr("192.168.105.44"); // ip address of a server on LAN
Reachability *r = [[Reachability reachabilityWithAddress:&server_address ] retain];
NetworkStatus internetStatus = [r currentReachabilityStatus];
但它总是说状态是“可达”,不管我在 IP 地址中提供什么。我做错什么了吗?为什么这行不通?提前致谢。