📄 usrnetwork.c
字号:
dhcpsResult = taskSpawn ("tDhcpsTask", dhcpsTaskPriority,
dhcpsTaskOptions, dhcpsTaskStackSize,
(FUNCPTR) dhcpsStart,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
if (dhcpsResult == ERROR)
printf ("Unable to start DHCP server task.\n");
printf ("DHCP server started.\n");
}
}
#else
if (devlist[0] == NULL)
printf("Network interface %s not found. DHCP relay agent not started.\n",
devName);
else
{
dhcprResult = dhcprInit (devlist, 1, dhcpTargetTbl, dhcpTargetTblSize);
if (dhcprResult == ERROR)
printf ("Error initializing DHCP relay agent. Not started.\n");
else
{
dhcprResult = taskSpawn ("tDhcprTask", dhcprTaskPriority,
dhcprTaskOptions, dhcprTaskStackSize,
(FUNCPTR) dhcprStart,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
if (dhcprResult == ERROR)
printf ("Unable to start DHCP relay agent task.\n");
printf ("DHCP relay agent started.\n");
}
}
#endif
#endif /* INCLUDE_DHCPS or INCLUDE_DHCPR */
#if 0
#ifdef INCLUDE_SNTPC
sntpcInit (SNTP_PORT);
#endif
#ifdef INCLUDE_SNTPS
/*
* For now, set server to listen on boot device.
* Eventually, need to allow for multiple network devices.
*/
devName [0] = EOS;
sprintf(devName, "%s%d", params.bootDev, params.unitNum);
sntpsInit (devName, SNTPS_MODE,
SNTPS_DSTADDR, SNTPS_INTERVAL, SNTP_PORT, SNTPS_TIME_HOOK);
#endif
#endif
#if 0
#ifdef INCLUDE_PING
/*(void) pingLibInit ();*/ /* initialize the ping utility change by yuqs 2003-08-05*/
/*(void) sp_pingLibInit ();*/ /* remove to sysSwitch.c initialize the ping utility */
#endif /* INCLUDE_PING */
#endif/* INCLUDE_PING */
#ifdef INCLUDE_SNMPD
usrSnmpdInit ();
#endif
#ifdef INCLUDE_RIP
#ifndef RIP_SUPPLIER
#define RIP_SUPPLIER 0
#endif /* RIP_SUPPLIER */
#ifndef RIP_GATEWAY
#define RIP_GATEWAY 0
#endif /* RIP_GATEWAY */
#ifndef RIP_VERSION
#define RIP_VERSION 1
#endif /* RIP_VERSION */
#ifndef RIP_MULTICAST
#define RIP_MULTICAST 0
#endif /* RIP_MULTICAST */
#ifndef RIP_TIMER_RATE
#define RIP_TIMER_RATE 1
#endif /* RIP_TIMER_RATE */
#ifndef RIP_SUPPLY_INTERVAL
#define RIP_SUPPLY_INTERVAL 30
#endif /* RIP_SUPPLY_INTERVAL */
#ifndef RIP_EXPIRE_TIME
#define RIP_EXPIRE_TIME 180
#endif /* RIP_EXPIRE_TIME */
#ifndef RIP_GARBAGE_TIME
#define RIP_GARBAGE_TIME 300
#endif /* RIP_GARBAGE TIME */
ripLibInit(RIP_SUPPLIER, RIP_GATEWAY, RIP_MULTICAST, RIP_VERSION,
RIP_TIMER_RATE, RIP_SUPPLY_INTERVAL, RIP_EXPIRE_TIME,
RIP_GARBAGE_TIME);
#endif /* INCLUDE_RIP2 */
#ifdef INCLUDE_DNS_RESOLVER
if (usrResolvInit () == ERROR)
{
printf ("Error initializing resolvLib\n");
return(ERROR);
}
#endif /* INCLUDE_DNS_RESOLVER */
return (OK);
}
/* the next routines are in common with bootConfig.c and will be merged */
/******************************************************************************
*
* usrBootLineInit - initialize system boot line
*
* Initializes system boot line as per specified start type. If the boot
* line is empty or this is a COLD boot, i.e. with CLEAR option to clear
* memory, then the boot line is initialized from non-volatile ram, if any,
* otherwise from the compiled in default boot line.
*
* NOMANUAL
*/
void usrBootLineInit
(
int startType
)
{
if ((startType & BOOT_CLEAR) || (* BOOT_LINE_ADRS == EOS))
{
/* either cold boot or empty boot line -- initialize boot line */
if ((sysNvRamGet (BOOT_LINE_ADRS, BOOT_LINE_SIZE, 0) == ERROR))
{
/* no non-volatile RAM -- use default boot line */
strcpy (BOOT_LINE_ADRS, DEFAULT_BOOT_LINE);
}
}
}
/******************************************************************************
*
* usrBootLineCrack - interpret and verify boot line
*
* This routine interprets the specified boot line and checks the validity
* of certain parameters. If there are errors, a diagnostic message is
* printed.
*
* NOMANUAL
*/
STATUS usrBootLineCrack
(
char * bootString,
BOOT_PARAMS *pParams
)
{
FAST char * pS;
pS = bootStringToStruct (bootString, pParams);
if (*pS != EOS)
{
bootParamsErrorPrint (bootString, pS);
return (ERROR);
}
/* check inet addresses */
if ((checkInetAddrField (pParams->ead, TRUE) != OK) ||
(checkInetAddrField (pParams->bad, TRUE) != OK) ||
(checkInetAddrField (pParams->had, FALSE) != OK) ||
(checkInetAddrField (pParams->gad, FALSE) != OK))
{
return (ERROR);
}
return (OK);
}
/******************************************************************************
*
* checkInetAddrField - check for valid inet address in boot field
*
* RETURNS: OK, or ERROR if invalid inet address
*
* NOMANUAL
*/
STATUS checkInetAddrField
(
char *pInetAddr,
BOOL subnetMaskOK
)
{
char inetAddr [30];
int netmask;
bzero (inetAddr, 30); /* SPR 6326 - prevents error if address invalid. */
if (*pInetAddr == EOS)
return (OK);
strncpy (inetAddr, pInetAddr, sizeof (inetAddr));
if (subnetMaskOK)
{
if (bootNetmaskExtract (inetAddr, &netmask) < 0)
{
printf ("Error: invalid netmask in boot field \"%s\".\n", inetAddr);
return (ERROR);
}
}
if (inet_addr (inetAddr) == (u_long) ERROR)
{
printf ("Error: invalid inet address in boot field \"%s\".\n",inetAddr);
return (ERROR);
}
return (OK);
}
/******************************************************************************
*
* usrNetIfAttach - attach a network interface
*
* This routine attaches the specified network interface.
*
* - interface is attached
* - interface name is constructed as "<devName>0"
*
* RETURNS: OK or ERROR
*
* NOMANUAL
*/
STATUS usrNetIfAttach
(
char * devName,
int unitNum,
char * inetAdrs
)
{
FAST NETIF * pNif;
STATUS status;
char buf [BOOT_DEV_LEN + 1]; /* device name + unit number */
#ifdef INCLUDE_PCMCIA
int sock;
if (strncmp (devName, "pcmcia", 6) == 0)
{
if (strlen (devName) == 6)
return (ERROR);
else
sscanf (devName, "%*6s%*c%d", &sock);
*(devName + 6) = '\0';
}
#endif /* INCLUDE_PCMCIA */
/* attach interface */
/* find interface in table */
sprintf(buf, "%s%d", devName, unitNum);
for (pNif = usrNetIfTbl; pNif->ifName != 0; pNif++)
{
if (strcmp (buf, pNif->ifName) == 0)
break;
}
/*
* For backward compatibility, the device name only is acceptable for
* unit numbers of 0.
*/
if (pNif->ifName == 0 && unitNum == 0)
{
for (pNif = usrNetIfTbl; pNif->ifName != 0; pNif++)
{
if (strcmp (devName, pNif->ifName) == 0)
break;
}
}
if (pNif->ifName == 0)
{
printf ("Network interface %s unknown.\n", devName);
return (ERROR);
}
/* by cxj
printf ("Attaching network interface %s... ", buf); */
#ifdef INCLUDE_PCMCIA
if (strncmp (devName, "pcmcia", 6) == 0)
pNif->arg1 = (char *)sock;
#endif /* INCLUDE_PCMCIA */
#if defined (TARGET_VIP10)
/* SGI VIP10 boards are supposed to come with the ethernet address
* in SGI formated non volatile ram. We can not be sure where this
* is so we default the upper 4 bytes of the address to SGI standard
* and use the bottom two bytes of the internet address for the rest.
*/
if (strcmp (devName, "lnsgi") == 0)
{
IMPORT char lnsgiEnetAddr []; /* ethernet addr for lance */
u_long inet = inet_addr (inetAdrs);
lnsgiEnetAddr [4] = (inet >> 8) & 0xff;
lnsgiEnetAddr [5] = inet & 0xff;
}
#endif /* TARGET_VIP10 */
status = pNif->attachRtn (unitNum, pNif->arg1, pNif->arg2, pNif->arg3,
pNif->arg4, pNif->arg5, pNif->arg6,
pNif->arg7, pNif->arg8);
if (status != OK)
{
if (errno == S_iosLib_CONTROLLER_NOT_PRESENT)
printf ("failed.\nError: S_iosLib_CONTROLLER_NOT_PRESENT.\n");
else
printf ("failed: errno = %#x.\n", errno);
return (ERROR);
}
/*printf ("done.\n");*/ /* cancel by jxm 2003-05-05*/
return (OK);
}
/******************************************************************************
*
* usrNetIfConfig - configure network interface
*
* This routine configures the specified network interface with the specified
* boot parameters:
*
* - subnetmask is extracted from inetAdrs and, if present,
* set for interface
* - inet address is set for interface
* - if present, inet name for interface is added to host table.
*
* RETURNS: OK or ERROR
*
* NOMANUAL
*/
STATUS usrNetIfConfig
(
char * devName, /* device name */
int unitNum, /* unit number */
char * inetAdrs, /* inet address */
char * inetName, /* host name */
int netmask /* subnet mask */
)
{
char ifname [20];
#ifdef INCLUDE_PCMCIA
if (strncmp (devName, "pcmcia", 6) == 0)
devName = "pcmcia";
#endif /* INCLUDE_PCMCIA */
/* check for empty inet address */
if (inetAdrs[0] == EOS)
{
printf ("No inet address specified for interface %s.\n", devName);
return (ERROR);
}
/* build interface name */
sprintf (ifname, "%s%d", devName, unitNum);
/* set subnet mask, if any specified */
if (netmask != 0)
ifMaskSet (ifname, netmask);
/* set inet address */
if (ifAddrSet (ifname, inetAdrs) != OK)
{
printf ("Error setting inet address of %s to %s, errno = %#x\n",
ifname, inetAdrs, errno);
return (ERROR);
}
/* add host name to host table */
if ((inetName != NULL) && (*inetName != EOS))
hostAdd (inetName, inetAdrs);
return (OK);
}
/*****************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -