⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m2iflib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
*/STATUS rcvEtherAddrAdd    (    M2_IFINDEX *    pIfIndexEntry,    /* the avl node */    unsigned char * pEnetAddr         /* the addr to be added */    )    {    M2_IFRCVADDRTBL *    pIfRcvAddr = NULL;    M2_IFRCVADDRTBL **   ppTemp = &pIfIndexEntry->pRcvAddr;    if (pEnetAddr)        {        pIfRcvAddr = KHEAP_ALLOC(sizeof (M2_IFRCVADDRTBL));        if (!pIfRcvAddr)            return ERROR;        bcopy (pEnetAddr, pIfRcvAddr->ifRcvAddrAddr.phyAddress, ETHERADDRLEN);        pIfRcvAddr->ifRcvAddrAddr.addrLength = ETHERADDRLEN;        pIfRcvAddr->ifRcvAddrStatus = ROW_ACTIVE;        pIfRcvAddr->ifRcvAddrType = STORAGE_NONVOLATILE;        pIfRcvAddr->pNextEntry = NULL;        if (pIfIndexEntry->pRcvAddr)            {            while (*ppTemp)                {                if (memcmp (pEnetAddr, (*ppTemp)->ifRcvAddrAddr.phyAddress,                                                         ETHERADDRLEN) > 0)                    {                    ppTemp = &(*ppTemp)->pNextEntry;                    continue;                    }                else                    {                    pIfRcvAddr->pNextEntry = *ppTemp;                    break;                    }                                    *ppTemp = pIfRcvAddr;                }            }        else            {            pIfIndexEntry->pRcvAddr = pIfRcvAddr;            }        return (OK);        }        return (ERROR);    }/******************************************************************************** m2IfTblEntryGet - get a MIB-II interface-group table entry** This routine maps the MIB-II interface index to the system's internal* interface index.  The internal representation is in the form of a balanced* AVL tree indexed by ifIndex of the interface. The <search> parameter is * set to either M2_EXACT_VALUE or M2_NEXT_VALUE; for a discussion of its use, see* the manual entry for m2Lib. The interface table values are returned in a* structure of type M2_DATA, which is passed as the second argument to this * routine.** RETURNS: * OK, or ERROR if the input parameter is not specified, or a match is not found.** ERRNO:*  S_m2Lib_INVALID_PARAMETER*  S_m2Lib_ENTRY_NOT_FOUND** SEE ALSO:* m2Lib, m2IfInit(), m2IfGroupInfoGet(), m2IfTblEntrySet(), m2IfDelete()*/STATUS m2IfTblEntryGet    (    int       search,       /* M2_EXACT_VALUE or M2_NEXT_VALUE */    void *    pIfReqEntry   /* pointer to requested interface entry */    )    {    M2_IFINDEX *   pIfIndexEntry = NULL;    struct ifnet * pIfNetEntry = NULL;    int            index;    M2_ID *        pM2Id = NULL;    M2_DATA *      pM2Entry = (M2_DATA *)pIfReqEntry;    M2_NETDRVCNFG  ifDrvCnfg;        /* Validate pointer to requeste structure */     if (pIfReqEntry == NULL)	{	errnoSet (S_m2Lib_INVALID_PARAMETER);        return (ERROR);	}    semTake (m2InterfaceSem, WAIT_FOREVER);    /*     * For a M2_EXACT_VALUE search, look up the index provided in the     * request and get the node from our internal tree. For a     * M2_NEXT_VALUE search, look up the successor of this node.     */    /* First, Validate the bounds of the requested index  */    index = pM2Entry->mibIfTbl.ifIndex;    if (index > ifsInList || index < 0)        {        semGive (m2InterfaceSem);	errnoSet (S_m2Lib_ENTRY_NOT_FOUND);        return (ERROR);        }    /* Check to see if it is a EXACT search or a next search */    if (search == M2_EXACT_VALUE)        {        pIfIndexEntry = (M2_IFINDEX *) avlSearch (pM2IfRoot,                                  (GENERIC_ARGUMENT)index, nextIndex);        }    else        {        pIfIndexEntry = (M2_IFINDEX *) avlSuccessorGet (pM2IfRoot,                                 (GENERIC_ARGUMENT)index, nextIndex);        }    if (!pIfIndexEntry)        {        semGive (m2InterfaceSem);	errnoSet (S_m2Lib_ENTRY_NOT_FOUND);        return (ERROR);        }    /* Get the pointer to the ifnet struct for this ifIndex */        pIfNetEntry = (struct ifnet *) pIfIndexEntry->pIfStats;    /* Get the interface data from the driver via the Ioctl */    if (pIfIndexEntry->mibStyle == TRUE)        {        /* Call the RFC 2233 Ioctl */        if ( (pIfNetEntry->if_ioctl != NULL) &&             ((*pIfNetEntry->if_ioctl)(pIfNetEntry, SIOCGMIB2233,                                                  (caddr_t)&pM2Id) != 0) )            {            /* ioctl failed, copy default values and return */                        m2IfDefaultValsGet (pM2Entry, pIfIndexEntry);            pM2Entry->mibIfTbl.ifIndex = pIfIndexEntry->ifIndex;            m2IfCommonValsGet (pM2Entry, pIfIndexEntry);	    semGive(m2InterfaceSem);            return (OK);            }        memcpy ((char *)pM2Entry, (char *)&pM2Id->m2Data, sizeof (M2_DATA));        pM2Entry->mibIfTbl.ifIndex = pIfIndexEntry->ifIndex;        semGive (m2InterfaceSem);        return (OK);        }    else        {        /* Declare variables for RFC 1213 support */                M2_INTERFACETBL * pM2IntTblEntry = &pM2Entry->mibIfTbl;        M2_NETDRVCNTRS    m2DrvCounters;        bzero ((char *)pM2IntTblEntry, sizeof (M2_INTERFACETBL));        /* Enter some of the values that we already know */            pM2IntTblEntry->ifIndex = pIfIndexEntry->ifIndex;                    /* Do what we used to do before for the RFC 1213 only counters */        if ( (pIfNetEntry->if_ioctl != NULL) &&                ((*pIfNetEntry->if_ioctl)(pIfNetEntry, SIOCGMIB2CNTRS,                                         (caddr_t)&m2DrvCounters) != 0) )            {            m2IfDefaultValsGet (pM2Entry, pIfIndexEntry);            }        else            {	    /* Fill parameters with driver counters */            m2IfDefaultValsGet (pM2Entry, pIfIndexEntry);            pM2IntTblEntry->ifSpeed           = m2DrvCounters.ifSpeed;            pM2IntTblEntry->ifInOctets        = m2DrvCounters.ifInOctets;            pM2IntTblEntry->ifInDiscards      = m2DrvCounters.ifInDiscards;            pM2IntTblEntry->ifInUnknownProtos = m2DrvCounters.ifInUnknownProtos;            pM2IntTblEntry->ifOutOctets       = m2DrvCounters.ifOutOctets;            pM2IntTblEntry->ifOutDiscards     = m2DrvCounters.ifOutDiscards;            /* We can now do the second ioctl to get drv cnfg params */                        if ( (*pIfNetEntry->if_ioctl) &&                 ((*pIfNetEntry->if_ioctl)(pIfNetEntry, SIOCGMIB2CNFG,                                          (caddr_t)&ifDrvCnfg) == 0) )                {                /* Copy the ifType and the ifSpecific values */                                pM2IntTblEntry->ifType  = ifDrvCnfg.ifType;                if (ifDrvCnfg.ifSpecific.idLength > 0)                    {	            bcopy (((char *) ifDrvCnfg.ifSpecific.idArray), 		           ((char *) pM2IntTblEntry->ifSpecific.idArray),		           ifDrvCnfg.ifSpecific.idLength * sizeof (long));                     pM2IntTblEntry->ifSpecific.idLength =                                        ifDrvCnfg.ifSpecific.idLength;                    }                }            else                {                /*                 * no info from ioctl, make an educated guess at                 * the driver configuration                 */                if (strncmp(pIfNetEntry->if_name, "lo", 2) == 0)                    {                    /* IP Loop back interface. */                    pM2IntTblEntry->ifType  =                                     M2_ifType_softwareLoopback;                    pM2IntTblEntry->ifSpeed = 0;                    }                else                                          if (strncmp(pIfNetEntry->if_name, "sl", 2) == 0)                        {                        /* Slip Network Interface */                         pM2IntTblEntry->ifType  = M2_ifType_slip;                        pM2IntTblEntry->ifSpeed = 19200; /* Baud Rate ??? */                        }                else                    if (strncmp(pIfNetEntry->if_name, "ppp", 3) == 0)                        {                        /* PPP Network Interface */                        pM2IntTblEntry->ifType  = M2_ifType_ppp;                        pM2IntTblEntry->ifSpeed = 19200; /* Baud Rate ??? */                        }                else                    {                    /* Use Ethernet parameters as defaults */                    pM2IntTblEntry->ifType  =                                      M2_ifType_ethernet_csmacd;                    pM2IntTblEntry->ifSpeed = 10000000;                    }                }            }                /* Fill in the other parameters */        m2IfCommonValsGet (pM2Entry, pIfIndexEntry);                }    semGive (m2InterfaceSem);    return (OK);        }/******************************************************************************** m2IfDefaultValsGet - get the default values for the counters** This function fills the given struct with the default values as* specified in the RFC. We will enter this routine only if the ioctl* to the driver fails.** RETURNS: n/a*/void m2IfDefaultValsGet    (    M2_DATA *    pM2Data,        /* The requested entry */    M2_IFINDEX * pIfIndexEntry   /* The ifindex node */    )    {    struct ifnet * pIfNetEntry = (struct ifnet *)pIfIndexEntry->pIfStats;    /* We will check only for loopback here */    if (strncmp(pIfNetEntry->if_name, "lo", 2) == 0)        pM2Data->mibIfTbl.ifType = M2_ifType_softwareLoopback;    else        pM2Data->mibIfTbl.ifType = M2_ifType_other;    if (pIfIndexEntry->mibStyle == TRUE)        {        pM2Data->mibIfTbl.ifInOctets        = 0;        pM2Data->mibIfTbl.ifInUcastPkts     = 0;        pM2Data->mibIfTbl.ifInNUcastPkts    = 0;        pM2Data->mibIfTbl.ifInDiscards      = 0;        pM2Data->mibIfTbl.ifInErrors        = 0;        pM2Data->mibIfTbl.ifInUnknownProtos = 0;        pM2Data->mibIfTbl.ifOutOctets       = 0;        pM2Data->mibIfTbl.ifOutUcastPkts    = 0;        pM2Data->mibIfTbl.ifOutNUcastPkts   = 0;        pM2Data->mibIfTbl.ifOutDiscards     = 0;        pM2Data->mibIfTbl.ifOutErrors       = 0;        pM2Data->mibIfTbl.ifOutQLen         = 0;        }    pM2Data->mibXIfTbl.ifInMulticastPkts = 0;    pM2Data->mibXIfTbl.ifInBroadcastPkts = 0;    pM2Data->mibXIfTbl.ifOutMulticastPkts = 0;    pM2Data->mibXIfTbl.ifOutBroadcastPkts = 0;    memset(&(pM2Data->mibXIfTbl.ifHCInOctets), 0, sizeof(UI64));     memset(&(pM2Data->mibXIfTbl.ifHCInUcastPkts), 0, sizeof(UI64));    memset(&(pM2Data->mibXIfTbl.ifHCInMulticastPkts), 0, sizeof(UI64));    memset(&(pM2Data->mibXIfTbl.ifHCInBroadcastPkts), 0, sizeof(UI64));    memset(&(pM2Data->mibXIfTbl.ifHCOutOctets), 0, sizeof(UI64));    memset(&(pM2Data->mibXIfTbl.ifHCOutUcastPkts), 0, sizeof(UI64));    memset(&(pM2Data->mibXIfTbl.ifHCOutMulticastPkts), 0, sizeof(UI64));    memset(&(pM2Data->mibXIfTbl.ifHCOutBroadcastPkts), 0, sizeof(UI64));    memset(pM2Data->mibXIfTbl.ifName, 0, M2DISPLAYSTRSIZE);    pM2Data->mibXIfTbl.ifLinkUpDownTrapEnable = M2_LINK_UP_DOWN_TRAP_DISABLED;    pM2Data->mibXIfTbl.ifHighSpeed = 0;    pM2Data->mibXIfTbl.ifPromiscuousMode = M2_PROMISCUOUS_MODE_OFF;     pM2Data->mibXIfTbl.ifConnectorPresent = M2_CONNECTOR_NOT_PRESENT;    memset(pM2Data->mibXIfTbl.ifAlias, 0, M2DISPLAYSTRSIZE);    pM2Data->mibXIfTbl.ifCounterDiscontinuityTime = 0;    return;    }/******************************************************************************** m2IfCommonValsGet - get the common values** This function updates the requested struct with all the data that is* independent of the driver ioctl. This information can be obtained* from the ifnet structures.** RETURNS: n/a*/void m2IfCommonValsGet    (    M2_DATA *    pM2Data,        /* The requested struct */    M2_IFINDEX * pIfIndexEntry   /* The ifindex node */    )    {    struct ifnet *    pIfNetEntry    = (struct ifnet *)pIfIndexEntry->pIfStats;    M2_INTERFACETBL * pM2IntTblEntry = &pM2Data->mibIfTbl;    struct arpcom *   pArpcomEntry   = (struct arpcom *)pIfNetEntry;        sprintf (pM2IntTblEntry->ifDescr, "%s%d",                     pIfNetEntry->if_name, pIfNetEntry->if_unit);    if (!pM2IntTblEntry->ifSpecific.idLength)        {        memcpy (pM2IntTblEntry->ifSpecific.idArray, pIfIndexEntry->ifOid.idArray,            ((int) pIfIndexEntry->ifOid.idLength * sizeof (long)));        pM2IntTblEntry->ifSpecific.idLength = pIfIndexEntry->ifOid.idLength;        }    pM2IntTblEntry->ifMtu = pIfNetEntry->if_mtu;    /* If the device does not have a hardware address set it to zero */     if (pIfNetEntry->if_flags &                        (IFF_LOOPBACK | IFF_POINTOPOINT | IFF_NOARP))        {        memset(&(pM2IntTblEntry->ifPhysAddress), 0, sizeof(M2_PHYADDR));        }    else        {        bcopy (((char *) pArpcomEntry->ac_enaddr),              ((char *) pM2IntTblEntry->ifPhysAddress.phyAddress),                                                          ETHERADDRLEN);        pM2IntTblEntry->ifPhysAddress.addrLength = ETHERADDRLEN;        }    /* Get the ifAdminStatus, ifLastChange, and ifOperStatus  */    pM2IntTblEntry->ifAdminStatus = (((pIfNetEntry->if_flags & IFF_UP) != 0) ?                                     M2_ifAdminStatus_up :                                     M2_ifAdminStatus_down);    /*    pNetIf->netIfAdminStatus  = pIfReqEntry->ifAdminStatus;    pM2IntTblEntry->ifLastChange = pIfNetEntry->netIfLastChange;    */    pM2IntTblEntry->ifOperStatus = (((pIfNetEntry->if_flags & IFF_UP) != 0) ?                                    M2_ifOperStatus_up : M2_ifOperStatus_down);    if (pIfIndexEntry->mibStyle != TRUE)        {        pM2IntTblEntry->ifInUcastPkts  = pIfNetEntry->if_ipackets -                                         pIfNetEntry->if_imcasts;        pM2IntTblEntry->ifInNUcastPkts = pIfNetEntry->if_imcasts;        pM2IntTblEntry->ifInErrors     = pIfNetEntry->if_ierrors;        pM2IntTblEntry->ifOutUcastPkts = pIfNetEntry->if_opackets -                                         pIfNetEntry->if_omcasts;        pM2IntTblEntry->ifOutNUcastPkts= pIfNetEntry->if_omcasts;        pM2IntTblEntry->ifOutErrors    = pIfNetEntry->if_oerrors;	pM2IntTblEntry->ifOutQLen      = pIfNetEntry->if_snd.ifq_len;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -