src/usr.sbin/mountd/mountd.c
/*
 * Compare two sockaddrs according to a specified mask. Return zero if
 * `sa1' matches `sa2' when filtered by the netmask in `samask'.
 * If samask is NULL, perform a full comparison.
 */
Compare two sockaddrs according to a specified mask. Return zero if
`sa1' matches `sa2' when filtered by the netmask in `samask'.
If samask is NULL, perform a full comparison.
Compare two sockaddrs according to a specified mask . Return zero if ` sa1 ' matches ` sa2 ' when filtered by the netmask in ` samask ' . If samask is NULL perform a full comparison .
static int
sacmp(struct sockaddr *sa1, struct sockaddr *sa2, struct sockaddr *samask)
{
	unsigned char *p1, *p2, *mask;
	int len, i;
	if (sa1->sa_family != sa2->sa_family ||
	    (p1 = sa_rawaddr(sa1, &len)) == NULL ||
	    (p2 = sa_rawaddr(sa2, NULL)) == NULL)
		return (1);
	switch (sa1->sa_family) {
	case AF_INET6:
		if (((struct sockaddr_in6 *)sa1)->sin6_scope_id !=
		    ((struct sockaddr_in6 *)sa2)->sin6_scope_id)
			return (1);
		break;
	}
	if (samask == NULL)
		return (memcmp(p1, p2, len));
	if (sa1->sa_family != samask->sa_family ||
	    (mask = sa_rawaddr(samask, NULL)) == NULL)
		return (1);
	for (i = 0; i < len; i++)
		if ((p1[i] & mask[i]) != (p2[i] & mask[i]))
			return (1);
	return (0);
}
static int sacmp ( struct sockaddr * sa1 , struct sockaddr * sa2 , struct sockaddr * samask ) { unsigned char * p1 , * p2 , * mask ; int len , i ; if ( sa1 -> sa_family != sa2 -> sa_family || ( p1 = sa_rawaddr ( sa1 , & len ) ) == NULL || ( p2 = sa_rawaddr ( sa2 , NULL ) ) == NULL ) return ( 1 ) ; switch ( sa1 -> sa_family ) { case AF_INET6 : if ( ( ( struct sockaddr_in6 * ) sa1 ) -> sin6_scope_id != ( ( struct sockaddr_in6 * ) sa2 ) -> sin6_scope_id ) return ( 1 ) ; break ; } if ( samask == NULL ) return ( memcmp ( p1 , p2 , len ) ) ; if ( sa1 -> sa_family != samask -> sa_family || ( mask = sa_rawaddr ( samask , NULL ) ) == NULL ) return ( 1 ) ; for ( i = 0 ; i < len ; i ++ ) if ( ( p1 [ i ] & mask [ i ] ) != ( p2 [ i ] & mask [ i ] ) ) return ( 1 ) ; return ( 0 ) ; }
Compare two sockaddrs according to a specified mask.
Compare two sockaddrs according to a specified mask .
/* Simple binary comparison if no mask specified. */ /* Set up the mask, and do a mask-based comparison. */