BSD syscall#31
svc · unix #31
getpeername
Returns the address of the peer connected to a socket.
Prototype
int getpeername(int fdes, caddr_t asa, socklen_t *alen);Returns: int
Arguments
| Name | Type | Dir | Description |
|---|---|---|---|
| fdes | int | - | |
| asa | caddr_t | - | |
| alen | socklen_t | - |
Version history
| XNU tag | macOS | # |
|---|---|---|
| xnu-1456.1.26 | macOS 10.6 Snow Leopard | 31 |
| xnu-1486.2.11 | — | 31 |
| xnu-1504.15.3 | — | 31 |
| xnu-1504.3.12 | — | 31 |
| xnu-1504.7.4 | — | 31 |
| xnu-1504.9.17 | — | 31 |
| xnu-1504.9.26 | — | 31 |
| xnu-1504.9.37 | — | 31 |
Notes
Returns ENOTCONN for sockets that never completed connect/accept. For AF_UNIX sockets created with socketpair the peer has no name and the returned sockaddr_un has length sizeof(sa_family_t). Useful for SCM_CREDS-style identity checks; combine with getsockopt LOCAL_PEERCRED or LOCAL_PEERPID for the macOS-specific peer credential APIs.
Detection
Not directly observable via ES. The same information is available through proc_pidfdinfo to a privileged observer.
Related APIs
getsocknameacceptconnectgetsockopt