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

📄 routecommonlib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    if (pGateway)    /* Set gateway to zero if not specified. */        bcopy ( (char *)pGateway, (char *)&gateway, sizeof (struct sockaddr));    else        bzero ( (char*)&gateway, sizeof (struct sockaddr));    routeDesc.pDstAddr = &dstAddr;    routeDesc.pNetmask = pNetMask;    routeDesc.pGateway = &gateway;    routeDesc.flags = flags;    routeDesc.protoId = protoId;    /*     * Use the correct netmask for a host specific route. The rtinit()     * routine supplies the interface's mask instead of this value.     */    if (flags & RTF_HOST)        routeDesc.pNetmask = 0;    /*     * Delete the matching route. If successful, the descriptor contains     * the actual destination (generated from the netmask), matching gateway,     * and all the metric values and additional information from the deleted     * route entry. It also includes a flag setting which indicates whether     * the deleted route was a duplicate entry.     */    result = _routeEntryDel (&routeDesc, ppRouteEntry);    if (result == ERROR)        return (result);    /* Announce the route deletion to any registered users, if appropriate. */    if (notifyFlag)        routeCallBackSend (ROUTE_DEL, &routeDesc);    /*     * Save the routing protocol's identifier in the gateway address     * for any routing socket message.     */    RT_PROTO_SET(&gateway, protoId);    /*     * Transmit a routing socket message. This operation might occur     * within the preceding delete routine if it is limited to     * representative nodes which the routing sockets are currently     * able to modify.     */    if (socketFlag)    /* Transmit routing socket message? */        {        routeSocketMessageSend (RTM_DELETE, &routeDesc);        }    /* XXX: should it return ERROR if a message isn't sent? */    return (OK);#else                                   /* Host version */    return (rtrequest((int)RTM_DELETE, pDstAddr, pGateway, pNetMask,flags,                      (struct rtentry **)ppRouteEntry));#endif ROUTER_STACK    }/******************************************************************************** routeAgeSet - Set the age of the route entry** This routine searches the routing table for an entry which matches the* specified destination address. (For a Router stack, the protocol ID* is also checked for a match; it is ignored for a Host stack).* If the netmask is specified, the selected route also matches that value.** Once a route is chosen, this routine sets the route age to the value* specified by <newTime>.** RETURNS: OK if a route is found and time set, or ERROR otherwise.** NOMANUAL** INTERNAL: This routine is currently called only by RIP*/STATUS routeAgeSet    (    struct sockaddr *	pDstAddr,	/* Destination address */    struct sockaddr *	pNetmask,	/* Netmask */    int			protoId,	/* Protocol ID */    int			newTime		/* New time to set */    )    {    int s;#ifndef ROUTER_STACK    register struct rtentry *	pRoute;    struct radix_node_head *	rnh;    /* First validate the parameters */    if (pDstAddr == NULL)        return (ERROR);    s = splnet ();    if ((rnh = rt_tables[pDstAddr->sa_family]) == 0)         {        splx (s);        return (ERROR);        }    if (pNetmask)	{	in_socktrim ((struct sockaddr_in *)pNetmask);	TOS_SET (pNetmask, 0x1f);	}    if ((pRoute = (struct rtentry *) rnh->rnh_lookup(pDstAddr,                                                      pNetmask, rnh)))            pRoute->rt_refcnt++;#else    ROUTE_ENTRY * 		pRoute;    /* Matching route, if any. */    ULONG 			netmask;    ULONG * 			pMask;    /* First validate the parameters */    if (pDstAddr == NULL || protoId == 0)        return (ERROR);    if (pNetmask)        {        netmask = ((struct sockaddr_in *)(pNetmask))->sin_addr.s_addr;        pMask = &netmask;        }    else        pMask = NULL;    s = splnet ();    semTake (routeTableLock, WAIT_FOREVER);    pRoute = routeLookup (pDstAddr, pMask, protoId);    semGive (routeTableLock);#endif /* ROUTER_STACK */    splx (s);    if (pRoute == NULL)        return (ERROR);    /* Now set the age of the route */    #ifdef ROUTER_STACK    pRoute->rtEntry.rt_mod = newTime;#else    pRoute->rt_mod = newTime;#endif /* ROUTER_STACK */    /* Release the reference when finished. */    s = splnet ();    rtfree ( (struct rtentry *)pRoute);    splx (s);    return (OK);    }/******************************************************************************** routeMetricSet - Set the metric for the specified route entry** This routine searches the routing table for an entry which matches the* specified destination address. (For a Router stack, the protocol ID* is also checked for a match; it is ignored for a Host stack).* If the netmask is specified, the selected route also matches that value.** Once a route is chosen, this routine sets the route metric to the value* specified by <metric>.** RETURNS: OK if a route is found and time set, or ERROR otherwise.** NOMANUAL** INTERNAL: This routine is currently called only by RIP*/STATUS routeMetricSet    (    struct sockaddr *	pDstAddr,	/* Destination address */    struct sockaddr *	pNetmask,	/* Netmask */    int			protoId,	/* Protocol ID */    int			metric		/* metric to set */    )    {    int s;#ifndef ROUTER_STACK    register struct rtentry *	pRoute;    struct radix_node_head *	rnh;    /* First validate the parameters */    if (pDstAddr == NULL)        return (ERROR);    s = splnet ();    if ((rnh = rt_tables[pDstAddr->sa_family]) == 0)         {        splx (s);        return (ERROR);        }    if (pNetmask)	{	in_socktrim ((struct sockaddr_in *)pNetmask);	TOS_SET (pNetmask, 0x1f);	}    if ((pRoute = (struct rtentry *) rnh->rnh_lookup(pDstAddr,                                                      pNetmask, rnh)))            pRoute->rt_refcnt++;#else    ROUTE_ENTRY * 		pRoute;    /* Matching route, if any. */    ULONG 			netmask;    ULONG * 			pMask;    /* First validate the parameters */    if (pDstAddr == NULL || protoId == 0)        return (ERROR);    if (pNetmask)        {        netmask = ((struct sockaddr_in *)(pNetmask))->sin_addr.s_addr;        pMask = &netmask;        }    else        pMask = NULL;    s = splnet ();    semTake (routeTableLock, WAIT_FOREVER);    pRoute = routeLookup (pDstAddr, pMask, protoId);    semGive (routeTableLock);#endif /* ROUTER_STACK */    splx (s);    if (pRoute == NULL)        return (ERROR);    /* Now set the metric of the route */    #ifdef ROUTER_STACK    pRoute->rtEntry.rt_rmx.rmx_hopcount = metric;#else    pRoute->rt_rmx.rmx_hopcount = metric;#endif /* ROUTER_STACK */    /* Release the reference when finished. */    s = splnet ();    rtfree ( (struct rtentry *)pRoute);    splx (s);    return (OK);    }

⌨️ 快捷键说明

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