📄 usrnetwork.c.bak
字号:
#ifdef INCLUDE_DHCPS
STATUS dhcpsResult;
#endif
#ifdef INCLUDE_DHCPR
#ifndef INCLUDE_DHCPS /* Server is superset of relay agent. */
STATUS dhcprResult;
#endif
#endif
#ifdef INCLUDE_END
int count;
END_TBL_ENTRY* pDevTbl;
END_OBJ* pCookie = NULL;
END_OBJ* pEnd;
#endif /* INCLUDE_END */
BOOL backplaneBoot = FALSE;
BOOL attachFlag = FALSE; /* Device configuration required? */
/* interpret boot command */
if (bootString == NULL)
bootString = BOOT_LINE_ADRS;
if (usrBootLineCrack (bootString, ¶ms) != OK)
return (ERROR);
/* fill in any default values specified in configAll */
if ((params.hostName [0] == EOS) && /* host name */
(strcmp (HOST_NAME_DEFAULT, "") != 0))
{
strncpy (params.hostName, HOST_NAME_DEFAULT, BOOT_HOST_LEN);
printf ("Host Name: %s \n", params.hostName);
}
if ((params.targetName [0] == EOS) && /* targetname */
(strcmp (TARGET_NAME_DEFAULT, "") != 0))
{
strncpy (params.targetName, TARGET_NAME_DEFAULT, BOOT_HOST_LEN);
printf ("Target Name: %s \n", params.targetName);
}
if ((params.usr [0] == EOS) && /* user name (u) */
(strcmp (HOST_USER_DEFAULT, "") != 0))
{
strncpy (params.usr, HOST_USER_DEFAULT, BOOT_USR_LEN);
printf ("User: %s \n", params.usr);
}
if ((params.startupScript [0] == EOS) && /* startup script (s) */
(strcmp (SCRIPT_DEFAULT, "") != 0))
{
strncpy (params.startupScript, SCRIPT_DEFAULT, BOOT_FILE_LEN);
printf ("StartUp Script: %s \n", params.startupScript);
}
if ((params.other [0] == EOS) && /* other (o) */
(strcmp (OTHER_DEFAULT, "") != 0))
{
strncpy (params.other, OTHER_DEFAULT, BOOT_OTHER_LEN);
printf ("Other: %s \n", params.other);
}
if (params.passwd [0] == EOS) /* password */
strncpy (params.passwd, HOST_PASSWORD_DEFAULT, BOOT_PASSWORD_LEN);
/* fill in system-wide variables */
bcopy ((char *) ¶ms, (char *) &sysBootParams, sizeof (sysBootParams));
sysFlags = params.flags;
strcpy (sysBootHost, params.hostName); /* backwards compatibility */
strcpy (sysBootFile, params.bootFile); /* backwards compatibility */
/* set processor number: may establish vme bus access, etc. */
if (_procNumWasSet != TRUE)
{
sysProcNumSet (params.procNum);
_procNumWasSet = TRUE;
}
/* start the network */
/* initialize the generic socket library */
if (sockLibInit (NUM_FILES) == ERROR)
return (ERROR);
#if defined(INCLUDE_STREAMS) || defined(INCLUDE_STREAMS_ALL)
if (usrStrmInit() == ERROR) /* init Streams subsystem */
return (ERROR);
#endif
#ifdef INCLUDE_BSD_SOCKET
#ifdef BSD43_COMPATIBLE
bsdSock43ApiFlag = TRUE;
#endif /* BSD43_COMPATIBLE */
/* add the BSD socket library interface */
if (sockLibAdd ((FUNCPTR) bsdSockLibInit, AF_INET_BSD, AF_INET) == ERROR)
return (ERROR);
#if defined (INCLUDE_ROUTE_SOCK)
if (sockLibAdd ((FUNCPTR) bsdSockLibInit, AF_ROUTE, AF_ROUTE) == ERROR)
return (ERROR);
routeSockLibInit () ;
#endif /* INCLUDE_ROUTE_SOCK */
#endif /* INCLUDE_BSD_SOCKET */
/* install default socket library interface */
#ifndef DEFAULT_STREAMS_SOCKET
if (sockLibAdd ((FUNCPTR) bsdSockLibInit, AF_INET, AF_INET) == ERROR)
return (ERROR);
#endif /* DEFAULT_STREAMS_SOCKET */
/* set max link header reserved by BSD socket layer */
max_linkhdr = USR_MAX_LINK_HDR;
hostTblInit (); /* initialize host table */
usrNetProtoInit (); /* initialize various protocols */
netLibInit ();
#if defined(INCLUDE_END)
muxMaxBinds = MUX_MAX_BINDS;
if (muxLibInit() == ERROR)
return (ERROR);
/* Add our default address resolution functions. */
#ifdef INCLUDE_NT_ULIP
muxAddrResFuncAdd (M2_ifType_ethernet_csmacd, 0x800, ntResolv);
#else
muxAddrResFuncAdd (M2_ifType_ethernet_csmacd, 0x800, ipEtherResolvRtn);
#endif
/* Add in mux ENDs. */
for (count = 0, pDevTbl = endDevTbl; pDevTbl->endLoadFunc != END_TBL_END;
pDevTbl++, count++)
{
/* Make sure that WDB has not already installed the device. */
if (!pDevTbl->processed)
{
pCookie = muxDevLoad(pDevTbl->unit,
pDevTbl->endLoadFunc,
pDevTbl->endLoadString,
pDevTbl->endLoan, pDevTbl->pBSP);
if (pCookie == NULL)
{
printf("muxDevLoad failed for device entry %d!\n", count);
}
else
{
pDevTbl->processed = TRUE;
if (muxDevStart(pCookie) == ERROR)
{
printf("muxDevStart failed for device entry %d!\n", count);
}
}
}
}
#endif /* INCLUDE_END */
#ifdef INCLUDE_PPP
#ifdef INCLUDE_PPP_CRYPT
cryptRtnInit (&pppCryptRtn); /* install crypt() routine */
#endif /* INCLUDE_PPP_CRYPT */
loginInit(); /* for possible login option */
pppSecretLibInit(); /* initialize secrets library */
pppHookLibInit (); /* initialize pppHooks library */
pppShowInit();
#endif /* INCLUDE_PPP */
#ifdef INCLUDE_NET_REM_IO
remLastResvPort = 1010; /* pick an unused port number so we don't *
* have to wait for the one used by the *
* by the bootroms to time out */
_func_ftpLs = ftpLs; /* init ptr to ftp dir listing routine */
_func_netLsByName = netLsByName; /* init ptr to netDrv listing routine */
_func_remCurIdGet = (FUNCPTR) remCurIdGet;
_func_remCurIdSet = (FUNCPTR) remCurIdSet;
#endif /* INCLUDE_NET_REM_IO */
#ifdef INCLUDE_DHCPR
#ifndef INCLUDE_DHCPS
dhcprLibInit ();
#endif
#endif
if ((strncmp (params.bootDev, "bp", 2) == 0) ||
(strncmp (params.bootDev, "sm", 2) == 0))
{
/* booting via backplane */
pBootString = params.bad;
}
else
pBootString = params.ead;
#ifdef INCLUDE_DHCPC
/*
* Remove any values for DHCP lease origin and lease duration from
* address string and store in dhcpcBootLease global. Set dhcpBoot
* flag to indicate if DHCP lease values were found.
*/
if (sysFlags & SYSFLG_AUTOCONFIG)
if (dhcpcLeaseGet (pBootString, &dhcpBoot) == ERROR)
{
printf ("Unable to verify assigned DHCP address.\n");
return (ERROR);
}
#else
/*
* If network configuration protocols are used, check address
* for DHCP lease information. If found (and removed), exit
* with an error, since the active DHCP lease cannot be maintained.
*/
if (sysFlags & SYSFLG_AUTOCONFIG)
if (dhcpcBootLineClean (pBootString) == OK)
{
printf ("Can't use dynamic address %s without DHCP.\n",
pBootString);
return (ERROR);
}
#endif /* INCLUDE_DHCPC */
/* attach and configure interfaces */
#ifdef INCLUDE_ULIP
if (strncmp (params.bootDev, "ul", 2) == 0)
{
/*
* Booting with the simulator's interface completely configures the
* device. No DHCP/BOOTP address assignment is available.
*/
extern int ulipInit ();
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)
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)
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)
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) ||
(strncmp (params.bootDev, "rfa", 3) == 0))
{
/* booting from disk, configure network if requested */
if (params.other [0] != EOS)
{
/*
* Protocol attachment is required and automatic
* configuration with DHCP or BOOTP is supported
* for all these network devices.
*/
attachFlag = TRUE;
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)
{
if (ipAttach(params.unitNum, pNetDev) != OK)
{
logMsg ("Failed to attach to device %s",
(int)pNetDev, 0, 0, 0, 0, 0);
return (ERROR);
}
attached = TRUE;
}
#endif /*INCLUDE_END*/
#ifdef INCLUDE_BSD
if (!attached)
{
if ( (usrNetIfAttach (pNetDev, params.unitNum, pBootString) !=OK))
return (ERROR);
attached = TRUE;
}
#endif /*INCLUDE_BSD*/
if (!attached)
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -