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

📄 usrnetwork.c

📁 一个VXWORKS的网络驱动原代码
💻 C
📖 第 1 页 / 共 5 页
字号:
        pNetDev = params.bootDev;        printf ("Attaching network interface %s%d... ",		 params.bootDev, params.unitNum);	bootNetmaskExtract (params.ead, &netmask); /* remove and ignore mask */	/* XXX last octet of 'ead' == procNum */	if (ulipInit (params.unitNum, params.ead, params.had, params.procNum)		 == ERROR)	    {	    if (errno == S_if_ul_NO_UNIX_DEVICE)		printf ("\nulipInit failed, errno = S_if_ul_NO_UNIX_DEV\n");	    else		printf ("\nulipInit failed, errno = 0x%x\n", errno);	    return (ERROR);	    }	printf ("done.\n");	}    else#endif  /* INCLUDE_ULIP */    if (strncmp (params.bootDev, "ppp", 3) == 0)        {        /*         * Booting via ppp completely configures the device.         * No automatic DHCP/BOOTP address assignment (not broadcast capable).         */        pNetDev = params.bootDev;        if (usrPPPInit (params.bootDev, params.unitNum, params.ead,		        ((params.gad[0] == EOS)? params.had : params.gad))		== ERROR)	    {	    NET_DIAG(("usrPPPInit() returned errno = 0x%x\n", errno));            return (ERROR);	    }        }    else if (strncmp (params.bootDev, "sl", 2) == 0)	{	/*	 * Booting via slip completely configures the device.	 * No automatic DHCP/BOOTP address assignment (not broadcast capable).	 */	pNetDev = params.bootDev;	if (usrSlipInit (params.bootDev, params.unitNum, params.ead,			 ((params.gad[0] == EOS)? params.had : params.gad))	    == ERROR)	    {	    NET_DIAG(("usrSlipInit() returned errno = 0x%x\n", errno));	    return (ERROR);	    }	}    else if ((strncmp (params.bootDev, "bp", 2) == 0) ||            (strncmp (params.bootDev, "sm", 2) == 0))	{        pNetDev = params.bootDev;	backplaneBoot = TRUE;	if (usrBpInit (params.bootDev, params.unitNum, 0) == ERROR)	    {	    NET_DIAG(("usrBpInit() returned errno = 0x%x\n", errno));	    return (ERROR);	    }        /*         * Booting via backplane: protocol attachment is still required         * and automatic configuration with DHCP or BOOTP is supported.         */        attachFlag = TRUE;	}    else	{        if ((strncmp (params.bootDev, "scsi", 4) == 0) ||            (strncmp (params.bootDev, "ide", 3) == 0) ||	    (strncmp (params.bootDev, "ata", 3) == 0) ||	    (strncmp (params.bootDev, "fd", 2) == 0)  ||	    (strncmp (params.bootDev, "tffs", 4) == 0))	    {	    /* booting from disk, configure network if requested */	    if (params.other [0] != EOS)		{		char *pStr;		int unit;		/*		 * Protocol attachment is required and automatic		 * configuration with DHCP or BOOTP is supported		 * for all these network devices.		 */		attachFlag = TRUE;        		/*		 * Fix up the unitNum correctly. If the boot device		 * was specified in the other field, we need to derive		 * the unit number from here, rather than the one		 * derived from bootDev, since bootDev was a disk		 * device of some kind.		 */		pStr = (char *)&params.other;		while (!isdigit (*pStr) && *pStr != EOS)		    pStr++;		if (*pStr != EOS && sscanf (pStr, "%d", &unit) == 1)		    {		    params.unitNum = unit;		    *pStr = EOS;		    }		pNetDev = params.other;                }	    }	else	    {            pNetDev = params.bootDev;            /*             * Booting via network: protocol attachment is required and             * automatic configuration with DHCP or BOOTP is supported             * for all these network devices.             */            attachFlag = TRUE;            }        }    if (attachFlag)        {        /*         * Attempt to attach and setup the network boot device         * (which is capable of automatic configuration).         */        BOOL attached = FALSE;        netmask = 0;        bootNetmaskExtract (pBootString, &netmask);#ifdef INCLUDE_END        /* Check for the END driver, if any. */        pEnd = endFindByName (pNetDev, params.unitNum);        if (pEnd == NULL && *params.other)	    /* Couldn't find the bootrom's device, try the "other" */            pEnd = endFindByName (pNetDev=params.other, params.unitNum);        if (pEnd == NULL)	    {	    /* muxLib.c drags in printf anyway */            printf("Can't find END device <%s> unit <%d>.  Known devices are\n",		   pNetDev, params.unitNum);	    /* muxShow() is in muxLib.c and not separately scalable */	    muxShow(NULL, 0);	    }        else            {            if (ipAttach(params.unitNum, pNetDev) != OK)		{		logMsg ("Failed to attach to device <%s> unit <%d>\n",		        (int)pNetDev, params.unitNum, 0, 0, 0, 0);		return (ERROR);		}            attached = TRUE;            }#endif /*INCLUDE_END*/#ifdef INCLUDE_BSD        if (!attached)            {            if ( (usrNetIfAttach (pNetDev, params.unitNum, pBootString) !=OK))		{		NET_DIAG(("usrNetIfAttach() returned errno = 0x%x\n", errno));		return (ERROR);		}            attached = TRUE;            }#endif /*INCLUDE_BSD*/        if (!attached)	    {	    printf("Couldn't attach to network\n");            return (ERROR);	    }        printf ("Attached TCP/IP interface to %s unit %d\n", pNetDev,		params.unitNum);        }    /* add loop-back interface */    usrNetIfAttach ("lo", 0, "127.0.0.1");    usrNetIfConfig ("lo", 0, "127.0.0.1", "localhost", 0);    /* Attempt to retrieve a target IP address if it is not available. */#ifdef INCLUDE_DHCPC    if (dhcpcLibInit (DHCPC_SPORT, DHCPC_CPORT, DHCPC_MAX_LEASES,		      DHCPC_MAX_MSGSIZE, DHCPC_OFFER_TIMEOUT,		      DHCPC_DEFAULT_LEASE, DHCPC_MIN_LEASE) == ERROR)        return (ERROR);#ifdef INCLUDE_NET_SHOW    dhcpcShowInit ();#endif    /*     * Renew or obtain a lease as needed and store values in boot line.     * If successful, the pDhcpcBootCookie global is set to allow user     * access to the lease and the timing information is stored in the     * dhcpcBootLease global for later use.     */    if (dhcpcConfigSet (&params, pBootString, &netmask, &dhcpBoot, attachFlag) == ERROR)        return (ERROR);#endif   /* INCLUDE_DHCPC */    /* If autoconf is requested for "other" device try BOOTP */    if (pNetDev == params.other && sysFlags & SYSFLG_AUTOCONFIG)	{        sprintf(devName, "%s%d", pNetDev, params.unitNum);        bootpGet (devName, params.ead, params.bootFile,            params.had, &netmask, params.gad);        bootStructToString (BOOT_LINE_ADRS, &params);	}    /* Configure the network device using the address/mask information. */    if (attachFlag && (usrNetIfConfig (pNetDev, params.unitNum, pBootString,		        params.targetName, netmask) != OK))        return (ERROR);    /* attach backplane interface (as second interface) */#ifdef INCLUDE_SM_NET#define BP_ADDR_GIVEN	        (params.bad [0] != EOS)#define BP_ADDR_NOT_GIVEN	(params.bad [0] == EOS)    if ( !backplaneBoot )	{    	char 		*bpDev;    	BOOL	        proxyOn = FALSE;       /* Initialize Defaults */	u_long          startAddr = 0;         /* Default sequential Addr off */	char            netDev [BOOT_DEV_LEN + 1];	BOOL            seqAddrOn = FALSE;	BOOL            configureBp = TRUE;	BOOL            useEtherAddr = FALSE;		                             /* Turn switches ON as needed */#ifdef INCLUDE_SM_SEQ_ADDR	seqAddrOn = TRUE;#endif#ifdef INCLUDE_PROXY_DEFAULT_ADDR	useEtherAddr = TRUE;#endif#ifdef INCLUDE_PROXY_SERVER	proxyOn = TRUE;#endif        bpDev = "sm";        sprintf(netDev, "%s", "sm0");	bootNetmaskExtract (params.bad, &proxymask);	if (proxyOn == TRUE)	    {	    if (seqAddrOn == TRUE)   /* PROXY WITH SEQ ADDR */	        {	        /* Pick address from backplane or ethernet */		if (BP_ADDR_GIVEN)	   	    {	    	     startAddr = ntohl (inet_addr (params.bad));	    	     netmask = proxymask;	   	    }		else if (sysProcNumGet () == 0)		    {		    /*		     * The shared memory master calculates the next available		     * address, if possible. Slaves will read it directly.		     */		    if ( useEtherAddr )			{	    	    	startAddr = ntohl (inet_addr (params.ead)) + 1;		        netmask = 0xffffffff;			}		    else		/* Configuration error */		       {		       printf ("Error: No address for proxy service.\n");		       printf ("Backplane IP Address must be specified.\n");		       configureBp = FALSE;		       }		    }		}	    else                     /* PROXY WITHOUT SEQ ADDR */		{		if (BP_ADDR_NOT_GIVEN)		    {		    if (sysProcNumGet () == 0)		        configureBp = FALSE;    /* Can't start master. */		    }		else		    {   /* startAddr is left as zero */	    	    netmask = proxymask;		    }	        }	    }	else	    {		/* Using Subnet without PROXY Arp */	    if (BP_ADDR_GIVEN)	        {	        if (seqAddrOn == TRUE)	            {    /* Assign sequential address to backplane */	    	    startAddr = ntohl (inet_addr (params.bad));		    }	    	netmask = proxymask;		}            else if (sysProcNumGet () == 0)		{		/* Don't start the master if the backplane address is empty. */		configureBp = FALSE;		}	    }	if (configureBp == TRUE)	    {	    if (usrBpInit (bpDev, 0, startAddr) == ERROR)	    	return (ERROR);	    (void) usrNetIfAttach (bpDev, 0, params.bad);	    /* Assigned Back Plane Address if needed */	    if ((BP_ADDR_NOT_GIVEN) &&		 (smNetInetGet (netDev, params.bad, NONE) == OK))		 printf ("Backplane address: %s\n", params.bad);	    (void) usrNetIfConfig (bpDev, 0, params.bad,		                   (char *) NULL, netmask);	    }	}#ifdef INCLUDE_DHCPC    if (backplaneBoot)        {        if ((sysFlags & SYSFLG_AUTOCONFIG) && !(sysFlags & SYSFLG_PROXY))            {            printf ("Warning! DHCP over backplane may need proxy arp.\n");            }        }#endif /* INCLUDE_DHCPC */#ifdef INCLUDE_SM_NET_SHOW    smNetShowInit ();#endif /* INCLUDE_SM_NET_SHOW */#endif /* INCLUDE_SM_NET */    if (sysFlags & SYSFLG_PROXY)        {#ifdef INCLUDE_PROXY_CLIENT        printf ("registering proxy client %s...", pBootString);        devName [0] = EOS;        sprintf(devName, "%s%d", params.bootDev, params.unitNum);        if (proxyReg (devName, pBootString) == ERROR)            {            printf ("failed: error %x\n", errno);            return (ERROR);            }        printf ("done.\n");#else /* INCLUDE_PROXY_CLIENT */        printf ("proxy client requested but not included.\n");        return (ERROR);#endif /* INCLUDE_PROXY_CLIENT */        }#ifdef INCLUDE_PROXY_SERVER#ifndef INCLUDE_SM_NET    /* Remove netmask from address if not already done. */    bootNetmaskExtract (params.bad, &proxymask);#endif    if ((sysProcNumGet () == 0) && (params.bad [0] != EOS) &&        (params.ead [0] != EOS))        {        hashLibInit ();                 /* make sure hash functions init'd */        if (proxyArpLibInit (8, 8) == ERROR)	    NET_DIAG(("Unable to initialize proxy server.\n"));        else	    {            printf ("Creating proxy network: %s\n", params.bad);            if (proxyNetCreate (params.bad, params.ead) == ERROR)                {                printf ("proxyNetCreate failed:%x\n", errno);                return (ERROR);                }            }

⌨️ 快捷键说明

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