PSTAT Interfaces

23
Description:
This call returns detailed information specific to a socket. For the specified socket, there
is one instance of this context. For each call, data up to a maximum of elemsize bytes are
returned in the struct pst_socket pointed to by buf. The fid parameter uniquely identifies the
socket. This fid is obtained from calls to pstat_getfile2(). Use of this call is limited to UID == 0
or effective UID match. Please refer to pstat_getfiledetails() call for more information on
effective UID match.
For AF_UNIX sockets that are opened to files, more information about those files can be
obtained with the pstat_getfiledetails() call. In case of AF_UNIX sockets, pst_peer_hi_nodeid and
pst_peer_lo_nodeid fields can be used to find the peer socket by matching them with
pst_hi_nodeid and pst_lo_nodeid. The members pst_boundaddr and pst_remaddr contain data of
the form struct sockaddr, sockaddr_un, sockaddr_in, or sockaddr_in6 depending on the socket
family. These need to be copied to the structure they represent using pst_boundaddr_len and
pst_remaddr_len to assure proper structure alignment.
Return value:
On success, the call returns 1. On failure, value of -1 is returned and errno is set
indicating the cause of the failure.
Errors:
EINVAL is set if the user's size declaration isn't valid.
EACESS is set if no effective ID match.
EFAULT is set if buf points to an invalid address.
EINVAL is set if the file is not a socket.
ENOENT is set if the specified socket is not found or is being closed.
ESRCH is set if the required process is not found.
Example:
#include <sys/pstat.h>
#include <socket.h>
void main(void)
{
struct pst_fileinfo2 psf;
struct pst_socket psfsocket;
int rv, count, fd;
fd = socket(AF_INET, SOCK_STREAM, 0);
rv = pstat_getfile2(&psf, sizeof(psf), 0, fd, getpid());
if ((rv == 1) && (psf.psf_type == PS_TYPE_SOCKET)){
count = pstat_getsocket(psfsocket, sizeof(struct pst_socket),
&(psf.psf_fid));
if (count == 1) {
if ((psfsocket.pst_hi_fileid == psf.psf_hi_fileid) &&
(psfsocket.pst_lo_fileid == psf.psf_lo_fileid) &&
(psfsocket.pst_hi_nodeid == psf.psf_hi_nodeid) &&
(psfsocket.pst_lo_nodeid == psf.psf_lo_nodeid)) {
printf("The type of socket is %d, should be %d\n",
psfsocket.pst_type, PS_SOCK_STREAM);
} else {
printf("State changed\n");
}
} else {