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

📄 tables.c

📁 This is a source code of VxWorks
💻 C
📖 第 1 页 / 共 3 页
字号:
                        rt->rt_subnets_cnt - 1, TRUE,                         rt->rt_ifp->int_subnetmask);            }        }    free ((char *)rt);        return (OK);    }void rtdeleteall (void)    {    register struct rthash *rh;    register struct rt_entry *rt;    struct rthash *base = hosthash;    int doinghost = 1;        char address[32];    struct sockaddr_in *pDsin;    struct sockaddr_in *pGsin;    struct sockaddr_in *pNsin;    again:    for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++)        {        rt = rh->rt_forw;	for (; rt != (struct rt_entry *)rh;                  rt = ( (struct rt_entry *)rh)->rt_forw)            {            /* Remove the entry from the kernel routing table if present. */            if ( (rt->rt_state & (RTS_INTERNAL|RTS_EXTERNAL|RTS_OTHER)) == 0)                {                ripRouteToAddrs (rt, &pDsin, &pGsin, &pNsin);                inet_ntoa_b (pDsin->sin_addr, (char *)&address);                /*                 * Expired route entries were already removed from the kernel                 * routing table, but may remain in the RIP routing table                 * if the garbage collection interval has not passed.                  * These entries are usually detectable by their infinite                  * metric, but all metrics are infinite in this case.                 * However, the pointer to the kernel route will be                 * NULL, so the following call will not attempt to                 * delete a (non-existent) expired entry.                 */                if (rt->inKernel)                    {                    if (ripSystemRouteDelete (pDsin->sin_addr.s_addr,                                               pGsin->sin_addr.s_addr,                                               pNsin->sin_addr.s_addr,                                               0) == ERROR)                        {                        if (routedDebug)                             logMsg ("Error %x removing route from kernel table.\n",                                     errno, 0, 0, 0, 0, 0);                        }                    else                        {                        rt->inKernel = FALSE;                        ripState.ripGlobal.rip2GlobalRouteChanges++;                        }                    }                }            /* Remove the entry from the RIP routing table. */            ((struct rt_entry *)rh)->rt_forw = rt->rt_forw;            free ((char *)rt);            }        }    if (doinghost)        {        doinghost = 0;        base = nethash;        goto again;        }    return;    }/* * If we have an interface to the wide, wide world, * add an entry for an Internet default route (wildcard) to the internal * tables and advertise it.  This route is not added to the kernel routes, * but this entry prevents us from listening to other people's defaults * and installing them in the kernel here. */void rtdefault (void)    {    rtadd ( (struct sockaddr *)&inet_default, (struct sockaddr *)&inet_default,            1, RTS_CHANGED | RTS_PASSIVE | RTS_INTERNAL, NULL,            M2_ipRouteProto_rip, 0, 0, NULL);    }void routedTableInit (void)    {    register struct rthash *rh;        for (rh = nethash; rh < &nethash[ROUTEHASHSIZ]; rh++)        rh->rt_forw = rh->rt_back = (struct rt_entry *)rh;    for (rh = hosthash; rh < &hosthash[ROUTEHASHSIZ]; rh++)        rh->rt_forw = rh->rt_back = (struct rt_entry *)rh;    }/******************************************************************************** ripSystemRouteAdd - add a RIP route to the system routing database** This routine adds the route to the system routing database using the* method which the particular product supports.** RETURNS: ERROR or OK (return value from selected add method)** ERRNO: N/A** NOMANUAL*/LOCAL STATUS ripSystemRouteAdd     (    long             dstIp,    	/* destination address, network order */    long             gateIp,    	/* gateway address, network order */    long             mask,      	/* mask for destination, network order */    int              flags      	/* route flags */     )    {#ifdef ROUTER_STACK    ROUTE_DESC		routeDesc;    struct sockaddr_in	dstAddr;    struct sockaddr_in	netmask;    struct sockaddr_in	gateway;    /* Initialize the routeDesc structure and the sockaddr structures */    bzero ((char *)&routeDesc, sizeof (routeDesc));    routeDesc.pDstAddr = (struct sockaddr *)&dstAddr;    routeDesc.pNetmask = (struct sockaddr *)&netmask;    routeDesc.pGateway = (struct sockaddr *)&gateway;    bzero ((char *)&dstAddr, sizeof (struct sockaddr_in));    bzero ((char *)&netmask, sizeof (struct sockaddr_in));    bzero ((char *)&gateway, sizeof (struct sockaddr_in));    dstAddr.sin_len = sizeof (struct sockaddr_in);    netmask.sin_len = sizeof (struct sockaddr_in);    gateway.sin_len = sizeof (struct sockaddr_in);    dstAddr.sin_family = AF_INET;    netmask.sin_family = AF_INET;    gateway.sin_family = AF_INET;    dstAddr.sin_addr.s_addr = dstIp;    netmask.sin_addr.s_addr = mask;    gateway.sin_addr.s_addr = gateIp;    routeDesc.flags = flags;    routeDesc.protoId = M2_ipRouteProto_rip;    /*      * If it is a host route, set netmask to NULL. RIP internally     * assigns a host route the netmask of the interface. But the system     * expect a NULL or all zero's netmask.     */    if (flags & RTF_HOST)        routeDesc.pNetmask = NULL;    /* Now add the route */    return (routeEntryAdd (&routeDesc));#else    /*      * If it is a host route, set netmask to NULL. RIP internally     * assigns a host route the netmask of the interface. But the system     * expect a NULL netmask     */    if (flags & RTF_HOST)        mask = 0;    return (mRouteEntryAdd (dstIp, gateIp, mask, 0, flags,                             M2_ipRouteProto_rip));#endif /* ROUTER_STACK */    }/******************************************************************************** ripSystemRouteDelete - delete a RIP route from the system routing database** This routine deletes a route from the system routing database using the* method which the particular product supports.** RETURNS: ERROR or OK (return value from selected delete method)** ERRNO: N/A** NOMANUAL*/LOCAL STATUS ripSystemRouteDelete     (    long		dstIp,    	/* destination address, network order */    long		gateIp,    	/* gateway address, network order */    long		mask,      	/* mask for destination, network order */    int		flags      	/* route flags */     )    {#ifdef ROUTER_STACK    ROUTE_DESC		routeDesc;    struct sockaddr_in	dstAddr;    struct sockaddr_in	netmask;    struct sockaddr_in	gateway;    /* Initialize the routeDesc structure and the sockaddr structures */    bzero ((char *)&routeDesc, sizeof (routeDesc));    routeDesc.pDstAddr = (struct sockaddr *)&dstAddr;    routeDesc.pNetmask = (struct sockaddr *)&netmask;    routeDesc.pGateway = (struct sockaddr *)&gateway;    bzero ((char *)&dstAddr, sizeof (struct sockaddr_in));    bzero ((char *)&netmask, sizeof (struct sockaddr_in));    bzero ((char *)&gateway, sizeof (struct sockaddr_in));    dstAddr.sin_len = sizeof (struct sockaddr_in);    netmask.sin_len = sizeof (struct sockaddr_in);    gateway.sin_len = sizeof (struct sockaddr_in);    dstAddr.sin_family = AF_INET;    netmask.sin_family = AF_INET;    gateway.sin_family = AF_INET;    dstAddr.sin_addr.s_addr = dstIp;    netmask.sin_addr.s_addr = mask;    gateway.sin_addr.s_addr = gateIp;    routeDesc.flags = flags;    routeDesc.protoId = M2_ipRouteProto_rip;    /*      * If it is a host route, set netmask to NULL. RIP internally     * assigns a host route the netmask of the interface. But the system     * expect a NULL or all zero's netmask.     */    if (flags & RTF_HOST)        routeDesc.pNetmask = NULL;    /* Now delete the route */    return (routeEntryDelete (&routeDesc));#else    /*      * If it is a host route, set netmask to NULL. RIP internally     * assigns a host route the netmask of the interface. But the system     * expect a NULL or all zero's netmask.     */    if (flags & RTF_HOST)        mask = 0;    return (mRouteEntryDelete (dstIp, gateIp, mask, 0, flags,                                M2_ipRouteProto_rip));#endif /* ROUTER_STACK */    }/******************************************************************************** ripRouteMetricSet - Set the metric for the RIP route** This routine changes the metric of the RIP route that is kept in the* system Routing database.* The parameter <pRtEntry> describes the RIP route that is kept in RIP's* private database. It also contains the metric value that is to be set.** This routine calls the routing extensions function routeMetricSet() * to set the metric** RETURNS: N/A** ERRNO: N/A** NOMANUAL*/void ripRouteMetricSet     (    struct rt_entry *	pRtEntry	/* Route entry describing the */    					/* Kernel route to update */    )    {    struct sockaddr_in * pDsin;    struct sockaddr_in * pGsin;    struct sockaddr_in * pNsin;        /*     * Retrieve the destination and netmask values from the     * corresponding fields in the RIP route entry structure     */    ripRouteToAddrs (pRtEntry, &pDsin, &pGsin, &pNsin);    /*      * If it is a host route, set netmask to NULL. RIP internally     * assigns a host route the netmask of the interface. But the system     * overrides that and stores the route as a host route with a NULL mask.     * (which is the right thing to do). So we set the netmask field to     * NULL so that the route lookup happens fine.     */    if (pRtEntry->rt_flags & RTF_HOST)        pNsin = NULL;    if (routedDebug > 2)        {        logMsg ("ripRouteMetricSet: setting new metric = %d for\n",                 pRtEntry->rt_metric , 0, 0, 0, 0, 0);        ripSockaddrPrint ((struct sockaddr *)pDsin);        ripSockaddrPrint ((struct sockaddr *)pNsin);        ripSockaddrPrint ((struct sockaddr *)pGsin);        }    /* Now set the route metric */    if (routeMetricSet ((struct sockaddr *)pDsin, (struct sockaddr *)pNsin,                        M2_ipRouteProto_rip, pRtEntry->rt_metric) == ERROR)         {        if (routedDebug)             logMsg ("Couldn't set metric for rtEntry = %x.\n", (int)pRtEntry, 0,                     0, 0, 0, 0);        }    }/******************************************************************************* ripInsque - insert node in list after specified node.** Portable version of _insque ().** NOMANUAL*/ LOCAL void ripInsque    (    NODE *pNode,    NODE *pPrev    )    {    NODE *pNext;     pNext = pPrev->next;    pPrev->next = pNode;    pNext->previous = pNode;    pNode->next = pNext;    pNode->previous = pPrev;    } /******************************************************************************* ripRemque - remove specified node in list.** Portable version of _remque ().** NOMANUAL*/ LOCAL void ripRemque     (    NODE *	pNode	/* Node to remove */    )    {    pNode->previous->next = pNode->next;    pNode->next->previous = pNode->previous;    }

⌨️ 快捷键说明

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