FreeBSD/contrib/ntp/ntpd/ntp_io.c
/*
 * calc_addr_distance - calculate the distance between two addresses,
 *			the absolute value of the difference between
 *			the addresses numerically, stored as an address.
 */
calculate the distance between two addresses,
the absolute value of the difference between
the addresses numerically, stored as an address.
calculate the distance between two addresses the absolute value of the difference between the addresses numerically stored as an address .
static void
calc_addr_distance(
	sockaddr_u *		dist,
	const sockaddr_u *	a1,
	const sockaddr_u *	a2
	)
{
	u_int32	a1val;
	u_int32	a2val;
	u_int32	v4dist;
	int	found_greater;
	int	a1_greater;
	int	i;
	REQUIRE(AF(a1) == AF(a2));
	ZERO_SOCK(dist);
	AF(dist) = AF(a1);
	if (IS_IPV4(a1)) {
		a1val = SRCADR(a1);
		a2val = SRCADR(a2);
		v4dist = (a1val > a2val)
			     ? a1val - a2val
			     : a2val - a1val;
		SET_ADDR4(dist, v4dist);
		return;
	}
	found_greater = FALSE;
	a1_greater = FALSE;	
	for (i = 0; i < (int)sizeof(NSRCADR6(a1)); i++) {
		if (!found_greater &&
		    NSRCADR6(a1)[i] != NSRCADR6(a2)[i]) {
			found_greater = TRUE;
			a1_greater = (NSRCADR6(a1)[i] > NSRCADR6(a2)[i]);
		}
		if (!found_greater) {
			NSRCADR6(dist)[i] = 0;
		} else {
			if (a1_greater)
				NSRCADR6(dist)[i] = NSRCADR6(a1)[i] -
						    NSRCADR6(a2)[i];
			else
				NSRCADR6(dist)[i] = NSRCADR6(a2)[i] -
						    NSRCADR6(a1)[i];
		}
	}
}
static void calc_addr_distance ( sockaddr_u * dist , const sockaddr_u * a1 , const sockaddr_u * a2 ) { u_int32 a1val ; u_int32 a2val ; u_int32 v4dist ; int found_greater ; int a1_greater ; int i ; REQUIRE ( AF ( a1 ) == AF ( a2 ) ) ; ZERO_SOCK ( dist ) ; AF ( dist ) = AF ( a1 ) ; if ( IS_IPV4 ( a1 ) ) { a1val = SRCADR ( a1 ) ; a2val = SRCADR ( a2 ) ; v4dist = ( a1val > a2val ) ? a1val - a2val : a2val - a1val ; SET_ADDR4 ( dist , v4dist ) ; return ; } found_greater = FALSE ; a1_greater = FALSE ; for ( i = 0 ; i < ( int ) sizeof ( NSRCADR6 ( a1 ) ) ; i ++ ) { if ( ! found_greater && NSRCADR6 ( a1 ) [ i ] != NSRCADR6 ( a2 ) [ i ] ) { found_greater = TRUE ; a1_greater = ( NSRCADR6 ( a1 ) [ i ] > NSRCADR6 ( a2 ) [ i ] ) ; } if ( ! found_greater ) { NSRCADR6 ( dist ) [ i ] = 0 ; } else { if ( a1_greater ) NSRCADR6 ( dist ) [ i ] = NSRCADR6 ( a1 ) [ i ] - NSRCADR6 ( a2 ) [ i ] ; else NSRCADR6 ( dist ) [ i ] = NSRCADR6 ( a2 ) [ i ] - NSRCADR6 ( a1 ) [ i ] ; } } }
calc_addr_distance - calculate the distance between two addresses,
                      the absolute value of the difference between
                      the addresses numerically, stored as an address.
calc_addr_distance - calculate the distance between two addresses the absolute value of the difference between the addresses numerically stored as an address .
/* v4 can be done a bit simpler */ /* suppress pot. uninit. warning */