📄 usrnetwork.c
字号:
NET_DIAG(("sockLibAdd(..., AF_ROUTE, AF_ROUTE) returned errno = 0x%x\n", errno)); 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) { NET_DIAG(("sockLibAdd(..., AF_INET, AF_INET) returned errno = 0x%x\n", errno)); 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 */ if (netLibInit () != OK) return (ERROR);#ifdef INCLUDE_MIB2_IP m2IpInit (MIB2IP_MAX_ROUTE_TBL_SIZE); /* the IP group */#endif /* MIB_IP */#ifdef INCLUDE_ARP_API arpLibInit ();#endif#ifdef INCLUDE_NET_SHOW netShowInit ();#endif#if defined(INCLUDE_END) muxMaxBinds = MUX_MAX_BINDS; if (muxLibInit() == ERROR) { NET_DIAG(("muxLibInit() returned errno = 0x%x\n", errno)); 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); } }#ifdef END_POLL_STATS_ROUTINE_HOOK endPollStatsInit (pCookie, END_POLL_STATS_ROUTINE_HOOK);#endif /* END_POLL_STATS_ROUTINE_HOOK */ } }#endif /* INCLUDE_END */#ifdef INCLUDE_PCCARD csClientLoad (CS_END_ENABLER);#endif /* INCLUDE_PCCARD */#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_MIB2_IF /* add hooks for if.c */ _m2SetIfLastChange = (FUNCPTR) m2SetIfLastChange; _m2IfTableUpdate = (FUNCPTR) m2IfTableUpdate;#ifdef MIB2IF_64BIT_COUNTERS m2If64BitCounters = MIB2IF_64BIT_COUNTERS;#else /* MIB2IF_64BIT_COUNTERS */ m2If64BitCounters = 0;#endif /* MIB2IF_64BIT_COUNTERS */#endif /* INCLUDE_MIB2_IF */#ifdef INCLUDE_DHCPR#ifndef INCLUDE_DHCPS dhcprResult = dhcprLibInit (DHCPS_MAX_MSGSIZE); if (dhcprResult == ERROR) NET_DIAG(("Unable to initialize DHCP relay agent library!\n"));#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) { 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 *)¶ms.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);#if (DHCPC_DISCOVER_RETRIES) dhcpcDiscoverRetries = DHCPC_DISCOVER_RETRIES;#endif#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 (¶ms, pBootString, &netmask, &dhcpBoot, attachFlag) == ERROR) return (ERROR);#endif /* INCLUDE_DHCPC */ /* 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) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -