File: recvping.c

package info (click to toggle)
icmpinfo 1.11-12
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster, sid, stretch, trixie
  • size: 216 kB
  • ctags: 217
  • sloc: ansic: 1,024; makefile: 50
file content (32 lines) | stat: -rw-r--r-- 643 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
 * Infinite loop to receive every ICMP packet received on the socket.
 * For every packet that's received, we just call pr_pack() to look
 * at it and print it.
 */

#include	"defs.h"

void recv_ping()
{
	register int		n;
#if !defined(__GLIBC__)
	int			fromlen;
#else /* __GLIBC__ */
	socklen_t		fromlen;
#endif /* __GLIBC__ */
	struct sockaddr_in	from;

	for ( ; ; ) {
		fromlen = sizeof(from);
		if ( (n = recvfrom(sockfd, recvpack, sizeof(recvpack), 0,
				(struct sockaddr *) &from, &fromlen)) < 0) {
			if (errno == EINTR)
				continue;	/* normal */
			err_ret("recvfrom error");
			continue;
		}

		pr_pack(recvpack, n, &from);

	}
}