我想用超时和TTL进行ping.我使用Apple的代码("Simple Ping").我读到它 "iOS ping with timeout".我改变代码:
CFSocketNativeHandle sock = CFSocketGetNative(self->_socket);
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 100000; // 0.1 sec
setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (void *)&tv, sizeof(tv));
bytesSent = sendto(
sock,
[packet bytes],
[packet length],
0,
(struct sockaddr *) [self.hostAddress bytes],
(socklen_t) [self.hostAddress length]
);
Run Code Online (Sandbox Code Playgroud)
但我不明白我应该把代码放在哪里,以显示我接收数据包的超时.此外,我需要使用TTL(生存时间)信息进行ping操作.我想根据这种模式获取信息:icmp_seq=count from=ip_address ttl=value_of_ttl time=value_of_replytime_ms