home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / hamradio / s920603.zip / SOCKCMD.C < prev    next >
C/C++ Source or Header  |  1992-05-30  |  1KB  |  64 lines

  1. /* Socket status display code
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. #include <stdio.h>
  5. #include "global.h"
  6. #include "mbuf.h"
  7. #include "proc.h"
  8. #include "lzw.h"
  9. #include "usock.h"
  10. #include "socket.h"
  11. #include "commands.h"
  12.  
  13. /* Socket status display command */
  14. int
  15. dosock(argc,argv,p)
  16. int argc;
  17. char *argv[];
  18. void *p;
  19. {
  20.     register struct usock *up;
  21.     int s,i;
  22.     struct sockaddr fsock;
  23.     struct socklink *sp;
  24.     char *cp;
  25.  
  26.     if(argc < 2){
  27.         printf("S#  Type    PCB      Remote socket         Owner\n");
  28.         for(s=Nfiles;s<Nsock+Nfiles;s++){
  29.             up = itop(s);
  30.             if(up == NULLUSOCK)
  31.                 continue;
  32.  
  33.             i = sizeof(fsock);
  34.             if(getpeername(s,(char *)&fsock,&i) == 0 && i != 0)
  35.                 cp = psocket(&fsock);
  36.             else
  37.                 cp = "";
  38.  
  39.             printf("%3d %-8s%-8lx %-22s%-8lx %-10s\n",
  40.              s,Socktypes[up->type],ptol(up->cb.p),cp,
  41.              ptol(up->owner),up->owner->name);
  42.         }
  43.         return 0;
  44.     }
  45.     s = atoi(argv[1]);
  46.     if(s < Nfiles || s >= Nsock+Nfiles){
  47.         printf("Number out of range\n");
  48.         return 1;
  49.     }
  50.     up = itop(s);
  51.     if(up == NULLUSOCK){
  52.         printf("Socket not in use\n");
  53.         return 0;
  54.     }
  55.     sp = up->sp;
  56.     printf("%s %lx\n",Socktypes[up->type],ptol(up->cb.p));
  57.     if(up->cb.p == NULL)
  58.         return 0;
  59.     if(sp->status != NULLFP)
  60.         (*sp->status)(up);
  61.     return 0;    
  62. }
  63.  
  64.