Sample code
#include <sys/types.h>
#include <sys/qnxterm.h>
#include <sys/vc.h>
#include <sys/psinfo.h>
#include <sys/kernel.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h>
#include <signal.h>
#define MAX_NET 4
#define N_ATTR TERM_NORMAL|TERM_FLUSH|TERM_WHITE|TERM_BLUE_BG
#define ERR_ATTR TERM_NORMAL|TERM_FLUSH|TERM_WHITE|TERM_RED_BG
void sigAlrm (int s_num) {
s_num = s_num;
}
static timer_t idt;
static int pr_idt;
static struct itimerspec timer;
short diaginfo (nid_t node,short net, short *buf) {
short c,p;
pid_t pid;
if (pr_idt==0) {
if ((idt=timer_create (CLOCK_REALTIME,NULL))==-1)
return (8);
pr_idt++;
// qnx_pflags (~0L,_PPF_SIGCATCH,NULL,NULL);
signal( SIGALRM, sigAlrm );
timer.it_value.tv_sec = 0L;
timer.it_value.tv_nsec = 0L;
timer.it_interval.tv_sec = 0L;
timer.it_interval.tv_nsec = 0L;
}
timer.it_value.tv_sec = 1L;
timer_settime (idt,0,&timer,NULL);
pid=qnx_vc_name_attach (node,100,“qnx/net”);
timer.it_value.tv_sec = 0L;
timer_settime (idt,0,&timer,NULL);
if (pid==-1)
return (1);
buf[0] = 0x438;
timer.it_value.tv_sec = 1L;
timer_settime (idt,0,&timer,NULL);
p = Send (pid,(void far *)buf,(void far *)buf,2,8+12*MAX_NET);
timer.it_value.tv_sec = 0L;
timer_settime (idt,0,&timer,NULL);
qnx_vc_detach (pid);
if (p)
return (2);
if (buf[0])
return (3);
for (c=0; c<buf[2]; c++)
if (buf[4+c*6]==net) {
pid = buf[4+c*6+4];
timer.it_value.tv_sec = 1L;
timer_settime (idt,0,&timer,NULL);
pid=qnx_vc_attach (node,pid,512,0);
timer.it_value.tv_sec = 0L;
timer_settime (idt,0,&timer,NULL);
if (pid==-1)
return (4);
buf[0] = 0x477;
timer.it_value.tv_sec = 1L;
timer_settime (idt,0,&timer,NULL);
p = Send (pid,(void far *)buf,(void far *)buf,2,32);
timer.it_value.tv_sec = 0L;
timer_settime (idt,0,&timer,NULL);
qnx_vc_detach (pid);
if (p)
return (5);
if (buf[0])
return (6);
return (0);
}
return (7);
}
int main (int argc, char *argv[]) {
short i,j,k,km,max_node,buf[75],i1;
if (argc<2) {
printf ("Use diaginfo <max_nodes>\n");
return (1);
}
max_node = atoi (argv[1]);
if (max_node<1 || max_node>31)
max_node = 31;
if (term_load ()) {
printf ("_иÐ