Exemplo n.º 1
0
/* FUNCTION: sock_info()
 *
 * Display TCP and UDP socket structures (for IPv4 and/or IPv6)
 *
 * PARAM1: CLI_CTX            CLI context
 *
 * RETURNS: int               0 if successful, otherwise error code
 *
 */
STATIC int
sock_info(CLI_CTX ctx)
{
   GIO *gio = ctx->gio;
   char *pfstr = NULL;
   u_char prot = NO_IPPROTO;
   u_char domain = 0;
   int dump_all = FALSE;
   int i;

   if (CLI_DEFINED(ctx, 'p'))
   {
      pfstr = (char *)CLI_VALUE(ctx, 'p');

      for (i = 0; i < sizeof(npt) / sizeof(struct netprot); ++i)
      {
         if (!stricmp(pfstr, npt[i].name))
         {
            prot = npt[i].prot_id;
            domain = npt[i].domain;
            break;
         }
      }
   }
   else
   {
      /* dump information for all protocols (TCP and UDP) and 
       * all address families (IPv4 and IPv6)
       */
      dump_all = TRUE;
      domain = AF_INET_ALL;
   }

   if ((prot == NO_IPPROTO) && !dump_all)
   {
      return (CLI_ERR_PARAM);
   }
   else
   {
#ifdef NET_STATS
      if ((prot == IPPROTO_TCP) || dump_all)
      {
         tcpsock_list(gio, (int)domain);
      }

      if ((prot == IPPROTO_UDP) || dump_all)
      {
         udpsock_list(gio, (int)domain);
      }
#endif
   }

   return (0);
}
Exemplo n.º 2
0
int
sock_list(void * pio)
{
   struct inpcb * inp;
   struct socket *   so;
   struct tcpcb * tp;

   if (tcb.inp_next == NULL)
   {
      ns_printf(pio,"No TCP sockets\n");
      return 0;
   }

   ns_printf(pio,
    "TCP sock, fhost,     ports,    opts, rxbytes, txbytes, snd_una, snd_nxt, state:\n");
   for (inp = tcb.inp_next; inp != &tcb; inp = inp->inp_next) 
   {
      tp = intotcpcb(inp);
      so = inp->inp_socket;
      if (!so)
      {
         ns_printf(pio,"No socket\n");
         continue;
      }

#ifdef IP_V4
      if(so->so_domain == AF_INET)
      ns_printf(pio,"%lx,  %u.%u.%u.%u", so, PUSH_IPADDR(inp->inp_faddr.s_addr));
#endif
#ifdef IP_V6
      if(so->so_domain == AF_INET6)
      {
         char  ip6buf[46];
         ns_printf(pio,"%lx,  %s(v6), ", so, print_ip6(&inp->ip6_faddr, &ip6buf[0]));
      }
#endif   /* IP_V6 */

      ns_printf(pio,", %u->%u, ", htons(inp->inp_lport), htons(inp->inp_fport));
      ns_printf(pio,"0x%x, %u, %u, %ld, %ld, ", (unsigned)so->so_options,
       (unsigned)so->so_rcv.sb_cc,(unsigned)so->so_snd.sb_cc,
       tp->snd_una, tp->snd_nxt);
      if ((tp->t_state < 0) || 
          (tp->t_state >= sizeof(tcpstates)/sizeof(tcpstates[0])))
         ns_printf(pio, "???\n");
      else
         ns_printf(pio, "%s\n", tcpstates[tp->t_state]);
   }

   return udpsock_list(pio);
}