HP-UX Reference (11i v2 07/12) - 2 System Calls (vol 5)
p
pstat(2) pstat(2)
*/
#include <stdio.h>
#include <sys/param.h>
#include <sys/pstat.h>
#include <sys/unistd.h>
#include <sys/xti.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <stdlib.h>
main()
{
struct pst_fileinfo2 psf;
struct pst_stream *psfstream;
int rv, count, fd, entt_cnt, i;
fd = t_open("/dev/tcp", O_RDWR, NULL);
if(fd<0){
t_error("t_open() failed /dev/tcp");
exit(-1);
};
rv = t_bind(fd, NULL, NULL);
if(rv<0){
t_error("t_bind() failed on the fd");
exit(-1);
};
rv = pstat_getfile2(&psf, sizeof(psf), 0, fd, getpid());
if (rv == 1) {
entt_cnt = psf.psf_nstrentt;
psfstream = (struct pst_stream *)malloc(entt_cnt *
sizeof(struct pst_stream));
if (!psfstream) {
perror("malloc failed");
}
/*
* Get Transport protocol information for this stream.
*/
count = pstat_getstream(psfstream, sizeof(struct pst_stream),
entt_cnt, 0, &(psf.psf_fid));
if (count > 0) {
for (i = 0; i < entt_cnt; i++) {
if (psfstream[i].type != PS_STR_HEAD)
continue;
break;
}
if (i >= entt_cnt) {
perror("No STREAM Head");
return(1);
}
if ((psfstream[i].val.head.pst_hi_fileid ==
psf.psf_hi_fileid) &&
(psfstream[i].val.head.pst_lo_fileid ==
psf.psf_lo_fileid) &&
(psfstream[i].val.head.pst_hi_nodeid ==
psf.psf_hi_nodeid) &&
(psfstream[i].val.head.pst_lo_nodeid ==
HP-UX 11i Version 2: December 2007 Update − 16 − Hewlett-Packard Company 289