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

📄 startup.c

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 C
📖 第 1 页 / 共 2 页
字号:
/* startup.c - RIP routines for creating initial data structures *//* Copyright 1984 - 1998 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. * @(#)startup.c	8.2 (Berkeley) 4/28/95 *//*modification history--------------------01h,11sep98,spm  provided fatal error handling in place of quit routine,                 replaced ripMakeAddr with optimized results (SPR #22350)01g,01sep98,spm  modified addrouteforif to correctly support interfaces                  with classless netmasks (SPR #22220); changed spacing                 for coding standards01f,26jul98,spm  moved assignment from conditional to avoid compiler warnings01e,06oct97,gnn  fixed SPR 9211 and added sendHook functionality01d,16may97,gnn  added code to initialize hooks to NULL.01c,07apr97,gnn  cleared up some of the more egregious warnings.                 added MIB-II interfaces and options.01b,24feb97,gnn  added rip version 2 functionality.01a,26nov96,gnn  created from BSD4.4 routed*//*DESCRIPTION*//* * Routing Table Management Daemon */#include "vxWorks.h"#include "rip/defs.h"#include "sys/ioctl.h"#include "net/if.h"#include "net/if_dl.h"#include "netinet/in.h"#include "stdlib.h"IMPORT int routedDebug;struct	interface *ripIfNet;struct	interface **ifnext = &ripIfNet;int	foundloopback;			/* valid flag for loopaddr */struct	sockaddr loopaddr;		/* our address on loopback */void addrouteforif(register struct interface *ifp);struct rt_addrinfo info;/* Sleazy use of local variables throughout file, warning!!!! */#define NETMASK	info.rti_info[RTAX_NETMASK]#define IFAADDR	info.rti_info[RTAX_IFA]#define BRDADDR	info.rti_info[RTAX_BRD]#define ROUNDUP(a) \	((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))voidrt_xaddrs(cp, cplim, rtinfo)	register caddr_t cp, cplim;	register struct rt_addrinfo *rtinfo;{	register struct sockaddr *sa;	register int i;	memset(rtinfo->rti_info, 0, sizeof(rtinfo->rti_info));	for (i = 0; (i < RTAX_MAX) && (cp < cplim); i++) {		if ((rtinfo->rti_addrs & (1 << i)) == 0)			continue;		rtinfo->rti_info[i] = sa = (struct sockaddr *)cp;		ADVANCE(cp, sa);	}}/********************************************************************************* routedIfInit - build a linked list of available interfaces** This routine searches the kernel's "ifnet" interface list for all* entries with family AF_INET and copies the relevant data to the* linked list entry used by the RIP session. If the kernel's list* contains any incomplete entries, the "lookforinterfaces" flag is* set to repeat the execution of this routine at the next timer* interval. The initial execution of this routine (during RIP * startup) must succeed or the session will not begin. The session* will continue regardless of the results of later executions used to * add new interfaces.** RETURNS: OK, or ERROR if unable to process interface table.** NOMANUAL** INTERNAL* All executions of this routine after the RIP session has started* occur within the context of the RIP timer task. They are protected* by the mutex semaphore to prevent any message processing while the * interface list is changed and any corresponding route entries are* created.*/STATUS routedIfInit (void)    {    struct interface ifs, *ifp;    size_t needed;    int mib[6], no_ipaddr = 0, flags = 0;    char *buf, *cplim, *cp;    register struct if_msghdr *ifm;    register struct ifa_msghdr *ifam;    struct sockaddr_dl *sdl;    struct sockaddr_in *sin;    u_long i;    IMPORT RIP ripState;    int splLevel = splnet();            ripState.lookforinterfaces = FALSE;    /*      * The sysctl_rtable routine provides access to internal networking data      * according to the specified operations. The NET_RT_IFLIST operator     * traverses the entire internal "ifnet" linked list created when the     * network devices are initialized. The third argument, when non-zero,     * restricts the search to a particular unit number. In this case, all     * devices are examined. The first argument, when non-zero, limits the     * addresses to the specified address family.      */    mib[0] = AF_INET;    mib[1] = NET_RT_IFLIST;    mib[2] = 0;    /*      * The first call to the routine determines the amount of space needed     * for the results. No data is actually copied.     */    if (sysctl_rtable(mib, 3, NULL, &needed, NULL, 0) < 0)        {        if (routedDebug)            logMsg ("Error %x estimating size of interface buffer.\n", errno,                    0, 0, 0, 0, 0);        splx (splLevel);        return (ERROR);        }    /*      * Allocate the required data, and repeat the system call to copy the     * actual values.     */    buf = malloc (needed);    if (buf == NULL)        {        if (routedDebug)            logMsg ("Error %x allocating interface buffer.\n", errno,                    0, 0, 0, 0, 0);        splx (splLevel);        return (ERROR);        }    if (sysctl_rtable(mib, 3, buf, &needed, NULL, 0) < 0)        {        if (routedDebug)            logMsg ("Error %x retrieving interface table.\n", errno,                    0, 0, 0, 0, 0);        splx (splLevel);        free (buf);        return (ERROR);        }    /* End of VxWorks specific stuff. */    /*      * Analyze the retrieved data. The provided buffer now contains a      * structure of type if_msghdr for each interface followed by zero      * or more structures of type ifa_msghdr for each address for that     * interface. The if_msghdr structures have type fields of     * RTM_IFINFO and the address structures have type fields of      * RTM_NEWADDR.     */    cplim = buf + needed;    for (cp = buf; cp < cplim; cp += ifm->ifm_msglen)         {        ifm = (struct if_msghdr *)cp;        if (ifm->ifm_type == RTM_IFINFO)             {            /* Parse the generic interface information. */            memset(&ifs, 0, sizeof(ifs));            ifs.int_flags = flags = (0xffff & ifm->ifm_flags) | IFF_INTERFACE;            if ( (flags & IFF_UP) == 0 || no_ipaddr)                ripState.lookforinterfaces = TRUE;            /*              * The sockaddr_dl structure containing the link-level address             * immediately follows the if_msghdr structure.             */            sdl = (struct sockaddr_dl *) (ifm + 1);            sdl->sdl_data[sdl->sdl_nlen] = 0;            no_ipaddr = 1;            continue;            }        /*          * Only address entries should be present at this point.         * Exit if an unknown type is detected.         */        if (ifm->ifm_type != RTM_NEWADDR)            {            if (routedDebug)                logMsg ("Unexpected entry in interface table.\n",                         0, 0, 0, 0, 0, 0);            splx (splLevel);            free (buf);            return (ERROR);            }        /*          * Ignore the address information if the interface initialization         * is incomplete. Set flag to repeat the search at the next timer          * interval.         */        if ( (flags & IFF_UP) == 0)            {            ripState.lookforinterfaces = TRUE;            continue;            }        /* Access the address information through the ifa_msghdr structure. */        ifam = (struct ifa_msghdr *)ifm;        /* Reset the pointers to access the address pointers. */        info.rti_addrs = ifam->ifam_addrs;        rt_xaddrs((char *)(ifam + 1), cp + ifam->ifam_msglen, &info);        if (IFAADDR == 0)             {            if (routedDebug)                logMsg ("No address for %s.\n", sdl->sdl_data, 0, 0, 0, 0, 0);            continue;            }        /* Copy and process the actual address values. */        ifs.int_addr = *IFAADDR;        if (ifs.int_addr.sa_family != AF_INET)            continue;        no_ipaddr = 0;        if (ifs.int_flags & IFF_POINTOPOINT)            {            if (BRDADDR == 0)    /* No remote address specified? */                {                if (routedDebug)                    logMsg ("No dstaddr for %s.\n", sdl->sdl_data,                             0, 0, 0, 0, 0);                continue;                }            if (BRDADDR->sa_family == AF_UNSPEC)

⌨️ 快捷键说明

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