FreeBSD/tools/regression/netinet/ipmulticast/ipmulticast.c
/*
 * Protocol-agnostic multicast I/O loop.
 *
 * Wait for 'timeout' seconds looking for traffic on group, so that manual
 * or automated regression tests (possibly running on another host) have an
 * opportunity to transmit within the group to test source filters.
 *
 * If the filter failed, this loop will report if we received traffic
 * from the source we elected to monitor.
 */
Protocol-agnostic multicast I/O loop.
Wait for 'timeout' seconds looking for traffic on group, so that manual
or automated regression tests (possibly running on another host) have an
opportunity to transmit within the group to test source filters.

If the filter failed, this loop will report if we received traffic
from the source we elected to monitor.
Protocol - agnostic multicast I / O loop . Wait for ' timeout ' seconds looking for traffic on group so that manual or automated regression tests ( possibly running on another host ) have an opportunity to transmit within the group to test source filters . If the filter failed this loop will report if we received traffic from the source we elected to monitor .
static int
recv_loop_with_match(int sock, sockunion_t *group, sockunion_t *source)
{
	int		 error;
	sockunion_t	 from;
	char		 groupname[NI_MAXHOST];
	ssize_t		 len;
	size_t		 npackets;
	int		 jmpretval;
	char		 rxbuf[RXBUFSIZE];
	char		 sourcename[NI_MAXHOST];
	assert(source->sa.sa_family == AF_INET);
	if (timeout == 0)
		return (0);
	error = getnameinfo(&group->sa, group->sa.sa_len, groupname,
	    NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
	if (error) {
		fprintf(stderr, "getnameinfo: %s\n", gai_strerror(error));
		return (error);
	}
	error = getnameinfo(&source->sa, source->sa.sa_len, sourcename,
	    NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
	if (error) {
		fprintf(stderr, "getnameinfo: %s\n", gai_strerror(error));
		return (error);
	}
	fprintf(stdout,
	    "Waiting %d seconds for inbound traffic on group %s\n"
	    "Expecting no traffic from blocked source: %s\n",
	    (int)timeout, groupname, sourcename);
	signal(SIGINT, signal_handler);
	signal(SIGALRM, signal_handler);
	error = 0;
	npackets = 0;
	alarm(timeout);
	while (0 == (jmpretval = setjmp(jmpbuf))) {
		len = recvfrom(sock, rxbuf, RXBUFSIZE, 0, &from.sa,
		    (socklen_t *)&from.sa.sa_len);
		if (dodebug) {
			fprintf(stderr, "debug: packet received from %s\n",
			    inet_ntoa(from.sin.sin_addr));
		}
		if (source &&
		    source->sin.sin_addr.s_addr == from.sin.sin_addr.s_addr)
			break;
		npackets++;
	}
	if (doverbose) {
		fprintf(stderr, "Number of datagrams received from "
		    "non-blocked sources: %d\n", (int)npackets);
	}
	switch (jmpretval) {
	case SIGALRM:	
		break;
	case SIGINT:	
		fprintf(stderr, "interrupted\n");
		error = 20;
		break;
	case 0:		
		fprintf(stderr, "FAIL: got packet from blocked source\n");
		error = EX_IOERR;
		break;
	default:
		warnx("recvfrom");
		error = EX_OSERR;
		break;
	}
	signal(SIGINT, SIG_DFL);
	signal(SIGALRM, SIG_DFL);
	return (error);
}
static int recv_loop_with_match ( int sock , sockunion_t * group , sockunion_t * source ) { int error ; sockunion_t from ; char groupname [ NI_MAXHOST ] ; ssize_t len ; size_t npackets ; int jmpretval ; char rxbuf [ RXBUFSIZE ] ; char sourcename [ NI_MAXHOST ] ; assert ( source -> sa . sa_family == AF_INET ) ; if ( timeout == 0 ) return ( 0 ) ; error = getnameinfo ( & group -> sa , group -> sa . sa_len , groupname , NI_MAXHOST , NULL , 0 , NI_NUMERICHOST ) ; if ( error ) { fprintf ( stderr , " \n " , gai_strerror ( error ) ) ; return ( error ) ; } error = getnameinfo ( & source -> sa , source -> sa . sa_len , sourcename , NI_MAXHOST , NULL , 0 , NI_NUMERICHOST ) ; if ( error ) { fprintf ( stderr , " \n " , gai_strerror ( error ) ) ; return ( error ) ; } fprintf ( stdout , " \n " " \n " , ( int ) timeout , groupname , sourcename ) ; signal ( SIGINT , signal_handler ) ; signal ( SIGALRM , signal_handler ) ; error = 0 ; npackets = 0 ; alarm ( timeout ) ; while ( 0 == ( jmpretval = setjmp ( jmpbuf ) ) ) { len = recvfrom ( sock , rxbuf , RXBUFSIZE , 0 , & from . sa , ( socklen_t * ) & from . sa . sa_len ) ; if ( dodebug ) { fprintf ( stderr , " \n " , inet_ntoa ( from . sin . sin_addr ) ) ; } if ( source && source -> sin . sin_addr . s_addr == from . sin . sin_addr . s_addr ) break ; npackets ++ ; } if ( doverbose ) { fprintf ( stderr , " " " \n " , ( int ) npackets ) ; } switch ( jmpretval ) { case SIGALRM : break ; case SIGINT : fprintf ( stderr , " \n " ) ; error = 20 ; break ; case 0 : fprintf ( stderr , " \n " ) ; error = EX_IOERR ; break ; default : warnx ( " " ) ; error = EX_OSERR ; break ; } signal ( SIGINT , SIG_DFL ) ; signal ( SIGALRM , SIG_DFL ) ; return ( error ) ; }
Protocol-agnostic multicast I/O loop.
Protocol - agnostic multicast I / O loop .
/*
	 * Return immediately if we don't need to wait for traffic.
	 */ /* ok */ /* go bye bye */ /* Broke out of loop; saw a bad source. */