|
@@ -97,6 +97,7 @@ struct ping_host_struct {
|
|
|
FAST_PING_TYPE type;
|
|
FAST_PING_TYPE type;
|
|
|
|
|
|
|
|
void *userptr;
|
|
void *userptr;
|
|
|
|
|
+ int error;
|
|
|
fast_ping_result ping_callback;
|
|
fast_ping_result ping_callback;
|
|
|
char host[PING_MAX_HOSTLEN];
|
|
char host[PING_MAX_HOSTLEN];
|
|
|
|
|
|
|
@@ -386,7 +387,7 @@ static void _fast_ping_host_put(struct ping_host_struct *ping_host)
|
|
|
tv.tv_usec = 0;
|
|
tv.tv_usec = 0;
|
|
|
|
|
|
|
|
ping_host->ping_callback(ping_host, ping_host->host, PING_RESULT_END, &ping_host->addr, ping_host->addr_len,
|
|
ping_host->ping_callback(ping_host, ping_host->host, PING_RESULT_END, &ping_host->addr, ping_host->addr_len,
|
|
|
- ping_host->seq, ping_host->ttl, &tv, ping_host->userptr);
|
|
|
|
|
|
|
+ ping_host->seq, ping_host->ttl, &tv, ping_host->error, ping_host->userptr);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
tlog(TLOG_DEBUG, "ping end, id %d", ping_host->sid);
|
|
tlog(TLOG_DEBUG, "ping end, id %d", ping_host->sid);
|
|
@@ -414,7 +415,7 @@ static void _fast_ping_host_remove(struct ping_host_struct *ping_host)
|
|
|
tv.tv_usec = 0;
|
|
tv.tv_usec = 0;
|
|
|
|
|
|
|
|
ping_host->ping_callback(ping_host, ping_host->host, PING_RESULT_END, &ping_host->addr, ping_host->addr_len,
|
|
ping_host->ping_callback(ping_host, ping_host->host, PING_RESULT_END, &ping_host->addr, ping_host->addr_len,
|
|
|
- ping_host->seq, ping_host->ttl, &tv, ping_host->userptr);
|
|
|
|
|
|
|
+ ping_host->seq, ping_host->ttl, &tv, ping_host->error, ping_host->userptr);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
_fast_ping_host_put(ping_host);
|
|
_fast_ping_host_put(ping_host);
|
|
@@ -445,7 +446,7 @@ static int _fast_ping_sendping_v6(struct ping_host_struct *ping_host)
|
|
|
(struct sockaddr *)&ping_host->addr, ping_host->addr_len);
|
|
(struct sockaddr *)&ping_host->addr, ping_host->addr_len);
|
|
|
if (len < 0 || len != sizeof(struct fast_ping_packet)) {
|
|
if (len < 0 || len != sizeof(struct fast_ping_packet)) {
|
|
|
int err = errno;
|
|
int err = errno;
|
|
|
- if (errno == ENETUNREACH || errno == EINVAL) {
|
|
|
|
|
|
|
+ if (errno == ENETUNREACH || errno == EINVAL || errno == EADDRNOTAVAIL) {
|
|
|
goto errout;
|
|
goto errout;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -644,6 +645,7 @@ static int _fast_ping_sendping(struct ping_host_struct *ping_host)
|
|
|
ping_host->send = 1;
|
|
ping_host->send = 1;
|
|
|
|
|
|
|
|
if (ret != 0) {
|
|
if (ret != 0) {
|
|
|
|
|
+ ping_host->error = errno;
|
|
|
return ret;
|
|
return ret;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -848,13 +850,15 @@ errout:
|
|
|
|
|
|
|
|
static void _fast_ping_print_result(struct ping_host_struct *ping_host, const char *host, FAST_PING_RESULT result,
|
|
static void _fast_ping_print_result(struct ping_host_struct *ping_host, const char *host, FAST_PING_RESULT result,
|
|
|
struct sockaddr *addr, socklen_t addr_len, int seqno, int ttl, struct timeval *tv,
|
|
struct sockaddr *addr, socklen_t addr_len, int seqno, int ttl, struct timeval *tv,
|
|
|
- void *userptr)
|
|
|
|
|
|
|
+ int error, void *userptr)
|
|
|
{
|
|
{
|
|
|
if (result == PING_RESULT_RESPONSE) {
|
|
if (result == PING_RESULT_RESPONSE) {
|
|
|
double rtt = tv->tv_sec * 1000.0 + tv->tv_usec / 1000.0;
|
|
double rtt = tv->tv_sec * 1000.0 + tv->tv_usec / 1000.0;
|
|
|
tlog(TLOG_INFO, "from %15s: seq=%d ttl=%d time=%.3f\n", host, seqno, ttl, rtt);
|
|
tlog(TLOG_INFO, "from %15s: seq=%d ttl=%d time=%.3f\n", host, seqno, ttl, rtt);
|
|
|
} else if (result == PING_RESULT_TIMEOUT) {
|
|
} else if (result == PING_RESULT_TIMEOUT) {
|
|
|
tlog(TLOG_INFO, "from %15s: seq=%d timeout\n", host, seqno);
|
|
tlog(TLOG_INFO, "from %15s: seq=%d timeout\n", host, seqno);
|
|
|
|
|
+ } else if (result == PING_RESULT_ERROR) {
|
|
|
|
|
+ tlog(TLOG_DEBUG, "from %15s: error is %s\n", host, strerror(error));
|
|
|
} else if (result == PING_RESULT_END) {
|
|
} else if (result == PING_RESULT_END) {
|
|
|
fast_ping_stop(ping_host);
|
|
fast_ping_stop(ping_host);
|
|
|
}
|
|
}
|
|
@@ -1041,7 +1045,6 @@ struct ping_host_struct *fast_ping_start(PING_TYPE type, const char *host, int c
|
|
|
|
|
|
|
|
ret = _fast_ping_get_addr_by_type(type, ip_str, port, &gai, &ping_type);
|
|
ret = _fast_ping_get_addr_by_type(type, ip_str, port, &gai, &ping_type);
|
|
|
if (ret != 0) {
|
|
if (ret != 0) {
|
|
|
- tlog(TLOG_ERROR, "get addr by type failed, host: %s", host);
|
|
|
|
|
goto errout;
|
|
goto errout;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1097,6 +1100,9 @@ struct ping_host_struct *fast_ping_start(PING_TYPE type, const char *host, int c
|
|
|
_fast_ping_host_put(ping_host);
|
|
_fast_ping_host_put(ping_host);
|
|
|
return ping_host;
|
|
return ping_host;
|
|
|
errout_remove:
|
|
errout_remove:
|
|
|
|
|
+ ping_host->ping_callback(ping_host, ping_host->host, PING_RESULT_ERROR, &ping_host->addr,
|
|
|
|
|
+ ping_host->addr_len, ping_host->seq, ping_host->ttl, 0,
|
|
|
|
|
+ ping_host->error, ping_host->userptr);
|
|
|
fast_ping_stop(ping_host);
|
|
fast_ping_stop(ping_host);
|
|
|
_fast_ping_host_put(ping_host);
|
|
_fast_ping_host_put(ping_host);
|
|
|
ping_host = NULL;
|
|
ping_host = NULL;
|
|
@@ -1315,7 +1321,7 @@ static int _fast_ping_process_icmp(struct ping_host_struct *ping_host, struct ti
|
|
|
if (recv_ping_host->ping_callback) {
|
|
if (recv_ping_host->ping_callback) {
|
|
|
recv_ping_host->ping_callback(recv_ping_host, recv_ping_host->host, PING_RESULT_RESPONSE, &recv_ping_host->addr,
|
|
recv_ping_host->ping_callback(recv_ping_host, recv_ping_host->host, PING_RESULT_RESPONSE, &recv_ping_host->addr,
|
|
|
recv_ping_host->addr_len, recv_ping_host->seq, recv_ping_host->ttl, &tvresult,
|
|
recv_ping_host->addr_len, recv_ping_host->seq, recv_ping_host->ttl, &tvresult,
|
|
|
- recv_ping_host->userptr);
|
|
|
|
|
|
|
+ ping_host->error, recv_ping_host->userptr);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
recv_ping_host->send = 0;
|
|
recv_ping_host->send = 0;
|
|
@@ -1349,7 +1355,8 @@ static int _fast_ping_process_tcp(struct ping_host_struct *ping_host, struct epo
|
|
|
tv_sub(&tvresult, tvsend);
|
|
tv_sub(&tvresult, tvsend);
|
|
|
if (ping_host->ping_callback) {
|
|
if (ping_host->ping_callback) {
|
|
|
ping_host->ping_callback(ping_host, ping_host->host, PING_RESULT_RESPONSE, &ping_host->addr,
|
|
ping_host->ping_callback(ping_host, ping_host->host, PING_RESULT_RESPONSE, &ping_host->addr,
|
|
|
- ping_host->addr_len, ping_host->seq, ping_host->ttl, &tvresult, ping_host->userptr);
|
|
|
|
|
|
|
+ ping_host->addr_len, ping_host->seq, ping_host->ttl, &tvresult, ping_host->error,
|
|
|
|
|
+ ping_host->userptr);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ping_host->send = 0;
|
|
ping_host->send = 0;
|
|
@@ -1445,7 +1452,7 @@ static int _fast_ping_process_udp(struct ping_host_struct *ping_host, struct tim
|
|
|
if (recv_ping_host->ping_callback) {
|
|
if (recv_ping_host->ping_callback) {
|
|
|
recv_ping_host->ping_callback(recv_ping_host, recv_ping_host->host, PING_RESULT_RESPONSE, &recv_ping_host->addr,
|
|
recv_ping_host->ping_callback(recv_ping_host, recv_ping_host->host, PING_RESULT_RESPONSE, &recv_ping_host->addr,
|
|
|
recv_ping_host->addr_len, recv_ping_host->seq, recv_ping_host->ttl, &tvresult,
|
|
recv_ping_host->addr_len, recv_ping_host->seq, recv_ping_host->ttl, &tvresult,
|
|
|
- recv_ping_host->userptr);
|
|
|
|
|
|
|
+ ping_host->error, recv_ping_host->userptr);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
recv_ping_host->send = 0;
|
|
recv_ping_host->send = 0;
|
|
@@ -1554,7 +1561,7 @@ static void _fast_ping_period_run(void)
|
|
|
if (millisecond >= ping_host->timeout && ping_host->send == 1) {
|
|
if (millisecond >= ping_host->timeout && ping_host->send == 1) {
|
|
|
ping_host->ping_callback(ping_host, ping_host->host, PING_RESULT_TIMEOUT, &ping_host->addr,
|
|
ping_host->ping_callback(ping_host, ping_host->host, PING_RESULT_TIMEOUT, &ping_host->addr,
|
|
|
ping_host->addr_len, ping_host->seq, ping_host->ttl, &interval,
|
|
ping_host->addr_len, ping_host->seq, ping_host->ttl, &interval,
|
|
|
- ping_host->userptr);
|
|
|
|
|
|
|
+ ping_host->error, ping_host->userptr);
|
|
|
ping_host->send = 0;
|
|
ping_host->send = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|