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

📄 output.c

📁 VxWorks BSP框架源代码包含头文件和驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
/* output.c - routines for generating outgoing RIP messages *//* Copyright 1984 - 2003 Wind River Systems, Inc. */#include "copyright_wrs.h"/* * Copyright (c) 1983, 1988, 1993 *	The Regents of the University of California.  All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *	This product includes software developed by the University of *	California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors *    may be used to endorse or promote products derived from this software *    without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. *            @(#)output.c	8.2 (Berkeley) 4/28/95"; *//*modification history--------------------01n,14jan03,rae  Merged from velocecp branch (SPRs 36037/83475, 75867, 24518)01m,22mar02,niq  Merged from Synth view, tor3_x.synth branch, ver 01p01l,15oct01,rae  merge from truestack ver 01n, base 01i (VIRTUAL_STACK etc.)01k,21nov00,spm  fixed handling of interface for default route (SPR #62533)01j,10nov00,spm  merged from version 01j of tor3_x branch (SPR #33692 fix)01i,11sep98,spm  added option to disable gateway filtering and removed                 all references to bloated trace commands (SPR #22350)01h,01sep98,spm  extended gateway filtering tests to handle classless                  netmasks and host-specific routes01g,26jul98,spm  removed duplicate condition from test in supply routine;                 corrected stray pointer in ripBuildPacket call and added                 parameter needed for RIPv2 updates; removed compiler warnings01f,06oct97,gnn  added sendHook functionality to sending01e,08may97,gnn  fixed an authentication bug.01d,07apr97,gnn  cleared up some of the more egregious warnings.                 added MIB-II interface and option support.01c,13mar97,gnn  fixed a minor bug in the output routine01b,24feb97,gnn  added rip version 2 functionality01a,26nov96,gnn  created from BSD4.4 routed*//*DESCRIPTION*//* * Routing Table Management Daemon */#include "vxWorks.h"#include "logLib.h"#include "m2Lib.h"#include "rip/defs.h"#include "rip/m2RipLib.h"#ifdef VIRTUAL_STACK#include "netinet/vsLib.h"#include "netinet/vsRip.h"#elseIMPORT int routedDebug;IMPORT BOOL ripFilterFlag;#endifIMPORT void ripSockaddrPrint (struct sockaddr * pSockAddr);/* * Apply the function "f" to all non-passive * interfaces.  If the interface supports the * use of broadcasting use it, otherwise address * the output to the known router. */void toall(f, rtstate, skipif)	int (*f)();	int rtstate;	struct interface *skipif;{	register struct interface *ifp;	register struct sockaddr *dst;	register int flags;#ifndef VIRTUAL_STACK	extern struct interface *ripIfNet;#endif	for (ifp = ripIfNet; ifp; ifp = ifp->int_next)            {            if (ifp->int_flags & IFF_PASSIVE || ifp == skipif ||                 (ifp->int_flags & IFF_UP) == 0)                continue;            dst = ifp->int_flags & IFF_BROADCAST ? &ifp->int_broadaddr :                ifp->int_flags & IFF_POINTOPOINT ? &ifp->int_dstaddr :                &ifp->int_addr;            flags = ifp->int_flags & IFF_INTERFACE ? MSG_DONTROUTE : 0;                        if (f == supply)                (*f)(dst, flags, ifp, rtstate, 0);            else                (*f)(dst, flags, ifp, rtstate);	}}/***************************************************************************  *  * ripRequestSend - send REQUEST message through a given interface *  * This function forms and sends an RIP REQUEST message through a * given interface. It can be called to solicite RIP information from * the neighboring RIP nodes whenever an interface becomes ready. * * RETURNS: OK; or ERROR, if the specified interface cannot be found. * */STATUS ripRequestSend    (    u_short ifIndex           /* index of the interface */    )     {     register struct interface * pIfp;     register struct sockaddr * pDst;     register int flags;#ifndef VIRTUAL_STACK    extern struct interface * ripIfNet;    extern RIP    ripState;#endif    register RIP_PKT * pQuery;    if (ripIfNet == NULL)        {        if (routedDebug)            logMsg ("ripRequestSend (): error - ripIfNet is NULL.\n",                     0, 0, 0, 0, 0, 0);        return (ERROR);        }    pQuery = (RIP_PKT *)ripState.packet;    for (pIfp = ripIfNet; pIfp && pIfp->int_index != ifIndex;          pIfp = pIfp->int_next);    if (pIfp == NULL)        {        if (routedDebug)            logMsg ("ripRequestSend (): cannot find ifIndex %d.\n",                     ifIndex, 0, 0, 0, 0, 0);        return (ERROR);        }    if (pIfp->int_flags & IFF_PASSIVE || (pIfp->int_flags & IFF_UP) == 0)        return (OK);        pDst = pIfp->int_flags & IFF_BROADCAST ? &pIfp->int_broadaddr :           pIfp->int_flags & IFF_POINTOPOINT ? &pIfp->int_dstaddr :           &pIfp->int_addr;    flags = pIfp->int_flags & IFF_INTERFACE ? MSG_DONTROUTE : 0;    pQuery->rip_cmd = RIPCMD_REQUEST;    pQuery->rip_vers = ripState.version;    pQuery->rip_nets[0].rip_dst.sa_family = htons ((u_short)AF_UNSPEC);    pQuery->rip_nets[0].rip_metric = htonl ((u_long)HOPCNT_INFINITY);    if (routedDebug)        {        logMsg ("ripRequestSend (): calling sndmsg() with pDst: \n",                 0,0,0,0,0,0);        ripSockaddrPrint (pDst);        }    sndmsg (pDst, flags, pIfp, 0);        return (OK);    }/* * Output a preformed packet. *//*ARGSUSED*/STATUS sndmsg(dst, flags, ifp, rtstate)	struct sockaddr *dst;	int flags;	struct interface *ifp;	int rtstate;{#ifndef VIRTUAL_STACK        IMPORT RIP ripState;#endif	(*afswitch[dst->sa_family].af_output)(ripState.s, flags,		dst, sizeof (RIP_PKT));       if (routedDebug > 2)           logMsg ("Transmitting RIP message.\n", 0, 0, 0, 0, 0, 0);        return (OK);}/* * Supply dst with the contents of the routing tables. * If this won't fit in one packet, chop it up into several. */STATUS supply    (    struct sockaddr *dst,    int flags,    register struct interface *ifp,    int rtstate,    int version    )    {#ifndef VIRTUAL_STACK    IMPORT RIP ripState;#endif    register struct rt_entry *rt;    register struct netinfo *pNetinfo = ripState.msg->rip_nets;    register struct rthash *rh;    struct rthash *base = hosthash;    int doinghost = 1;    UINT size;    int (*output)() = afswitch[dst->sa_family].af_output;    int (*sendroute)() = afswitch[dst->sa_family].af_sendroute;    int npackets = 0;    struct interface* pIfp;#ifdef RIP_MD5    RIP2_AUTH_PKT_HDR * pAuthHdr;    RIP_AUTH_KEY * pAuthKey;#endif /* RIP_MD5 */    ripState.msg->rip_cmd = RIPCMD_RESPONSE;        if (ifp == NULL)        pIfp = ripIfLookup(dst);    else        pIfp = ifp;        if (pIfp == NULL)        return (ERROR);         /*      * Check actual interface status before transmitting      * The interface might have been disabled.       */     if ((pIfp->int_flags & IFF_UP) == 0)         return (ERROR);    /*     * Next, check the status from the MIB-II RIP group. If this     * interface has been turned off then silently drop packets on it.     */    if (pIfp->ifConf.rip2IfConfStatus != M2_rip2IfConfStatus_valid)

⌨️ 快捷键说明

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