From 41e442fea26f20ceb815306777d36361575825cc Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Mon, 26 Aug 2013 13:05:01 +0200 Subject: Allow ping to be interrupted Signed-off-by: Hannes Reinecke --- ping.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ping.c b/ping.c index 06cc369..2c76677 100644 --- a/ping.c +++ b/ping.c @@ -92,6 +92,7 @@ static unsigned short in_cksum(const unsigned short *addr, int len, unsigned sho static void pr_icmph(uint8_t type, uint8_t code, uint32_t info, struct icmphdr *icp); static int parsetos(char *str); static int parseflow(char *str); +static void doexit (int); static struct sockaddr_in source = { .sin_family = AF_INET }; char *device; @@ -543,6 +544,8 @@ int ping4_run(int argc, char **argv, struct addrinfo *ai, socket_st *sock) options |= F_SOURCEROUTE; } } + set_signal(SIGINT, doexit); + while (argc > 0) { target = *argv; @@ -1619,3 +1622,8 @@ void ping4_install_filter(socket_st *sock) if (setsockopt(sock->fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter, sizeof(filter))) error(0, errno, _("WARNING: failed to install socket filter")); } + +static void doexit(int signo __attribute__((unused))) +{ + exit (1); +} -- 2.21.0