home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR3 / KA9Q212.ZIP / SOCKCMD.C < prev    next >
C/C++ Source or Header  |  1993-07-16  |  3KB  |  111 lines

  1. /* Socket status display code
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4.  
  5. /****************************************************************************
  6. *    $Id: sockcmd.c 1.2 93/07/16 11:50:44 ROOT_DOS Exp $
  7. *    13 Jul 93    1.2        GT    LZW conditional.                                *
  8. ****************************************************************************/
  9.  
  10. #include <stdio.h>
  11. #include "global.h"
  12. #include "mbuf.h"
  13. #include "proc.h"
  14. #include "lzw.h"
  15. #include "usock.h"
  16. #include "socket.h"
  17. #include "ax25.h"
  18. #include "netrom.h"
  19. #include "tcp.h"
  20. #include "udp.h"
  21. #include "commands.h"
  22. #include "config.h"
  23.  
  24. /* Socket status display command */
  25. int
  26. dosock(argc,argv,p)
  27. int argc;
  28. char *argv[];
  29. void *p;
  30. {
  31.     register struct usock *up;
  32.     int s,i;
  33.     struct sockaddr fsock;
  34.     char *cp;
  35.  
  36.     if(argc < 2){
  37.         tprintf("S#  Type    PCB      Remote socket         Owner\n");
  38.         for(s=SOCKBASE;s<Nusock+SOCKBASE;s++){
  39.             up = itop(s);
  40.             if(up == NULLUSOCK)
  41.                 continue;
  42.  
  43.             i = sizeof(fsock);
  44.             if(getpeername(s,(char *)&fsock,&i) == 0 && i != 0)
  45.                 cp = psocket(&fsock);
  46.             else
  47.                 cp = "";
  48.  
  49.             tprintf("%3d %-8s%-8lx %-22s%-8lx %-10s\n",
  50.              s,Socktypes[up->type],ptol(up->cb.p),cp,
  51.              ptol(up->owner),up->owner->name);
  52.         }
  53.         return 0;
  54.     }
  55.     s = atoi(argv[1]);
  56.     if(s < SOCKBASE || s >= Nusock+SOCKBASE){
  57.         tprintf("Number out of range\n");
  58.         return 1;
  59.     }
  60.     up = itop(s);
  61.     if(up == NULLUSOCK){
  62.         tprintf("Socket not in use\n");
  63.         return 0;
  64.     }
  65.     tprintf("%s %lx %s",Socktypes[up->type],ptol(up->cb.p),
  66.      up->flag == SOCK_ASCII ? "ascii" : "binary");
  67.     if(up->eol[0] != '\0'){
  68.         tprintf(" eol seq:");
  69.         for(i=0;up->eol[i] != '\0' && i<sizeof(up->eol);i++)
  70.             tprintf(" %02x",up->eol[i]);
  71.     }
  72.     tprintf("\n");
  73.     if(up->cb.p == NULL)
  74.         return 0;
  75.     switch(up->type){
  76.     case TYPE_RAW:
  77.     case TYPE_LOCAL_DGRAM:
  78.         tprintf("Inqlen: %d packets\n",socklen(s,0));
  79.         tprintf("Outqlen: %d packets\n",socklen(s,1));
  80.         break;
  81.     case TYPE_LOCAL_STREAM:
  82.         tprintf("Inqlen: %d bytes\n",socklen(s,0));
  83.         tprintf("Outqlen: %d bytes\n",socklen(s,1));
  84.         break;
  85.     case TYPE_TCP:
  86.         st_tcp(up->cb.tcb);
  87.         break;
  88.     case TYPE_UDP:
  89.         st_udp(up->cb.udp,0);
  90.         break;
  91. #ifdef    AX25
  92.     case TYPE_AX25I:
  93.         st_ax25(up->cb.ax25);
  94.         break;
  95. #endif
  96. #ifdef    NETROM
  97.     case TYPE_NETROML4:
  98.         donrdump(up->cb.nr4);
  99.         break;
  100. #endif
  101.     }
  102. #if    LZW
  103.     if(up->zout != NULLLZW)
  104.         tprintf("Compressed %ld bytes.\n",up->zout->cnt);
  105.     if(up->zin != NULLLZW)
  106.         tprintf("Decompressed %ld bytes.\n",up->zin->cnt);
  107. #endif
  108.     return 0;    
  109. }
  110.  
  111.