home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 024 / psi110g.zip / BPQCMD.C < prev    next >
C/C++ Source or Header  |  1994-04-17  |  8KB  |  291 lines

  1. /* code to allow nos to talk directly to bpqcode
  2.  *
  3.  * by paul h launspach n5faz
  4.  * (c) 1993,1994 FazCom
  5.  * 4-13-93
  6.  */
  7. /* $Id: bpqcmd.c 1.4 1994/03/11 15:25:06 fz-phl Exp $ */
  8. /* $Log: bpqcmd.c $
  9.  * Revision 1.4  1994/03/11  15:25:06  fz-phl
  10.  * added ifdef BPQJNOS for printf -> tprintf macro and
  11.  * changed display of ifp-rawsndcnt to a %lu in dobpqstat.
  12.  *
  13.  * Revision 1.3  1994/03/11  15:13:45  Johan
  14.  * changed printf's to tprintf's
  15.  *
  16.  * Revision 1.2  1994/03/11  15:04:33  fz-phl
  17.  * added ifdef BPQSOCK and other stuff for jnos.
  18.  *
  19.  * Revision 1.1  1994/03/11  02:25:10  fz-phl
  20.  * Initial revision
  21.  *
  22.  */
  23. #include "global.h"
  24. #include "config.h"
  25. #ifdef BPQ
  26. #include "cmdparse.h"
  27. #include "socket.h"
  28. #include "session.h"
  29. #include "usock.h"
  30. #include "bpq.h"
  31.   
  32. #ifdef BPQJNOS          /* change printf to tprintf for jnos etc */
  33. #define printf tprintf
  34. #endif
  35.   
  36. #ifdef BPQSOCK
  37. static int dobpqstat (int,char *argv[],void *);
  38. static int dobpqconn (int,char *argv[],void *);
  39. static int dobpqreset (int,char *argv[],void *);
  40. static int dobpqwindow (int,char *argv[],void *);
  41. #endif
  42.   
  43. char *Bpqstates[] = {
  44.     "Disconn",
  45.     "Connect",
  46.     "Listen",
  47.     "Lis>Con"
  48. };
  49.   
  50. char *Bpqreasons[] = {
  51.     "Normal",
  52.     "By Peer",
  53.     "Timeout",
  54.     "Reset",
  55.     "Refused"
  56. } ;
  57.   
  58. #ifdef BPQSOCK
  59. static struct cmds Bpqcmds[] = {
  60.     "connect",      dobpqconn,  1024, 0, NULLCHAR,
  61.     "reset",        dobpqreset, 0, 2, "bpq reset <bpqcb>",
  62.     "stat",         dobpqstat,  0, 0, NULLCHAR,
  63.     "window",       dobpqwindow, 0, 1, "bpq window <frames>",
  64.     NULLCHAR,
  65. };
  66.   
  67. /* Multiplexer for top-level bpq command */
  68. int
  69. dobpq(argc,argv,p)
  70. int argc;
  71. char *argv[];
  72. void *p;
  73. {
  74.     if(argc < 2)
  75.         return dobpqstat(argc,argv,p);
  76.     return subcmd(Bpqcmds,argc,argv,p);
  77. }
  78. #endif */ BPQSOCK */
  79.   
  80. /* display bpq info stats */
  81. #ifdef BPQSOCK
  82. static
  83. #endif
  84. int
  85. dobpqstat(argc,argv,p)
  86. int argc;
  87. char *argv[];
  88. void *p;
  89. {
  90.     int i;
  91.     struct iface *ifp;
  92. #ifdef BPQSOCK
  93.     struct bpq_cb *cb;
  94. #endif
  95.     char buf[11];
  96.   
  97.     if(!Bpqinfo.vec){
  98.         printf("Bpq must be initialized with: attach bpq init <vec> <stream>\n");
  99.         return 1;
  100.     }
  101.   
  102.     printf("Vec Stream Ports Window Conn: Tot Max Curr Next\n");
  103.     printf(" %2x     %2u    %2u     %2u       %3u %3u  %3u  %3u\n",
  104.     Bpqinfo.vec,Bpqinfo.monstream,Bpqinfo.maxport,Bpqinfo.window,
  105.     Bpqinfo.maxstream-Bpqinfo.monstream + 1,
  106.     Bpqinfo.maxconn,Bpqinfo.curr,Bpqinfo.nextconn+1);
  107.   
  108.     printf("Recvd  Sent    Rx    Tx   Rxint   Txint  Ctlint Free Min\n");
  109.     printf("%5lu %5lu %5lu %5lu %7lu %7lu %7lu",
  110.     Bpqinfo.recv,Bpqinfo.send,Bpqinfo.recvcnt,
  111.     Bpqinfo.sendcnt,Bpqinfo.rxcnt,Bpqinfo.txcnt,
  112.     Bpqinfo.contcnt);
  113.     i = bpq_int(BPQ_BUF,1,0,NULLCHAR);
  114.     Bpqinfo.minfree = min(i,Bpqinfo.minfree);
  115.     printf("  %3u %3u\n",i,Bpqinfo.minfree);
  116.   
  117.     /* print any iface info */
  118.     if(Bpqinfo.maxport){
  119.         printf("\nPort Lable      Call      IP-Address      Mtu    Rx    Tx\n");
  120.         for(i=0; i < BPQMAXPORT ; i++)
  121.             if((ifp = Bpqinfo.ports[i]) != NULLIF)
  122.                 printf("%4u %-10.10s %-9.9s %-15.15s %3u %5lu %5lu\n",ifp->dev,
  123.                 ifp->name,pax25(buf,ifp->hwaddr),inet_ntoa(ifp->addr),
  124.                 ifp->mtu,ifp->rawrecvcnt,ifp->rawsndcnt);
  125.     }
  126.   
  127.     /* print any connection status */
  128. #ifdef BPQSOCK
  129.     if(Bpqinfo.cb != NULLBPQ){
  130.         printf("\n&BPQCB   Owner            Sock St Num Recv Sent  Rxq  Txq Appl Tot Curr\n");
  131.         for(cb = Bpqinfo.cb; cb != NULLBPQ ; cb = cb->next)
  132.             st_bpq_cb(cb);
  133.     }
  134. #endif
  135.     /* print the all stream status */
  136.     /* whether we are using it or something else is */
  137.     printf("\n St Num State       Type/Pt User      Recv Unak Maxf Pacl\n");
  138.     for(i=1; i <= BPQMAXSTREAM ; i++)
  139.         st_bpq(i);
  140.   
  141.     return 0;
  142. }
  143.   
  144. #ifdef BPQSOCK
  145. void
  146. st_bpq_cb(cb)
  147. struct bpq_cb *cb;
  148. {
  149.     struct usock *up;
  150.   
  151.     up = itop(cb->user);
  152.     printf("%-8lx %-16.16s %4u %2u %3u %4u %4u %4u %4u",
  153.     ptol(cb),up->owner->name,cb->user,cb->stream,cb->conn,
  154.     cb->recv,cb->send,len_p(cb->rxq),len_q(cb->txq));
  155.     if(cb->serv != NULLBPQS)
  156.         if(cb->state == BPQ_ST_LIS)
  157.             printf("   %2u %3u  %3u",cb->serv->appl,
  158.             cb->serv->users,cb->serv->curr);
  159.         else
  160.             printf("           %3u",cb->sconn);
  161.     printf("\n");
  162. }
  163. #endif
  164.   
  165. void
  166. st_bpq(i)
  167. int i;
  168. {
  169. #ifdef BPQSOCK
  170.     struct bpq_cb *cb;
  171. #endif
  172.     char buf[11];
  173.     uint16 st;
  174.     uint16 tp;
  175.   
  176.         /* dont ack the state call. we want who ever is */
  177.         /* really using this stream to see any state changes  */
  178.         /* only display  active streams */
  179.   
  180. #ifdef BPQSOCK
  181.     cb = find_bpq(i);
  182.     st = bpq_int(BPQ_STATE,i,0,NULLCHAR);
  183.     if(!st && cb == NULLBPQ && i != Bpqinfo.monstream)
  184.         return;
  185. #else
  186.     if(!(st = bpq_int(BPQ_STATE,i,0,NULLCHAR)) && i != Bpqinfo.monstream)
  187.         return;
  188. #endif
  189.   
  190. #ifdef BPQSOCK
  191.     if(cb != NULLBPQ){
  192.         st |= cb->state;
  193.         printf("%s%2u %3u",i == Bpqinfo.monstream ? "*" : " ",
  194.         cb->stream,cb->conn);
  195.     } else
  196. #endif
  197.         printf("%s%2u    ",i == Bpqinfo.monstream ? "*" : " ",i);
  198.   
  199.     printf(" %-7s%s",Bpqstates[st & ~BPQ_ST_CHG],
  200.     st & BPQ_ST_CHG ? "+" : " ");
  201.   
  202.     if(st & BPQ_ST_CON){
  203.         tp = bpq_int(BPQ_USERCALL,i,0,buf);
  204.         if(tp & BPQ_HOST)
  205.             printf("    Host");
  206.         else if(tp & BPQ_SESSION)
  207.             printf(" Circuit");
  208.         else if(tp & BPQ_UPLINK)
  209.             printf("  Uplink");
  210.         else if(tp & BPQ_DOWNLK)
  211.             printf(" Downlnk");
  212.         else if(tp)
  213.             printf(" Unk: %2u");
  214.         else printf("        ");
  215.         if(tp & BPQ_L2)
  216.             printf(" %2u",lobyte(tp));
  217.         else printf("   ");
  218. #ifdef BPQSOCK
  219.         if(cb != NULLBPQ)
  220.             printf(" %9.9s  %3u  %3u  %3u  %3u",buf,
  221.             bpq_int(BPQ_RECVQUE,i,0,NULLCHAR),cb->unack,
  222.             cb->maxframe,cb->paclen);
  223.         else
  224. #endif
  225.             printf(" %9.9s  %3u  %3u  %3u  %3u",buf,
  226.             bpq_int(BPQ_RECVQUE,i,0,NULLCHAR),
  227.             bpq_int(BPQ_UNACK,i,0,NULLCHAR),
  228.             bpq_int(BPQ_MAXFR,i,0,buf),
  229.             bpq_int(BPQ_PACLEN,i,0,buf));
  230.     }
  231.     printf("\n");
  232. }
  233.   
  234. #ifdef BPQSOCK
  235. static int
  236. dobpqconn(argc,argv,p)
  237. int argc;
  238. char *argv[];
  239. void *p;
  240. {
  241.     struct sockaddr_bq fsocket;
  242.     struct session *sp;
  243.     int s;
  244.   
  245.     if((sp = newsession(Cmdline,BPQSESSION,1)) == NULLSESSION){
  246.         printf("Too many sessions\n");
  247.         return 1;
  248.     }
  249.     if((s = socket(AF_BPQ,SOCK_STREAM,0)) == -1){
  250.         printf("Can't create socket\n");
  251.         freesession(sp);
  252.         keywait(NULLCHAR,1);
  253.         return 1;
  254.     }
  255.     fsocket.bpq_family = AF_BPQ;
  256.     memcpy(fsocket.bpq_addr,"SWITCH   \0",AXBUF);
  257.     sp->network = fdopen(s,"r+t");
  258.     setvbuf(sp->network,NULLCHAR,_IOLBF,BUFSIZ);
  259.     return tel_connect(sp, (char *)&fsocket, sizeof(struct sockaddr_bq));
  260. }
  261.   
  262. static int
  263. dobpqreset(argc,argv,p)
  264. int argc;
  265. char *argv[];
  266. void *p;
  267. {
  268.     struct bpq_cb *cb;
  269.   
  270.     cb = (struct bpq_cb *)ltop(htol(argv[1]));
  271.     if(!bpqval(cb)){
  272.         printf(Notval);
  273.         return 1;
  274.     }
  275.     disc_bpq(cb,1);
  276.     return 0;
  277. }
  278.   
  279. static int
  280. dobpqwindow(argc,argv,p)
  281. int argc;
  282. char *argv[];
  283. void *p;
  284. {
  285.     return setshort(&Bpqinfo.window,"Bpq window (frames)",argc,argv);
  286. }
  287. #endif /* BPQSOCK */
  288.   
  289. #endif /* BPQ */
  290.   
  291.