#include <sys/types.h>
#include <sys/stream.h>
#include <sys/tihdr.h>
#include <stropts.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>

#define OLDSIZE (sizeof(struct T_info_ack) - sizeof(long))

char *errmsg = "tisz: Incorrect Response from transport provider";
void fatal(char *);

void 
main(int argc, char *argv[])
{
  int fd, ret, flag = RS_HIPRI;
  struct strbuf ctl;
  struct T_info_ack ack;
  struct T_info_req req;
  
  if (argc != 2)
    fatal("usage: tisz device");
  if ((fd = open (argv[1], O_RDWR))<0)
    fatal("tisz: can't open transport provider");
  
  ctl.buf= (char *)&req;
  ctl.len = sizeof(struct T_info_req);
  req.PRIM_type = T_INFO_REQ;
  if (putmsg(fd, &ctl, NULL, RS_HIPRI)<0)
    fatal ("tisz: Can't send reques");
  
  ctl.buf = (char *)&ack;
  ctl.maxlen = sizeof(struct T_info_ack);
  if ((ret = getmsg(fd, &ctl, NULL, &flag)) != 0) {
    if (ret <0)
      fatal("tisz: can't receive response");
    else
      fatal(errmsg);
  }
  if (((ctl.len != sizeof(struct T_info_ack)) &&
       (ctl.len != OLDSIZE)) ||
      (ack.PRIM_type != T_INFO_ACK))
    fatal(errmsg);
  printf("TIDU size = %d bytes \n", ack.TIDU_size);
  printf("TSDU size = %d bytes \n", ack.TSDU_size);
  exit(0);
}

void fatal(char *msg)
{
  perror(msg);
  exit(1);
}

