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

  1. /* Socket status display code
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. #ifdef MSDOS
  5. #include <dos.h>
  6. #endif
  7. #include "global.h"
  8. #include "iface.h"
  9. #include "mbuf.h"
  10. #include "proc.h"
  11. #include "lzw.h"
  12. #include "usock.h"
  13. #include "socket.h"
  14. #include "ax25.h"
  15. #include "netrom.h"
  16. #include "tcp.h"
  17. #include "udp.h"
  18. #include "commands.h"
  19. #include "config.h"
  20.   
  21. /* Socket status display command */
  22. int
  23. dosock(argc,argv,p)
  24. int argc;
  25. char *argv[];
  26. void *p;
  27. {
  28.     register struct usock *up;
  29.     int s,i;
  30.     struct sockaddr fsock;
  31.     char *cp;
  32.   
  33.     if(argc < 2){
  34. #ifdef UNIX
  35.         tputs("S#  Type    PCB  Remote socket         Owner\n");
  36. #else
  37.         tputs("S#  Type    PCB  Remote socket         Owner\n");
  38. #endif
  39.         s = 0;
  40.         while((s=getnextsocket(s)) != -1) {
  41.             if((up=itop(s)) == NULLUSOCK)
  42.                 continue;
  43.             i = sizeof(fsock);
  44.             if(getpeername(s,(char *)&fsock,&i) == 0 && i != 0)
  45.                 cp = psocket(&fsock);
  46.             else
  47.                 cp = "";
  48.   
  49. #ifdef UNIX
  50.             tprintf("%3d %-8s%8.8x %-22s%8.8x %-10s\n",
  51. #else
  52.             tprintf("%3d %-8s%4.4x %-22s%4.4x %-10s\n",
  53. #endif
  54.             s,Socktypes[up->type],FP_SEG(up->cb.p),cp,
  55.             FP_SEG(up->owner),up->owner->name);
  56.         }
  57.         return 0;
  58.     }
  59.     s = atoi(argv[1]);
  60.     up = itop(s);
  61.     if(up == NULLUSOCK){
  62.         tputs("Socket not in use\n");
  63.         return 0;
  64.     }
  65. #ifdef UNIX
  66.     tprintf("%s %8.8x %s",Socktypes[up->type],FP_SEG(up->cb.p),
  67. #else
  68.     tprintf("%s %4.4x %s",Socktypes[up->type],FP_SEG(up->cb.p),
  69. #endif
  70.     up->flag == SOCK_ASCII ? "ascii" : "binary");
  71.     if(up->eol[0] != '\0'){
  72.         tputs(" eol seq:");
  73.         for(i=0;up->eol[i] != '\0' && i<sizeof(up->eol);i++)
  74.             tprintf(" %02x",up->eol[i]);
  75.     }
  76.     tprintf("  Refcnt: %d  Since: %s",up->refcnt,ctime(&up->created));
  77.     if(up->cb.p == NULL)
  78.         return 0;
  79.     switch(up->type){
  80.         case TYPE_RAW:
  81.         case TYPE_LOCAL_DGRAM:
  82.             tprintf("Inqlen: %d packets\n",socklen(s,0));
  83.             tprintf("Outqlen: %d packets\n",socklen(s,1));
  84.             break;
  85.         case TYPE_LOCAL_STREAM:
  86.             tprintf("Inqlen: %d bytes\n",socklen(s,0));
  87.             tprintf("Outqlen: %d bytes\n",socklen(s,1));
  88.             break;
  89.         case TYPE_TCP:
  90.             st_tcp(up->cb.tcb);
  91.             break;
  92.         case TYPE_UDP:
  93.             st_udp(up->cb.udp,0);
  94.             break;
  95. #ifdef  AX25
  96.         case TYPE_AX25I:
  97.             st_ax25(up->cb.ax25);
  98.             break;
  99. #endif
  100. #ifdef  NETROM
  101.         case TYPE_NETROML4:
  102.             donrdump(up->cb.nr4);
  103.             break;
  104. #endif
  105.     }
  106. #ifdef LZW
  107.     if(up->zout != NULLLZW)
  108.         tprintf("Compressed %ld bytes.\n",up->zout->cnt);
  109.     if(up->zin != NULLLZW)
  110.         tprintf("Decompressed %ld bytes.\n",up->zin->cnt);
  111. #endif
  112.     return 0;
  113. }
  114.   
  115. /* Kick the session related to a particular socket
  116.  * this is easier then the tcp kick, ax25 kick, etc... commands
  117.  * 920117 - WG7J
  118.  */
  119. int
  120. dokicksocket(argc,argv,p)
  121. int argc;
  122. char *argv[];
  123. void *p;
  124. {
  125.     register struct usock *up;
  126.     int s;  /*socket to kick*/
  127.     int retval=0;
  128.   
  129.     s = atoi(argv[1]);
  130.     up = itop(s);
  131.     if(up == NULLUSOCK){
  132.         tputs("Socket not in use\n");
  133.         return 0;
  134.     }
  135.     if(up->type == TYPE_TCP)
  136.         retval = kick_tcp(up->cb.tcb);
  137. #ifdef AX25
  138.     if(up->type == TYPE_AX25I)
  139.         retval = kick_ax25(up->cb.ax25);
  140. #endif
  141. #ifdef NETROM
  142.     if(up->type == TYPE_NETROML4)
  143.         retval = kick_nr4(up->cb.nr4);
  144. #endif
  145.     if(retval == -1)
  146.         tputs("Kick not successfull\n");
  147.     return 0;
  148. }
  149.   
  150.   
  151.