FreeBSD/sys/netinet/in_mcast.c
/*
 * Return a pointer to an in_msource owned by an in_mfilter,
 * given its source address.
 * Lazy-allocate if needed. If this is a new entry its filter state is
 * undefined at t0.
 *
 * imf is the filter set being modified.
 * haddr is the source address in *host* byte-order.
 *
 * SMPng: May be called with locks held; malloc must not block.
 */
Return a pointer to an in_msource owned by an in_mfilter,
given its source address.
Lazy-allocate if needed. If this is a new entry its filter state is
undefined at t0.

imf is the filter set being modified.
haddr is the source address in *host* byte-order.

May be called with locks held; malloc must not block.
Return a pointer to an in_msource owned by an in_mfilter given its source address . Lazy - allocate if needed . If this is a new entry its filter state is undefined at t0 . imf is the filter set being modified . haddr is the source address in * host * byte - order . May be called with locks held ; malloc must not block .
static int
imf_get_source(struct in_mfilter *imf, const struct sockaddr_in *psin,
    struct in_msource **plims)
{
	struct ip_msource	 find;
	struct ip_msource	*ims, *nims;
	struct in_msource	*lims;
	int			 error;
	error = 0;
	ims = NULL;
	lims = NULL;
	find.ims_haddr = ntohl(psin->sin_addr.s_addr);
	ims = RB_FIND(ip_msource_tree, &imf->imf_sources, &find);
	lims = (struct in_msource *)ims;
	if (lims == NULL) {
		if (imf->imf_nsrc == in_mcast_maxsocksrc)
			return (ENOSPC);
		nims = malloc(sizeof(struct in_msource), M_INMFILTER,
		    M_NOWAIT | M_ZERO);
		if (nims == NULL)
			return (ENOMEM);
		lims = (struct in_msource *)nims;
		lims->ims_haddr = find.ims_haddr;
		lims->imsl_st[0] = MCAST_UNDEFINED;
		RB_INSERT(ip_msource_tree, &imf->imf_sources, nims);
		++imf->imf_nsrc;
	}
	*plims = lims;
	return (error);
}
static int imf_get_source ( struct in_mfilter * imf , const struct sockaddr_in * psin , struct in_msource * * plims ) { struct ip_msource find ; struct ip_msource * ims , * nims ; struct in_msource * lims ; int error ; error = 0 ; ims = NULL ; lims = NULL ; find . ims_haddr = ntohl ( psin -> sin_addr . s_addr ) ; ims = RB_FIND ( ip_msource_tree , & imf -> imf_sources , & find ) ; lims = ( struct in_msource * ) ims ; if ( lims == NULL ) { if ( imf -> imf_nsrc == in_mcast_maxsocksrc ) return ( ENOSPC ) ; nims = malloc ( sizeof ( struct in_msource ) , M_INMFILTER , M_NOWAIT | M_ZERO ) ; if ( nims == NULL ) return ( ENOMEM ) ; lims = ( struct in_msource * ) nims ; lims -> ims_haddr = find . ims_haddr ; lims -> imsl_st [ 0 ] = MCAST_UNDEFINED ; RB_INSERT ( ip_msource_tree , & imf -> imf_sources , nims ) ; ++ imf -> imf_nsrc ; } * plims = lims ; return ( error ) ; }
Return a pointer to an in_msource owned by an in_mfilter,
 given its source address.
Return a pointer to an in_msource owned by an in_mfilter given its source address .
/* key is host byte order */