Signed-off-by: Alex Henrie alexhenrie24@gmail.com --- programs/ping/ping_main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/programs/ping/ping_main.c b/programs/ping/ping_main.c index 74a1c71c65..9c4f23959e 100644 --- a/programs/ping/ping_main.c +++ b/programs/ping/ping_main.c @@ -157,6 +157,7 @@ int main(int argc, char** argv) printf("Pinging %s [%s] with %d bytes of data:\n", hostname, ip, l); for (;;) { + SetLastError(0); retval = IcmpSendEcho(icmp_file, ipaddr, send_data, l, NULL, reply_buffer, reply_size, w); if (retval != 0) @@ -177,7 +178,10 @@ int main(int argc, char** argv) } else { - printf("Request timed out.\n"); + if (GetLastError() == IP_REQ_TIMED_OUT) + puts("Request timed out."); + else + puts("PING: transmit failed. General failure."); lost++; } i++;
Hello Alex,
On 08/03/2018, Alex Henrie alexhenrie24@gmail.com wrote:
Signed-off-by: Alex Henrie alexhenrie24@gmail.com
programs/ping/ping_main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/programs/ping/ping_main.c b/programs/ping/ping_main.c index 74a1c71c65..9c4f23959e 100644 --- a/programs/ping/ping_main.c +++ b/programs/ping/ping_main.c @@ -157,6 +157,7 @@ int main(int argc, char** argv) printf("Pinging %s [%s] with %d bytes of data:\n", hostname, ip, l); for (;;) {
SetLastError(0); retval = IcmpSendEcho(icmp_file, ipaddr, send_data, l, NULL, reply_buffer, reply_size, w); if (retval != 0)
@@ -177,7 +178,10 @@ int main(int argc, char** argv) } else {
printf("Request timed out.\n");
if (GetLastError() == IP_REQ_TIMED_OUT)
puts("Request timed out.");
else
puts("PING: transmit failed. General failure.");
Wouldn't it be better to use FormatMessage to print exact error instead of "General failure"?
lost++; } i++;
-- 2.16.2
Regards, Ruslan
Missatge de Ruslan Kabatsayev b7.10110111@gmail.com del dia dj., 8 de març 2018 a les 3:16:
Wouldn't it be better to use FormatMessage to print exact error instead of "General failure"?
I can do that, but it will be quite a bit more work because I'll have to add all the errors that IcmpSendEcho can set to dlls/kernel32/winerror.mc. That's probably the right solution though.
-Alex
Missatge de Alex Henrie alexhenrie24@gmail.com del dia dj., 8 de març 2018 a les 8:52:
Missatge de Ruslan Kabatsayev b7.10110111@gmail.com del dia dj., 8 de març 2018 a les 3:16:
Wouldn't it be better to use FormatMessage to print exact error instead of "General failure"?
I can do that, but it will be quite a bit more work because I'll have to add all the errors that IcmpSendEcho can set to dlls/kernel32/winerror.mc. That's probably the right solution though.
I just checked and the strings created by FormatMessage are incorrect for these error codes, probably because the codes were reused for WSA errors. So, my original patch is basically correct: Any specific error messages would have to come from ping.exe itself.
-Alex