| 995 | } |
| 996 | |
| 997 | static int |
| 998 | uipc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam, |
| 999 | struct mbuf *control, struct thread *td) |
| 1000 | { |
| 1001 | struct unpcb *unp, *unp2; |
| 1002 | struct socket *so2; |
| 1003 | u_int mbcnt, sbcc; |
| 1004 | int freed, error; |
| 1005 | |
| 1006 | unp = sotounpcb(so); |
| 1007 | KASSERT(unp != NULL, ("%s: unp == NULL", __func__)); |
| 1008 | KASSERT(so->so_type == SOCK_STREAM || so->so_type == SOCK_DGRAM || |
| 1009 | so->so_type == SOCK_SEQPACKET, |
| 1010 | ("%s: socktype %d", __func__, so->so_type)); |
| 1011 | |
| 1012 | freed = error = 0; |
| 1013 | if (flags & PRUS_OOB) { |
| 1014 | error = EOPNOTSUPP; |
| 1015 | goto release; |
| 1016 | } |
| 1017 | if (control != NULL && (error = unp_internalize(&control, td))) |
| 1018 | goto release; |
| 1019 | |
| 1020 | unp2 = NULL; |
| 1021 | switch (so->so_type) { |
| 1022 | case SOCK_DGRAM: |
| 1023 | { |
| 1024 | const struct sockaddr *from; |
| 1025 | |
| 1026 | if (nam != NULL) { |
| 1027 | error = unp_connect(so, nam, td); |
| 1028 | if (error != 0) |
| 1029 | break; |
| 1030 | } |
| 1031 | UNP_PCB_LOCK(unp); |
| 1032 | |
| 1033 | /* |
| 1034 | * Because connect() and send() are non-atomic in a sendto() |
| 1035 | * with a target address, it's possible that the socket will |
| 1036 | * have disconnected before the send() can run. In that case |
| 1037 | * return the slightly counter-intuitive but otherwise |
| 1038 | * correct error that the socket is not connected. |
| 1039 | */ |
| 1040 | unp2 = unp_pcb_lock_peer(unp); |
| 1041 | if (unp2 == NULL) { |
| 1042 | UNP_PCB_UNLOCK(unp); |
| 1043 | error = ENOTCONN; |
| 1044 | break; |
| 1045 | } |
| 1046 | |
| 1047 | if (unp2->unp_flags & UNP_WANTCRED_MASK) |
| 1048 | control = unp_addsockcred(td, control, |
| 1049 | unp2->unp_flags); |
| 1050 | if (unp->unp_addr != NULL) |
| 1051 | from = (struct sockaddr *)unp->unp_addr; |
| 1052 | else |
| 1053 | from = &sun_noname; |
| 1054 | so2 = unp2->unp_socket; |
nothing calls this directly
no test coverage detected