From 8233cf3eb30a934fe4993f42df5051d8a8944705 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 4 May 2023 14:11:01 +0200 Subject: ping: fixed unreachable hosts and and interrupted system calls in receive --- README | 1 + ping.c | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README b/README index 99ae704..3eca7a0 100644 --- a/README +++ b/README @@ -13,6 +13,7 @@ Currently it contains the following: - a 'netstat': see list of active connections of a machine - 'mkswap' - 'fsck.ext4', 'mkfs.ext4': if ext4 is the only file system we support +- 'nbd-client': for NBD root mounts Note: abase is a shameless copy of sbase/ubase in certain areas like the Makefile, libutil, etc. This might also make an integration into diff --git a/ping.c b/ping.c index e2d9fd0..148e406 100644 --- a/ping.c +++ b/ping.c @@ -174,9 +174,13 @@ main(int argc, char *argv[]) unsigned int address_len = sizeof(sending_address); if (recvfrom(fd, &packet, sizeof(packet), 0, (struct sockaddr *)&sending_address, &address_len) <= 0) { - freeaddrinfo(addresses); - close(fd); - eprintf("Unable to receive packet from '%s': %s\n", host, strerror(errno)); + if (errno == EAGAIN || errno == EINTR) { + // ok, not reachable or interrupted by Ctrl-C + } else { + freeaddrinfo(addresses); + close(fd); + eprintf("Unable to receive packet from '%s': %s\n", host, strerror(errno)); + } } else { if (sent) { if (packet.header.type != 69 || packet.header.code != 0) { -- cgit v1.2.3-54-g00ecf