case IP_PORTRANGE: *mp = m = m_get(M_WAIT, MT_SOOPTS); m->m_len = sizeof(int);  if (inp->inp_flags & INP_HIGHPORT) optval = IP_PORTRANGE_HIGH; else if (inp->inp_flags & INP_LOWPORT) optval = IP_PORTRANGE_LOW; else optval = 0;  *mtod(m, int *) = optval; break;
ip_ctloutput(op, so, level, optname, mp)	int op;	struct socket *so;	int level, optname;	struct mbuf **mp;{	register struct inpcb *inp = sotoinpcb(so);	register struct mbuf *m = *mp;	register int optval = 0;	int error = 0;	if (level != IPPROTO_IP) {		error = EINVAL;		if (op == PRCO_SETOPT && *mp)			(void) m_free(*mp);	} else switch (op) {	case PRCO_SETOPT:		switch (optname) {		case IP_OPTIONS:#ifdef notyet		case IP_RETOPTS:			return (ip_pcbopts(optname, &inp->inp_options, m));#else			return (ip_pcbopts(&inp->inp_options, m));#endif		case IP_TOS:		case IP_TTL:		case IP_RECVOPTS:		case IP_RECVRETOPTS:		case IP_RECVDSTADDR:			if (m == NULL || m->m_len != sizeof(int))				error = EINVAL;			else {				optval = *mtod(m, int *);				switch (optname) {				case IP_TOS:					inp->inp_ip.ip_tos = optval;					break;				case IP_TTL:					inp->inp_ip.ip_ttl = optval;					break;#define	OPTSET(bit) \	if (optval) \		inp->inp_flags |= bit; \	else \		inp->inp_flags &= ~bit;				case IP_RECVOPTS:					OPTSET(INP_RECVOPTS);					break;				case IP_RECVRETOPTS:					OPTSET(INP_RECVRETOPTS);					break;				case IP_RECVDSTADDR:					OPTSET(INP_RECVDSTADDR);					break;				}			}			break;#undef OPTSET		case IP_MULTICAST_IF:		case IP_MULTICAST_TTL:		case IP_MULTICAST_LOOP:		case IP_ADD_MEMBERSHIP:		case IP_DROP_MEMBERSHIP:			error = ip_setmoptions(optname, &inp->inp_moptions, m);			break;		default:			error = ENOPROTOOPT;			break;		}		if (m)			(void)m_free(m);		break;	case PRCO_GETOPT:		switch (optname) {		case IP_OPTIONS:		case IP_RETOPTS:			*mp = m = m_get(M_WAIT, MT_SOOPTS);			if (inp->inp_options) {				m->m_len = inp->inp_options->m_len;				bcopy(mtod(inp->inp_options, caddr_t),				    mtod(m, caddr_t), (unsigned)m->m_len);			} else				m->m_len = 0;			break;		case IP_TOS:		case IP_TTL:		case IP_RECVOPTS:		case IP_RECVRETOPTS:		case IP_RECVDSTADDR:			*mp = m = m_get(M_WAIT, MT_SOOPTS);			m->m_len = sizeof(int);			switch (optname) {			case IP_TOS:				optval = inp->inp_ip.ip_tos;				break;			case IP_TTL:				optval = inp->inp_ip.ip_ttl;				break;#define	OPTBIT(bit)	(inp->inp_flags & bit ? 1 : 0)			case IP_RECVOPTS:				optval = OPTBIT(INP_RECVOPTS);				break;			case IP_RECVRETOPTS:				optval = OPTBIT(INP_RECVRETOPTS);				break;			case IP_RECVDSTADDR:				optval = OPTBIT(INP_RECVDSTADDR);				break;			}			*mtod(m, int *) = optval;			break;		case IP_MULTICAST_IF:		case IP_MULTICAST_TTL:		case IP_MULTICAST_LOOP:		case IP_ADD_MEMBERSHIP:		case IP_DROP_MEMBERSHIP:			error = ip_getmoptions(optname, inp->inp_moptions, mp);			break;		default:			error = ENOPROTOOPT;			break;		}		break;	}	return (error);}