Exemplo n.º 1
0
static void parse_descriptor(struct qeth_qoat_hdr *oat_hdr,
	struct qeth_print_hdr *phdr, char *buf, int *processed)
{
	int i;
	char *ptr;

	*processed += oat_hdr->len;
	for (i = 0; i < oat_hdr->type.descriptor.reply_entry_count; i++) {
		ptr = buf + *processed;
		switch (oat_hdr->type.descriptor.des_type) {
		case OAT_DES_TYPE_IP4:
			print_ip4((struct qeth_qoat_des_ip4 *)ptr, phdr->ip4_h);
			phdr->ip4_h = 0;
			break;
		case OAT_DES_TYPE_IP4MC:
			print_ip4mc((struct qeth_qoat_des_ip4mc *)ptr,
				phdr->ip4mc_h);
			phdr->ip4mc_h = 0;
			break;
		case OAT_DES_TYPE_IP6:
			print_ip6((struct qeth_qoat_des_ip6 *)ptr, phdr->ip6_h);
			phdr->ip6_h = 0;
			break;
		case OAT_DES_TYPE_IP6MC:
			print_ip6mc((struct qeth_qoat_des_ip6mc *)ptr,
				phdr->ip6mc_h);
			phdr->ip6mc_h = 0;
			break;
		case OAT_DES_TYPE_VMAC:
			print_vmac((struct qeth_qoat_des_vmac *)ptr,
				phdr->vmac_h);
			phdr->vmac_h = 0;
			break;
		case OAT_DES_TYPE_VLAN:
			print_vlan((struct qeth_qoat_des_vlan *)ptr,
				phdr->vlan_h);
			phdr->vlan_h = 0;
			break;
		case OAT_DES_TYPE_GMAC:
			print_gmac((struct qeth_qoat_des_gmac *)ptr,
				phdr->gmac_h);
			phdr->gmac_h = 0;
			break;
		case OAT_DES_TYPE_AIQ:
			print_aiq((struct qeth_qoat_des_aiq *)ptr,
				phdr->aiq_h);
			phdr->aiq_h = 0;
			break;
		default:
			printf("Unknown descriptor (0x%x)\n",
				oat_hdr->type.descriptor.des_type);
			hex_dump(ptr,
				oat_hdr->type.descriptor.reply_entry_len);
		}
		*processed += oat_hdr->type.descriptor.reply_entry_len;
	}
}
Exemplo n.º 2
0
static void debug( const struct sockaddr* before, struct sockaddr* after ) {
   printf("bind_public: ");
   switch( before->sa_family ) {
      case AF_INET:
         print_ip4( ((struct sockaddr_in*)before)->sin_addr.s_addr );
         printf(" --> ");
         print_ip4( ((struct sockaddr_in*)after)->sin_addr.s_addr );
         printf("\n");
         break;
      case AF_INET6:
         print_ip6( ((struct sockaddr_in6*)before)->sin6_addr.s6_addr );
         printf(" --> " );
         print_ip6( ((struct sockaddr_in6*)after)->sin6_addr.s6_addr );
         printf("\n");
         break;
      default:
         printf("UNKNOWN --> UNKNOWN\n");
         break;
   }
   fflush( stdout );
}
Exemplo n.º 3
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);
}
Exemplo n.º 4
0
const char *
inet_ntop(int af, const void *addr, char *str, size_t size)
{
    char *cp;

#if defined(IP_V4) || defined(MINI_IP)
    if (af == AF_INET)
    {
        u_long   ip4addr;

        ip4addr = *(u_long*)addr;
        cp = print_ipad(ip4addr);
        if (strlen(cp) < size)
        {
            strcpy(str, cp);
            return (str);
        }
    }
#endif   /* IP_V4 */

#ifdef IP_V6
    if (af == AF_INET6)
    {
        char ip6buf[48];

        cp = print_ip6((ip6_addr *)addr, ip6buf);
        if (strlen(cp) < size)
        {
            strcpy(str, ip6buf);
            return (str);
        }
    }
#endif

    return ((const char *)NULL);
}
Exemplo n.º 5
0
/* FUNCTION: netmain_iface()
 *
 * Display interface status
 *
 * PARAM1: CLI_CTX            CLI context
 *
 * RETURN: int                0 if successful, otherwise error code
 *
 * iface -i <iface>
 */
STATIC int
netmain_iface(CLI_CTX ctx)
{
   GIO *gio = ctx->gio;
   struct net *ifp;
   int iface;
   
   if (CLI_HELP(ctx))
   {
      return (0);
   }

   if (CLI_DEFINED(ctx, 'i'))
   {
      iface = (int)CLI_VALUE(ctx, 'i');
      if ((iface < 1) || (iface > (int)ifNumber))
         return (CLI_ERR_PARAM);

      ifp = nets[iface - 1];

      if (CLI_DEFINED(ctx, 'm'))
      {
         uint32_t mtu = (uint32_t)CLI_VALUE(ctx, 'm');

         if ((mtu >= 128) && (mtu < 65536))
         {
            ifp->n_mtu = mtu;    /* new interface MTU value */
         }
         else
            return (CLI_ERR_PARAM);
      }

      gio_printf(gio, "Interface %s - %s, MTU %d\n", 
                      ifp->name, ifp->n_mib->ifDescr, ifp->n_mtu);

#ifdef IP_V4
         gio_printf(gio, "IPv4 address: %u.%u.%u.%u, ",
                         PUSH_IPADDR(ifp->n_ipaddr));
         gio_printf(gio, "subnet mask: %u.%u.%u.%u, ",
                         PUSH_IPADDR(ifp->snmask));
         gio_printf(gio, "gateway: %u.%u.%u.%u\n",
                         PUSH_IPADDR(ifp->n_defgw));
#endif   /* IP_V4 */

      {
         char buf[80];

         gio_printf(gio, "Flags: %s\n",
                    in_bit2str(&ifp_flags[0], ifp->n_flags, &buf[0], 80, ','));
      }

#if defined(IP_V6) && defined(IP6_MENUS)
      if (ifp->n_flags & NF_IPV6)
      {
         int i;
         char ip6buf[46];     /* tmp buffer for ipv6 address text */

         for (i = 0; i < MAX_V6_ADDRS; i++)
         {
            if (ifp->v6addrs[i])
            {
               gio_printf(gio, "IPv6 %6s addr: %s", v6types[i], 
                          print_ip6(&(ifp->v6addrs[i]->addr), ip6buf));
               gio_printf(gio, " - %s\n", 
                          ip6addrstates[ifp->v6addrs[i]->flags & IA_STATEMASK]);
            }
         }
      }
      else
         gio_printf(gio, "No IPv6 addresses\n");
#endif   /* IP_V6 && IP6_MENUS */

      gio_printf(gio, "Status: Admin:%s Oper:%s for: %s\n", 
                 (ifp->n_mib->ifAdminStatus == 1) ? "up" : "down",
                 (ifp->n_mib->ifOperStatus == 1)  ? "up" : "down",
                 print_uptime(TIME_SUB(sysuptime(), (ifp->n_mib->ifLastChange))));
      gio_printf(gio, "rcvd: errors:%lu   dropped:%lu   station:%lu   bcast:%lu   bytes:%lu\n",
                 ifp->n_mib->ifInErrors, ifp->n_mib->ifInDiscards,
                 ifp->n_mib->ifInUcastPkts, ifp->n_mib->ifInNUcastPkts,
                 ifp->n_mib->ifInOctets);
      gio_printf(gio, "sent: errors:%lu   dropped:%lu   station:%lu   bcast:%lu   bytes:%lu\n",
                 ifp->n_mib->ifOutErrors, ifp->n_mib->ifOutDiscards,
                 ifp->n_mib->ifOutUcastPkts, ifp->n_mib->ifOutNUcastPkts,
                 ifp->n_mib->ifOutOctets);
      gio_printf(gio, "MAC address: ");
      gio_hexdump(gio, ifp->n_mib->ifPhysAddress, 6, TRUE, FALSE);
      gio_printf(gio, " \n");

#ifdef IP_MULTICAST
   /* Print any multicast addresses assigned to this iface */
#ifndef USE_IGMPV3
      if (ifp->mc_list)
      {
         struct in_multi *imp;

         gio_printf(gio, "   Multicast addresses: \n");
         for (imp = ifp->mc_list; imp; imp = imp->inm_next)
         {
#ifdef IP_V6
            if (*(u_long *)&imp->ip6addr != 0x0)
            {
               char ip6buf[40];     /* tmp buffer for ipv6 address text */

               gio_printf(gio, "   %s\n", print_ip6(&(imp->ip6addr), ip6buf));
            }
            else
#endif   /* IP_V6 */
            {
               gio_printf(gio, "   %u.%u.%u.%u\n", PUSH_IPADDR(imp->inm_addr));
            }
         }
      }
#else /* if USE_IGMPV3 defined*/
      igmp_print_membership(ifp, gio);
#endif /* USE_IGMPV3 */
#endif /* IP_MULTICAST */
   }
   else     /* list all interfaces */
   {
      for (iface = 1; iface <= (int)ifNumber; iface++)
      {
         gio_printf(gio, "%2d: %s - %s\n",
                    iface, 
                    nets[iface-1]->name, nets[iface-1]->n_mib->ifDescr);
      }
   }

   return (0);
}
Exemplo n.º 6
0
int
ifstats(void * pio, struct net * ifp)
{
   ns_printf(pio, "Interface %s - %s \n", 
      ifp->name, ifp->n_mib->ifDescr);
#ifdef IP_V4
   ns_printf(pio,"IPv4 address: %s, " , print_ipad(ifp->n_ipaddr));
   ns_printf(pio,"subnet mask: %s, ", print_ipad(ifp->snmask));
   ns_printf(pio,"gateway: %s\n"    , print_ipad(ifp->n_defgw));
#endif   /* IP_V4 */
#ifdef IP_V6
   if(ifp->n_flags & NF_IPV6)
   {
      int i;
      char ip6buf[46];     /* tmp buffer for ipv6 address text */

      for(i = 0; i < MAX_V6_ADDRS; i++)
      {
         if(ifp->v6addrs[i])
         {
            ns_printf(pio,"IPv6 %6s addr: %s", v6types[i], 
               print_ip6(&(ifp->v6addrs[i]->addr), ip6buf));
            ns_printf(pio," - %s\n", 
               ip6addrstates[ifp->v6addrs[i]->flags & IA_STATEMASK]);
         }
      }
   }
   else
      ns_printf(pio,"No IPv6 addresses\n");
#endif   /* IP_V6 */
   ns_printf(pio,"Status; Admin:%s Oper:%s for: %s\n", 
      ifp->n_mib->ifAdminStatus==1?"up":"down",
      ifp->n_mib->ifOperStatus==1?"up":"down",
      print_uptime(sysuptime() - (ifp->n_mib->ifLastChange)));
   ns_printf(pio,"rcvd: errors:%lu   dropped:%lu   station:%lu   bcast:%lu   bytes:%lu\n",
      ifp->n_mib->ifInErrors, ifp->n_mib->ifInDiscards,
      ifp->n_mib->ifInUcastPkts, ifp->n_mib->ifInNUcastPkts,
      ifp->n_mib->ifInOctets);
   ns_printf(pio,"sent: errors:%lu   dropped:%lu   station:%lu   bcast:%lu   bytes:%lu\n",
      ifp->n_mib->ifOutErrors, ifp->n_mib->ifOutDiscards,
      ifp->n_mib->ifOutUcastPkts, ifp->n_mib->ifOutNUcastPkts,
      ifp->n_mib->ifOutOctets);
   ns_printf(pio,"MAC address: ");
   hexdump(pio,ifp->n_mib->ifPhysAddress, 6);
   ns_printf(pio," \n");

#ifdef IP_MULTICAST
   /* Print any multicast addresses assign to this iface */
   if(ifp->mc_list)
   {
      struct in_multi * imp;

      ns_printf(pio, "   Multicast addresses: \n");
      for (imp = ifp->mc_list; imp; imp = imp->inm_next)
      {
#ifdef IP_V6
         {
            char ip6buf[40];     /* tmp buffer for ipv6 address text */
            ns_printf(pio, "   %s\n", print_ip6(&(imp->ip6addr), ip6buf));
            continue;
         }
#endif   /* IP_V6 */
         ns_printf(pio, "   %s\n",  print_ipad(imp->inm_addr) );
      }
   }
#endif   /* IP_MULTICAST */


   return 0;
}
Exemplo n.º 7
0
int
ping6_recv(PACKET pkt)
{
   struct ipv6 *pip;
   struct ping6 *ping;
   struct icmp6req *pinghdr;
   char   msg[50];
   int    offset;
   int    bytesleft;
   int    err = 0;
   int    len;
   char  *datap;
   int    i;
   PACKET p;

   pip = pkt->ip6_hdr;
   pinghdr = (struct icmp6req *)pkt->nb_prot;

   /* find the session the callback is for */
   for (ping = ping6q; ping; ping = ping->next)
   {
      if (pinghdr->id == ping->sess_id)
         break;
   }
   if (!ping)
   {
      dprintf("Ping response from unknown host=%lx\n", pkt->fhost);
      LOCK_NET_RESOURCE(FREEQ_RESID);
      PK_FREE(pkt);
      UNLOCK_NET_RESOURCE(FREEQ_RESID);
      return (0);
   }
  /* the upcalled packet included the ICMP header. Strip this off
    * for the purposes of reporting data size
    */
   if (ping->totread == 0)
   {
      bytesleft = pkt->nb_plen -= sizeof(struct icmp6req);
      datap = pkt->nb_prot + sizeof(struct icmp6req);
   }
   else
   {
      bytesleft = pkt->nb_plen;
      datap = pkt->nb_prot;
   }
   /* Verify that the data matches our default data */
   p = pkt;
   while (p)
   {
      offset = ping->totread ? ping->totread % PINGSTRSIZE : 0;
      while (bytesleft)
      {
         len = MIN(bytesleft, PINGSTRSIZE);
         for (i = offset; i < len; i++) 
         {
            if (*datap++ != *(pingdata6 + i))
            {
               dprintf("ping data mismatch at byte %u\n", 
                       i + ping->totread + sizeof(struct icmp6req));
               err = -1;
               break;
            }
         }
         if (err)
            break;
         offset = 0;   /* Back to beginning of pingdata */
         bytesleft -= len;
         ping->totread += len;
      }
      p = p->pk_next;
      if (p)
      {
         bytesleft = p->nb_plen;
         datap = p->nb_prot;
      }
   }
   LOCK_NET_RESOURCE(FREEQ_RESID);
   PK_FREE(pkt);
   UNLOCK_NET_RESOURCE(FREEQ_RESID);
   if ((ping->totread != ping->length) && (ping->replies == 0))
      gio_printf(ping->gio, "Reply truncated to %d bytes\n", ping->totread);
   if (++ping->replies == ping->count)
      ping6_done(ping);
   else
   {
      gio_printf(ping->gio, "ping6 reply: len=%d session %d (seq: %d) [%s]\n",
                 ping->totread,
                 htons(pinghdr->id), 
                 htons(pinghdr->sequence), 
                 print_ip6(&pip->ip_src, msg));
      ping->totread = 0;
      ping->last = CTICKS;
   }
   return 0;
}
Exemplo n.º 8
0
int
ping6_send(struct ping6 *ping)
{
   PACKET   pkt;
   struct icmp6req *pinghdr;
   char     addrbuf[40];   /* for printf()ing */
   int      plen = sizeof(struct icmp6req) + ping->length;
   int      err = 0;
   int      sendflags;
   int      bytesleft;
   int      offset;
   /* try for a pkt chain */
   LOCK_NET_RESOURCE(FREEQ_RESID);
   PK_ALLOC(pkt, plen + MaxLnh + sizeof(struct ipv6));
   UNLOCK_NET_RESOURCE(FREEQ_RESID); 

   if (pkt == NULL)
   {
      ping->count = 0;     /* mark session for deletion */
      return (ENP_NOBUFFER);
   }
   pkt->flags = 0;

   /* prepare for cb_read */
   pkt->nb_prot = pkt->nb_buff + MaxLnh + sizeof(struct ipv6);
 
   /* got chain? */
   if (pkt->pk_next == NULL)
      pkt->nb_plen = plen;       /* no */
   else
      pkt->nb_plen = pkt->nb_blen - MaxLnh - sizeof(struct ipv6);   /* yes */   

   /* Advance to point where we write the data */
   offset = sizeof(struct icmp6req);
   pkt->nb_tlen = offset;
   bytesleft = ping->length;
 
   while (bytesleft > PINGSTRSIZE)
   {
      err = cb_read(pkt, offset, (uint8_t *)pingdata6, PINGSTRSIZE);
      if (err < 0)
         break;
      offset += err;
      bytesleft -= err;
   }
   if (bytesleft && (err >= 0))
      err = cb_read(pkt, offset, (uint8_t *)pingdata6, bytesleft);
   /* read in data - user or standard? */
      
   /* got err? */
   if (err <= 0)
   {
      LOCK_NET_RESOURCE(FREEQ_RESID);  
      PK_FREE(pkt);
      UNLOCK_NET_RESOURCE(FREEQ_RESID);    
      ping->count = 0;     /* mark session for deletion */
      return (ENP_NOBUFFER);
   }    

#ifdef IP6_ROUTING
   /* Put scopeID in pkt */
   pkt->soxopts = npalloc(sizeof(struct ip_socopts));
   if (pkt->soxopts == NULL)
   {
      LOCK_NET_RESOURCE(FREEQ_RESID);
      pk_free(pkt);
      UNLOCK_NET_RESOURCE(FREEQ_RESID);      
      ping->count = 0;     /* mark session for deletion */
      return (ENP_NOBUFFER);
   }
   pkt->soxopts->ip_scopeid = ping->scopeID;
#endif

   pinghdr = (struct icmp6req *)pkt->nb_prot;
   pinghdr->code = 0;
   pinghdr->type = ICMP6_ECHOREQ;
   pinghdr->id = ping->sess_id;
   pinghdr->sequence = (htons((unshort)ping->sent));
   ping->sent++;
   pkt->net = ping->net;

   pkt->type = htons(0x86dd);

   /* multicast ping? */
   if (ping->fhost.addr[0] == 0xFF)
   {
      pkt->flags |= PKF_MCAST;  /* send mac multicast */
      sendflags = 0; /* no routing */
   }
   else
   {
      pkt->flags &= ~PKF_MCAST;  /* send mac unicast */
      /* see if we can skip the routing step */
      if(pkt->net && (!IP6EQ(&ping->nexthop, &ip6unspecified)))
      {
        pkt->nexthop = &ping->nexthop;   /* set next hop */
        sendflags = IP6F_NOROUTE;
      }
      else
        sendflags = IP6F_ALL;
   }
   /* is the scope global? */
   if ( (ping->fhost.addr[0] == 0xFF) && ((ping->fhost.addr[1] & 0xF) == 0xE) )
      {
         /* yup - it's a global ping */         
        pkt->flags |= PKF_IPV6_GBL_PING;  /* global ping */        
      }

   /* loopback? */
   if (IN6_IS_ADDR_LOOPBACK((struct in6_addr *)&(ping->fhost.addr)))
      IP6CPY((struct in6_addr *)&(ping->lhost.addr), 
             (struct in6_addr *)&(ping->fhost.addr));   /* both are loopback */

   /* put prot at IPv6 hdr */
   pkt->nb_prot -= sizeof(struct ipv6);
   pkt->nb_plen += sizeof(struct ipv6);
   pkt->nb_tlen += sizeof(struct ipv6);
  
   /* set time for next ping */
   ping->nextping = TIME_ADD(CTICKS, ping->ping6_interval); 
 
   err = icmp6_send(pkt, &ping->lhost, &ping->fhost, sendflags);
   pkt->net->icmp6_ifmib.OutEchos++;
   
   if (err < 0)
   {
      /* Don't record gio error, since we're going to kill this
       * ping session anyway.
       */
      gio_printf(ping->gio, "error %d sending ping; sess %d, seq:%d\n",
                 err, ntohs(ping->sess_id), ping->sent);
      ping->count = 0;     /* mark session for deletion by timer */
   }
   else if ((err == 1) || (err == 0))
   {
      err = gio_printf(ping->gio, "Sent ping; sess: %d, Seq: %d to %s\n",
                       ntohs(ping->sess_id), ping->sent,
                       print_ip6(&ping->fhost, addrbuf));
   }
   return (0);
}
Exemplo n.º 9
0
STATIC int
ping_debug(CLI_CTX ctx)
{
   GIO *gio = ctx->gio;
   uint32_t count = 1;              /* Default count */
   char *data = NULL; 
   int datalen;
   int ret;
   u_long ipadd = 0;
   struct cli_addr *cliaddr = NULL;
#ifdef IP_V6
   ip6_addr fhost6;                 /* v6 target to ping */
   int  scopeID = 1;                /* Default scope ID  */
   int  prefixLen = 64;
   int *ping6Live = (int *)NULL;
#endif   /* IP_V6 */
   int delay = TPS;                 /* Default delay  */
   int set_datalen = 0;
   
   if (CLI_HELP(ctx))
      return (0);
  
   if ((!CLI_DEFINED(ctx, 'a') && !CLI_DEFINED(ctx, 'h')) ||
       (CLI_DEFINED(ctx, 'a') && CLI_DEFINED(ctx, 'h')))
   {
      gio_printf(gio, "One of: -a <addr> or -h <name> is required\n");
      return (CLI_ERR_PARAM);
   }
   if (CLI_DEFINED(ctx, 'a'))
   {
      cliaddr = (struct cli_addr *)CLI_VALUE(ctx, 'a');
      if ((cliaddr->type != CLI_IPV4) && (cliaddr->type != CLI_IPV6))
         return (CLI_ERR_PARAM);
#ifdef IP_V4     
      if (cliaddr->type == CLI_IPV4) 
         ipadd = *((ip_addr *)&cliaddr->addr[0]);   /* IPv4 address? */
#endif /* IP_V4 */
#ifdef IP_V6    
      if (cliaddr->type == CLI_IPV6) 
      {
         IP6CPY(&fhost6, ((ip6_addr *)&cliaddr->addr[0]));  /* IPv6 address? */
         scopeID = cliaddr->scopeID;
         if (cliaddr->prefixLen != 0)
            prefixLen = cliaddr->prefixLen;
      }
#endif /* IP_V6 */  
   }
   else
   {
      char *hdata = (char *)CLI_VALUE(ctx, 'h');
      ip_addr fhost4 = 0L;
         
#ifdef IP_V6
      ret = in_reshost(hdata, &fhost4, &fhost6, RH_VERBOSE | RH_BLOCK);
#else         
      ret = in_reshost(hdata, &fhost4, NULL, RH_VERBOSE | RH_BLOCK);
#endif /* IP_V6 or not */
      if (ret != 0)
      {
         gio_printf(gio, "Unable to resolve ping host \"%s\"\n", hdata);
         return (CLI_ERR_PARAM);
      }      
      if (fhost4 != 0L)
         ipadd = (u_long)fhost4;
   }
   /* length? */
   if (CLI_DEFINED(ctx, 'l'))
   {
      datalen = (int)CLI_VALUE(ctx, 'l');
      
      set_datalen = 1;
      
      if (datalen < 0)
      {
         gio_printf(gio, "length < 0\n");
         return (CLI_ERR_PARAM);
      }
   }   
   /* delay between pings? */
   if (CLI_DEFINED(ctx, 't'))
   {
      delay = (int)CLI_VALUE(ctx, 't');
      if (delay <= 0)
      {
         gio_printf(gio, "delay <= 0\n");
         return (CLI_ERR_PARAM);
      }   
   }
   /* Number of pings  */
   if (CLI_DEFINED(ctx, 'n'))
   {
      count = (int)CLI_VALUE(ctx, 'n');
      if (count < 1)
      {
         gio_printf(gio, "ping count <= 0\n");
         return (CLI_ERR_PARAM);
      }
   }
   if (count > 5)
      gio_printf(gio, "Type 'k' (Kill) for early termination\n");
 
#ifdef IP_V6
   /* ipadd is now used as a flag to indicate IPv4 or not */
   if (ipadd == 0) 
   {
      char wrkBuf[40];

      if (!set_datalen)
         datalen = strlen(pingdata6);  /* Default length */
         
      ping6Live = &ping6LiveSig;
      gio_printf(gio, "ping IPv6 addr: %s\n", print_ip6(&fhost6, wrkBuf));
      ping6_start(gio, &fhost6, scopeID, count, datalen, data,  delay, ping6Live);
         
      /* bad start? */
      if (ping6LiveSig == 0)
      {
         gio_printf(gio, "Bad ping6 initialization\n");
         return (0);  /* yes */
      }
   }
#endif    /* IP_V6  */

#ifdef IP_V4
   /* ipadd is now used as a flag to indicate IPv4 or not */
   if (ipadd != 0) 
   {
      ping4ID++;  /* bump to next ping ID */
      
      if (!set_datalen)
         datalen = strlen(pingdata);  /* Default length */
         
#ifndef OS_PREEMPTIVE
     start_ping_req(gio, ipadd, count, datalen, data, delay);
#else
      msgp = (struct pingtask_msg *) PING_ALLOC (sizeof (struct pingtask_msg));
      if (!msgp)
      {
         ++ping_err.alloc_fail;
         return (PING_ST_ALLOC_ERR);
      }
         
      /* send message for PING client task */
      msgp->type = PING_CNTRL_START_PING;
      msgp->ipadd = (u_long) ipadd;
      msgp->times = count;
      msgp->gio = gio;
      msgp->data = data; 
      msgp->length = dataLen;
      msgp->delay = delay;
         
      LOCK_NET_RESOURCE (PINGQ_RESID);
      putq(&pingRcvq, (q_elt)msgp);
      UNLOCK_NET_RESOURCE (PINGQ_RESID);
      
      TK_SIGNAL(to_diagcheck, NULL);
#endif   /* OS_PREEMPTIVE  */
   }
#endif  /* IP_V4 */
      
   /* wait for console input or ping end */
   for (;;)
   {
      int  ret;
      char buff[3];
      int flags;
      
      buff[0] = NUL;

      /* Check if ping is still running */
#if defined(IP_V4) && defined(PING_APP)
      if ((ipadd != 0) && !ping_search(gio))
         break;    /* No */
#endif  /* IP_V4 && PING_APP */
#ifdef IP_V6
      if ((ipadd == 0) && !ping6q)
         break;    /* No  */
#endif   /* IP_V6  */

      /* read a char - set GIO non-blocking read */
      flags = gio->flags;
      gio->flags &= ~GIO_F_BIN;
      ret = gio_in(gio, buff, 1);
      gio->flags = flags;

      /* Console routine puts char in buff[0]; telnet's puts it in ret */
      if ((ret > 0) && ((buff[0] == 'k') || (ret == 'k')))
      {
#if defined(IP_V4) && defined(PING_APP)
         if (ipadd != 0)
         {
            PING_INFO p;

            if ((p = ping_search(gio)) != NULL)
               ping_cmd_end(p);
            break;  /* already done */
         }
         else
#endif  /* IP_V4 && PING_APP */
#ifdef IP_V6
            ping6_done(ping6q);
#endif   /* IP_V6  */

         gio_printf(gio, "Ping canceled by console\n");
         break;
      }     
      TK_YIELD();
   }  
   return (0);
}
Exemplo n.º 10
0
/* FUNCTION: netdiag_lookup()
 *
 * Resolve a host name to an IP address.
 *
 * PARAM1: CLI_CTX *          CLI context
 *
 * RETURN: int   
 */
int
netdiag_nslookup(CLI_CTX ctx)
{
   GIO *gio = ctx->gio;
   int  err = 0;

   if (!CLI_HELP(ctx))
   {
      /* host name? */
      if (!CLI_DEFINED(ctx, 'a'))
         err = CLI_ERR_MISSING;     /* hostname/address is required */
      else
      {
         char *cp = (char *)CLI_VALUE(ctx, 'a');
         struct dns_querys *DNSq = (struct dns_querys *)NULL;
   
         if (CLI_DEFINED(ctx, 'r'))    /* reverse lookup */
         {
            err = nslookupr(cp, DNS_TYPE_PTR, &DNSq);
            if (err != 0)
               gio_printf(gio, "nslookup failed.\n");
            else if (DNSq)
            {
               gio_printf(gio, "%s   name = %s\n",
                               DNSq->dns_names, DNSq->ptr_name);
            }
            else
            {
               gio_printf(gio, "dns_entry is NULL\n");
            }
         }
         else if (CLI_DEFINED(ctx, 't'))  /* text query */
         {
            /* call TXTQuery() to resolve the passed name */
            if ((DNSq = TXTQuery(cp)) == (struct dns_querys *)NULL)
            {
               gio_printf(gio, "nslookup failed.\n");
            }
            else
            {
               if (DNSq->h_TXT_listCount == 0)
               {
                  gio_printf(gio, "\tno TXT entries\n");
               }
               else
               {
                  TXTENTRY *cpp = DNSq->h_TXT_list;
                  int  i;

                  for (i = 0; i < DNSq->h_TXT_listCount; i++)
                  {
                     gio_printf(gio, "txt-%d:\n", i + 1);
                     gio_hexdump(gio, cpp->txt, cpp->len, TRUE, FALSE);
                     npfree(cpp->txt);
                     cpp++;
                  }
               }
            }
         }
         else                          /* normal lookup */
         {
#ifdef IP_V6
            int  af = (CLI_DEFINED(ctx, 'y')) ? AF_INET6 : AF_INET;
#else
            int  af = AF_INET;
#endif /* IP_V6 */
            struct hostent *ho = gethostbyname2(cp, af);

            if (ho)
            {
               gio_printf(gio, " h_name is %s\n", ho->h_name ? ho->h_name : "NULL");
               gio_printf(gio, " h_addrtype = %d\n", ho->h_addrtype);
               gio_printf(gio, " h_length = %d\n", ho->h_length);
               gio_printf(gio, " h_addr_list are:\n");
               if (!(ho->h_addr_list))
               {
                  gio_printf(gio, "\tno addresses\n");
               }
               else
               {
                  char **cpp;

                  for (cpp = ho->h_addr_list; *cpp; cpp++)
                  {
                     if (af == AF_INET)
                     {
                        u_char *ucp = (u_char *)(*cpp);

                        gio_printf(gio, "\t%d.%d.%d.%d\n",
                                        ucp[0], ucp[1], ucp[2], ucp[3]);
                     }
#ifdef IP_V6
                     else
                     {
                        char ip6buf[40];

                        print_ip6((struct in6_addr *)(*cpp), ip6buf);
                        gio_printf(gio, "\t%s\n", ip6buf);
                     }
#endif /* IP_V6 */
                  }
               }
            }
            else
            {
               gio_printf(gio, "nslookup failed.\n");
            }
         }
      }
   }

   return (err);
}