| 1463 | } |
| 1464 | |
| 1465 | int |
| 1466 | kern_getpeername(struct thread *td, int fd, struct sockaddr **sa, |
| 1467 | socklen_t *alen) |
| 1468 | { |
| 1469 | struct socket *so; |
| 1470 | struct file *fp; |
| 1471 | socklen_t len; |
| 1472 | int error; |
| 1473 | |
| 1474 | AUDIT_ARG_FD(fd); |
| 1475 | error = getsock_cap(td, fd, &cap_getpeername_rights, |
| 1476 | &fp, NULL, NULL); |
| 1477 | if (error != 0) |
| 1478 | return (error); |
| 1479 | so = fp->f_data; |
| 1480 | if ((so->so_state & (SS_ISCONNECTED|SS_ISCONFIRMING)) == 0) { |
| 1481 | error = ENOTCONN; |
| 1482 | goto done; |
| 1483 | } |
| 1484 | *sa = NULL; |
| 1485 | CURVNET_SET(so->so_vnet); |
| 1486 | error = (*so->so_proto->pr_usrreqs->pru_peeraddr)(so, sa); |
| 1487 | CURVNET_RESTORE(); |
| 1488 | if (error != 0) |
| 1489 | goto bad; |
| 1490 | if (*sa == NULL) |
| 1491 | len = 0; |
| 1492 | else |
| 1493 | len = MIN(*alen, (*sa)->sa_len); |
| 1494 | *alen = len; |
| 1495 | #ifdef KTRACE |
| 1496 | if (KTRPOINT(td, KTR_STRUCT)) |
| 1497 | ktrsockaddr(*sa); |
| 1498 | #endif |
| 1499 | bad: |
| 1500 | if (error != 0 && *sa != NULL) { |
| 1501 | free(*sa, M_SONAME); |
| 1502 | *sa = NULL; |
| 1503 | } |
| 1504 | done: |
| 1505 | fdrop(fp, td); |
| 1506 | return (error); |
| 1507 | } |
| 1508 | |
| 1509 | int |
| 1510 | sys_getpeername(struct thread *td, struct getpeername_args *uap) |
no test coverage detected