| 734 | } |
| 735 | |
| 736 | int |
| 737 | kern_sendit(struct thread *td, int s, struct msghdr *mp, int flags, |
| 738 | struct mbuf *control, enum uio_seg segflg) |
| 739 | { |
| 740 | struct file *fp; |
| 741 | struct uio auio; |
| 742 | struct iovec *iov; |
| 743 | struct socket *so; |
| 744 | cap_rights_t *rights; |
| 745 | #ifdef KTRACE |
| 746 | struct uio *ktruio = NULL; |
| 747 | #endif |
| 748 | ssize_t len; |
| 749 | int i, error; |
| 750 | |
| 751 | AUDIT_ARG_FD(s); |
| 752 | rights = &cap_send_rights; |
| 753 | if (mp->msg_name != NULL) { |
| 754 | AUDIT_ARG_SOCKADDR(td, AT_FDCWD, mp->msg_name); |
| 755 | rights = &cap_send_connect_rights; |
| 756 | } |
| 757 | error = getsock_cap(td, s, rights, &fp, NULL, NULL); |
| 758 | if (error != 0) { |
| 759 | m_freem(control); |
| 760 | return (error); |
| 761 | } |
| 762 | so = (struct socket *)fp->f_data; |
| 763 | |
| 764 | #ifdef KTRACE |
| 765 | if (mp->msg_name != NULL && KTRPOINT(td, KTR_STRUCT)) |
| 766 | ktrsockaddr(mp->msg_name); |
| 767 | #endif |
| 768 | #ifdef MAC |
| 769 | if (mp->msg_name != NULL) { |
| 770 | error = mac_socket_check_connect(td->td_ucred, so, |
| 771 | mp->msg_name); |
| 772 | if (error != 0) { |
| 773 | m_freem(control); |
| 774 | goto bad; |
| 775 | } |
| 776 | } |
| 777 | error = mac_socket_check_send(td->td_ucred, so); |
| 778 | if (error != 0) { |
| 779 | m_freem(control); |
| 780 | goto bad; |
| 781 | } |
| 782 | #endif |
| 783 | |
| 784 | auio.uio_iov = mp->msg_iov; |
| 785 | auio.uio_iovcnt = mp->msg_iovlen; |
| 786 | auio.uio_segflg = segflg; |
| 787 | auio.uio_rw = UIO_WRITE; |
| 788 | auio.uio_td = td; |
| 789 | auio.uio_offset = 0; /* XXX */ |
| 790 | auio.uio_resid = 0; |
| 791 | iov = mp->msg_iov; |
| 792 | for (i = 0; i < mp->msg_iovlen; i++, iov++) { |
| 793 | if ((auio.uio_resid += iov->iov_len) < 0) { |
no test coverage detected