* Return the IP multicast options in response to user getsockopt(). */
| 1787 | * Return the IP multicast options in response to user getsockopt(). |
| 1788 | */ |
| 1789 | int |
| 1790 | inp_getmoptions(struct inpcb *inp, struct sockopt *sopt) |
| 1791 | { |
| 1792 | struct rm_priotracker in_ifa_tracker; |
| 1793 | struct ip_mreqn mreqn; |
| 1794 | struct ip_moptions *imo; |
| 1795 | struct ifnet *ifp; |
| 1796 | struct in_ifaddr *ia; |
| 1797 | int error, optval; |
| 1798 | u_char coptval; |
| 1799 | |
| 1800 | INP_WLOCK(inp); |
| 1801 | imo = inp->inp_moptions; |
| 1802 | /* |
| 1803 | * If socket is neither of type SOCK_RAW or SOCK_DGRAM, |
| 1804 | * or is a divert socket, reject it. |
| 1805 | */ |
| 1806 | if (inp->inp_socket->so_proto->pr_protocol == IPPROTO_DIVERT || |
| 1807 | (inp->inp_socket->so_proto->pr_type != SOCK_RAW && |
| 1808 | inp->inp_socket->so_proto->pr_type != SOCK_DGRAM)) { |
| 1809 | INP_WUNLOCK(inp); |
| 1810 | return (EOPNOTSUPP); |
| 1811 | } |
| 1812 | |
| 1813 | error = 0; |
| 1814 | switch (sopt->sopt_name) { |
| 1815 | case IP_MULTICAST_VIF: |
| 1816 | if (imo != NULL) |
| 1817 | optval = imo->imo_multicast_vif; |
| 1818 | else |
| 1819 | optval = -1; |
| 1820 | INP_WUNLOCK(inp); |
| 1821 | error = sooptcopyout(sopt, &optval, sizeof(int)); |
| 1822 | break; |
| 1823 | |
| 1824 | case IP_MULTICAST_IF: |
| 1825 | memset(&mreqn, 0, sizeof(struct ip_mreqn)); |
| 1826 | if (imo != NULL) { |
| 1827 | ifp = imo->imo_multicast_ifp; |
| 1828 | if (!in_nullhost(imo->imo_multicast_addr)) { |
| 1829 | mreqn.imr_address = imo->imo_multicast_addr; |
| 1830 | } else if (ifp != NULL) { |
| 1831 | struct epoch_tracker et; |
| 1832 | |
| 1833 | mreqn.imr_ifindex = ifp->if_index; |
| 1834 | NET_EPOCH_ENTER(et); |
| 1835 | IFP_TO_IA(ifp, ia, &in_ifa_tracker); |
| 1836 | if (ia != NULL) |
| 1837 | mreqn.imr_address = |
| 1838 | IA_SIN(ia)->sin_addr; |
| 1839 | NET_EPOCH_EXIT(et); |
| 1840 | } |
| 1841 | } |
| 1842 | INP_WUNLOCK(inp); |
| 1843 | if (sopt->sopt_valsize == sizeof(struct ip_mreqn)) { |
| 1844 | error = sooptcopyout(sopt, &mreqn, |
| 1845 | sizeof(struct ip_mreqn)); |
| 1846 | } else { |
no test coverage detected