示例#1
0
文件: iface.c 项目: fjanssen/Car2X
int
ni_set_state(NET ifp, int opcode)
{
   int   err = 0;

   if ((opcode != NI_DOWN) &&
       (opcode != NI_UP))
   {
      return ENP_PARAM;
   }

   LOCK_NET_RESOURCE(NET_RESID);

   if (opcode == NI_DOWN)  /* clean up system tables */
   {
#ifdef INCLUDE_TCP
      if_killsocks(ifp);      /* kill this iface's sockets */
#endif   /* INCLUDE_TCP */
      del_route(0, 0, if_netnumber(ifp));    /* delete any IP routes */
      clear_arp_entries(NULLIP, ifp);        /* delete any ARP entries */
   }

   /* force if-mib AdminStatus flag to correct setting. This will
    * keep devices without n_setstate() calls from receiving any
    * packet to send from ip2mac().
    */
   if (opcode == NI_UP)
      ifp->n_mib->ifAdminStatus = NI_UP;
   else
      ifp->n_mib->ifAdminStatus = NI_DOWN;

   ifp->n_mib->ifLastChange = cticks * (100/TPS);
   if (ifp->n_setstate) /* call state routine if any */
      err = ifp->n_setstate(ifp, opcode);
   else
      err = 0; /* no routine == no error */

   if(!err)
   {
      /* Get here if setstate was OK - set ifOperStatus */
      if (opcode == NI_UP)
         ifp->n_mib->ifOperStatus = NI_UP;
      else
         ifp->n_mib->ifOperStatus = NI_DOWN;
   }

   UNLOCK_NET_RESOURCE(NET_RESID);

   return err;
}
示例#2
0
/* FUNCTION: netdiag_arp()
 *
 * Display ARP table and statistics
 *
 * PARAM1: CLI_CTX            CLI context
 *
 * RETURNS: int               0 if successful, otherwise error code
 *
 * arp [-z STRING]
 */
STATIC int
netdiag_arp(CLI_CTX ctx)
{
   GIO *gio = ctx->gio;
   int err = 0;

   if (!CLI_HELP(ctx))
   {
#ifndef MINI_IP
      struct cli_addr ipaddr = { 0 };
      NET ifp = (NET)NULL;

      if (CLI_DEFINED(ctx, 'z'))
      {
         char *str = (char *)CLI_PARAM(ctx, 'z');
         char *endp = (char *)NULL;

         if (isdigit(str[0]))
         {
            if ((cli_parse_ipaddr(str, &endp, CLI_IPV4, &ipaddr) != 0) ||
                (ipaddr.type != CLI_IPV4))
            {
               err = CLI_ERR_PARAM;    /* not an IPv4 address */
            }
         }
         else if (stricmp(str, "all") == 0)
         {
            gio_printf(gio, "'all' is not yet supported\n");
            err = CLI_ERR_PARAM;
         }
         else
         {
            if ((ifp = if_getbyname(str)) == (NET)NULL)
            {
               err = CLI_ERR_PARAM;    /* interface not found */
            }
         }
      }
#endif /* !MINI_IP */

      if (err != 0)
      {
         gio_printf(gio, "illegal IPv4 address or network interface name.\n");
      }
      else
      {
         /* display ARP statistics */
         arp_stats(gio);

#ifndef MINI_IP
         if (CLI_DEFINED(ctx, 'z'))
         {
            /* clear entry(s) associated with this IP or NI */
            clear_arp_entries(*(ip_addr *)&ipaddr.addr, ifp);
         }
#endif /* !MINI_IP */
      }
   }

   return (err);
}