pstat.2 (2010 09)

p
pstat(2) pstat(2)
Example 9B
Acquire protocol information of an XTI or a TLI TCP/UDP end-point. Build this example with the follow-
ing command:
cc -D_PSTAT_STREAM_GET_XPORT -o example9B example9B.c -lxti
#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) &&
HP-UX 11i Version 3: September 2010 23 Hewlett-Packard Company 23