| 1377 | } |
| 1378 | |
| 1379 | int |
| 1380 | kern_getsockname(struct thread *td, int fd, struct sockaddr **sa, |
| 1381 | socklen_t *alen) |
| 1382 | { |
| 1383 | struct socket *so; |
| 1384 | struct file *fp; |
| 1385 | socklen_t len; |
| 1386 | int error; |
| 1387 | |
| 1388 | AUDIT_ARG_FD(fd); |
| 1389 | error = getsock_cap(td, fd, &cap_getsockname_rights, |
| 1390 | &fp, NULL, NULL); |
| 1391 | if (error != 0) |
| 1392 | return (error); |
| 1393 | so = fp->f_data; |
| 1394 | *sa = NULL; |
| 1395 | CURVNET_SET(so->so_vnet); |
| 1396 | error = (*so->so_proto->pr_usrreqs->pru_sockaddr)(so, sa); |
| 1397 | CURVNET_RESTORE(); |
| 1398 | if (error != 0) |
| 1399 | goto bad; |
| 1400 | if (*sa == NULL) |
| 1401 | len = 0; |
| 1402 | else |
| 1403 | len = MIN(*alen, (*sa)->sa_len); |
| 1404 | *alen = len; |
| 1405 | #ifdef KTRACE |
| 1406 | if (KTRPOINT(td, KTR_STRUCT)) |
| 1407 | ktrsockaddr(*sa); |
| 1408 | #endif |
| 1409 | bad: |
| 1410 | fdrop(fp, td); |
| 1411 | if (error != 0 && *sa != NULL) { |
| 1412 | free(*sa, M_SONAME); |
| 1413 | *sa = NULL; |
| 1414 | } |
| 1415 | return (error); |
| 1416 | } |
| 1417 | |
| 1418 | int |
| 1419 | sys_getsockname(struct thread *td, struct getsockname_args *uap) |
no test coverage detected