FreeBSD/sys/netinet6/in6_mcast.c
/*
 * Return the IP multicast options in response to user getsockopt().
 */
Return the IP multicast options in response to user getsockopt().
Return the IP multicast options in response to user getsockopt () .
int
ip6_getmoptions(struct inpcb *inp, struct sockopt *sopt)
{
	struct ip6_moptions	*im6o;
	int			 error;
	u_int			 optval;
	INP_WLOCK(inp);
	im6o = inp->in6p_moptions;
	if (inp->inp_socket->so_proto->pr_protocol == IPPROTO_DIVERT ||
	    (inp->inp_socket->so_proto->pr_type != SOCK_RAW &&
	    inp->inp_socket->so_proto->pr_type != SOCK_DGRAM)) {
		INP_WUNLOCK(inp);
		return (EOPNOTSUPP);
	}
	error = 0;
	switch (sopt->sopt_name) {
	case IPV6_MULTICAST_IF:
		if (im6o == NULL || im6o->im6o_multicast_ifp == NULL) {
			optval = 0;
		} else {
			optval = im6o->im6o_multicast_ifp->if_index;
		}
		INP_WUNLOCK(inp);
		error = sooptcopyout(sopt, &optval, sizeof(u_int));
		break;
	case IPV6_MULTICAST_HOPS:
		if (im6o == NULL)
			optval = V_ip6_defmcasthlim;
		else
			optval = im6o->im6o_multicast_hlim;
		INP_WUNLOCK(inp);
		error = sooptcopyout(sopt, &optval, sizeof(u_int));
		break;
	case IPV6_MULTICAST_LOOP:
		if (im6o == NULL)
			optval = in6_mcast_loop; 
		else
			optval = im6o->im6o_multicast_loop;
		INP_WUNLOCK(inp);
		error = sooptcopyout(sopt, &optval, sizeof(u_int));
		break;
	case IPV6_MSFILTER:
		if (im6o == NULL) {
			error = EADDRNOTAVAIL;
			INP_WUNLOCK(inp);
		} else {
			error = in6p_get_source_filters(inp, sopt);
		}
		break;
	default:
		INP_WUNLOCK(inp);
		error = ENOPROTOOPT;
		break;
	}
	INP_UNLOCK_ASSERT(inp);
	return (error);
}
int ip6_getmoptions ( struct inpcb * inp , struct sockopt * sopt ) { struct ip6_moptions * im6o ; int error ; u_int optval ; INP_WLOCK ( inp ) ; im6o = inp -> in6p_moptions ; if ( inp -> inp_socket -> so_proto -> pr_protocol == IPPROTO_DIVERT || ( inp -> inp_socket -> so_proto -> pr_type != SOCK_RAW && inp -> inp_socket -> so_proto -> pr_type != SOCK_DGRAM ) ) { INP_WUNLOCK ( inp ) ; return ( EOPNOTSUPP ) ; } error = 0 ; switch ( sopt -> sopt_name ) { case IPV6_MULTICAST_IF : if ( im6o == NULL || im6o -> im6o_multicast_ifp == NULL ) { optval = 0 ; } else { optval = im6o -> im6o_multicast_ifp -> if_index ; } INP_WUNLOCK ( inp ) ; error = sooptcopyout ( sopt , & optval , sizeof ( u_int ) ) ; break ; case IPV6_MULTICAST_HOPS : if ( im6o == NULL ) optval = V_ip6_defmcasthlim ; else optval = im6o -> im6o_multicast_hlim ; INP_WUNLOCK ( inp ) ; error = sooptcopyout ( sopt , & optval , sizeof ( u_int ) ) ; break ; case IPV6_MULTICAST_LOOP : if ( im6o == NULL ) optval = in6_mcast_loop ; else optval = im6o -> im6o_multicast_loop ; INP_WUNLOCK ( inp ) ; error = sooptcopyout ( sopt , & optval , sizeof ( u_int ) ) ; break ; case IPV6_MSFILTER : if ( im6o == NULL ) { error = EADDRNOTAVAIL ; INP_WUNLOCK ( inp ) ; } else { error = in6p_get_source_filters ( inp , sopt ) ; } break ; default : INP_WUNLOCK ( inp ) ; error = ENOPROTOOPT ; break ; } INP_UNLOCK_ASSERT ( inp ) ; return ( error ) ; }
Return the IP multicast options in response to user getsockopt().
Return the IP multicast options in response to user getsockopt () .
/*
	 * If socket is neither of type SOCK_RAW or SOCK_DGRAM,
	 * or is a divert socket, reject it.
	 */ /* XXX VIMAGE */