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

📄 bootplib.c

📁 VxWORKS的BOOTP协议栈
💻 C
📖 第 1 页 / 共 5 页
字号:
STATUS bootpParamsGet    (    char * 			ifName,		/* network interface name    */    int				port,		/* optional port number	     */    u_int 			timeOut,	/* timeout in ticks          */    struct bootpParams * 	pBootpParams 	/* parameters descriptor     */    )    {    BOOTP_MSG		bootpMessage;	/* bootp message		*/    struct in_addr	ipDest;		/* ip dest address 		*/    int length;    /* fill in bootp message */    bzero ((char *) &bootpMessage, sizeof (BOOTP_MSG));    /* Check for client IP address. */    if (pBootpParams->clientAddr != NULL)        bootpMessage.bp_ciaddr = *pBootpParams->clientAddr;    /* Check for host address, or use broadcast address. */    if (pBootpParams->bootHostAddr == NULL ||         pBootpParams->bootHostAddr->s_addr == 0)   	ipDest.s_addr = htonl (bootpBroadcastAddr);    else   	ipDest = *pBootpParams->bootHostAddr;    /* Check for partial boot file. */    if (pBootpParams->bootfile != NULL)        {        length = strlen (pBootpParams->bootfile);        if (length > SIZE_FILE)            length = SIZE_FILE;        (void) strncpy ( (char *) bootpMessage.bp_file, pBootpParams->bootfile,                        length);        }    /* Fill in RFC1048 magic cookie if vendor-specific info requested. */    if (bootpOptionCheck (pBootpParams))        {        bcopy ( (char *) magicCookie1048, (char *) bootpMessage.bp_vend,               sizeof (magicCookie1048));        bcopy ( (char *) endOfVend, (char *) bootpMessage.bp_vend +               sizeof(magicCookie1048), sizeof(endOfVend));        }    /* send bootp message */    if (bootpMsgSend (ifName, &ipDest, port, &bootpMessage, timeOut) == ERROR)        return (ERROR);    /* Fill in any options requested by user and provided by server. */    bootpParamsFill (pBootpParams);    return (OK);    }/******************************************************************************** bootpOptionCheck - check if user wants optional parameters** This routine is called to determine whether the magic cookie specified * in RFC 1048 should be inserted into the vendor specifications field of * a BOOTP request.  The cookie is inserted if the user has set any pointer * in the parameter descriptor which correspond to BOOTP options to a * non-NULL value.** RETURNS: TRUE if options requested, or FALSE otherwise.** ERRNO: N/A** NOMANUAL*/BOOL bootpOptionCheck    (    struct bootpParams * 	pBootpParams 	/* parameters descriptor     */    )    {    BOOL result;    result = FALSE;    if (pBootpParams->netmask != NULL)        result = TRUE;    else if (pBootpParams->timeOffset != NULL)        result = TRUE;    else if (pBootpParams->routers != NULL)        result = TRUE;    else if (pBootpParams->timeServers != NULL)        result = TRUE;    else if (pBootpParams->nameServers != NULL)        result = TRUE;    else if (pBootpParams->dnsServers != NULL)        result = TRUE;    else if (pBootpParams->logServers != NULL)        result = TRUE;    else if (pBootpParams->cookieServers != NULL)        result = TRUE;    else if (pBootpParams->lprServers != NULL)        result = TRUE;    else if (pBootpParams->impressServers != NULL)        result = TRUE;    else if (pBootpParams->rlpServers != NULL)        result = TRUE;    else if (pBootpParams->clientName != NULL)        result = TRUE;    else if (pBootpParams->filesize != NULL)        result = TRUE;    else if (pBootpParams->dumpfile != NULL)        result = TRUE;    else if (pBootpParams->domainName != NULL)        result = TRUE;    else if (pBootpParams->swapServer != NULL)        result = TRUE;    else if (pBootpParams->rootPath != NULL)        result = TRUE;    else if (pBootpParams->extoptPath != NULL)        result = TRUE;    else if (pBootpParams->ipForward != NULL)        result = TRUE;    else if (pBootpParams->nonlocalSourceRoute != NULL)        result = TRUE;    else if (pBootpParams->policyFilter != NULL)        result = TRUE;    else if (pBootpParams->maxDgramSize != NULL)        result = TRUE;    else if (pBootpParams->ipTTL != NULL)        result = TRUE;    else if (pBootpParams->mtuTimeout != NULL)        result = TRUE;    else if (pBootpParams->mtuTable != NULL)        result = TRUE;    else if (pBootpParams->intfaceMTU != NULL)        result = TRUE;    else if (pBootpParams->allSubnetsLocal != NULL)        result = TRUE;    else if (pBootpParams->broadcastAddr != NULL)        result = TRUE;    else if (pBootpParams->maskDiscover != NULL)        result = TRUE;    else if (pBootpParams->maskSupplier != NULL)        result = TRUE;    else if (pBootpParams->routerDiscover != NULL)        result = TRUE;    else if (pBootpParams->routerDiscAddr != NULL)        result = TRUE;    else if (pBootpParams->staticRoutes != NULL)        result = TRUE;    else if (pBootpParams->arpTrailers != NULL)        result = TRUE;    else if (pBootpParams->arpTimeout != NULL)        result = TRUE;    else if (pBootpParams->etherPacketType != NULL)        result = TRUE;    else if (pBootpParams->tcpTTL != NULL)        result = TRUE;    else if (pBootpParams->tcpInterval != NULL)        result = TRUE;    else if (pBootpParams->tcpGarbage != NULL)        result = TRUE;    else if (pBootpParams->nisDomain != NULL)        result = TRUE;    else if (pBootpParams->nisServers != NULL)        result = TRUE;    else if (pBootpParams->ntpServers != NULL)        result = TRUE;    else if (pBootpParams->vendString != NULL)        result = TRUE;    else if (pBootpParams->nbnServers != NULL)        result = TRUE;    else if (pBootpParams->nbddServers != NULL)        result = TRUE;    else if (pBootpParams->nbNodeType != NULL)        result = TRUE;    else if (pBootpParams->nbScope != NULL)        result = TRUE;    else if (pBootpParams->xFontServers != NULL)        result = TRUE;    else if (pBootpParams->xDisplayManagers != NULL)        result = TRUE;    else if (pBootpParams->nispDomain != NULL)        result = TRUE;    else if (pBootpParams->nispServers != NULL)        result = TRUE;    else if (pBootpParams->ipAgents != NULL)        result = TRUE;    else if (pBootpParams->smtpServers != NULL)        result = TRUE;    else if (pBootpParams->pop3Servers != NULL)        result = TRUE;    else if (pBootpParams->nntpServers != NULL)        result = TRUE;    else if (pBootpParams->wwwServers != NULL)        result = TRUE;    else if (pBootpParams->fingerServers != NULL)        result = TRUE;    else if (pBootpParams->ircServers != NULL)        result = TRUE;    else if (pBootpParams->stServers != NULL)        result = TRUE;    else if (pBootpParams->stdaServers != NULL)        result = TRUE;    return (result);    }/******************************************************************************** bootpParamsFill - copy requested BOOTP options** This routine fills in the non-NULL fields in the given parameter descriptor* with the corresponding entries from the received BOOTP message.  It is only* called internally after bootpMsgSend() completes successfully.** RETURNS: N/A** ERRNO: N/A** NOMANUAL*/void bootpParamsFill    (    struct bootpParams * 	pBootpParams 	/* parameters descriptor     */    )    {    int 	loop;    int 	limit;    u_char * 	cp;    int length;    int number;    /* Copy entries from message body if requested by user. */        /* Fill in assigned IP address. */    if (pBootpParams->clientAddr != NULL)        *pBootpParams->clientAddr = pBootpReply->bp_yiaddr;        /* Fill in host IP address. */    if (pBootpParams->bootHostAddr != NULL)        *pBootpParams->bootHostAddr = pBootpReply->bp_siaddr;         /* Fill in boot file. */    if (pBootpParams->bootfile != NULL)        {        if (pBootpReply->bp_file [0] == EOS)            {            printf ("\nno boot file specified.  Check file permissions");            printf (" (must be world readable).\n");            pBootpParams->bootfile[0] = EOS;            }        else            (void)strcpy (pBootpParams->bootfile,                          (char *)pBootpReply->bp_file);        }        /* Fill in server name. */    if (pBootpParams->serverName != NULL)        if (pBootpReply->bp_sname[0] == EOS)            pBootpParams->serverName[0] = EOS;        else            strcpy(pBootpParams->serverName, pBootpReply->bp_sname);    /* Fill in optional entries requested by user, if present in reply. */        /* Retrieve subnet mask. */    if (pBootpParams->netmask != NULL)        {        length = 0;        cp = bootpTagFind (pBootpReply->bp_vend, TAG_SUBNET_MASK, &length);        if (cp != NULL)            bcopy ( (char *) cp, (char *)pBootpParams->netmask, length);        else            bzero ( (char *)pBootpParams->netmask, sizeof (struct in_addr));        }        /* Retrieve time offset. */    if (pBootpParams->timeOffset != NULL)        {        length = 0;        cp = bootpTagFind (pBootpReply->bp_vend, TAG_TIME_OFFSET, &length);        if (cp != NULL)            *pBootpParams->timeOffset = ntohs (*(unsigned short *)cp);        else            *pBootpParams->timeOffset = 0;        }        /* Retrieve IP addresses of IP routers, up to number requested. */    if (pBootpParams->routers != NULL &&         pBootpParams->routers->addrlist != NULL)        {        length = 0;        limit = 0;        cp = bootpTagFind (pBootpReply->bp_vend, TAG_GATEWAY, &length);        if (cp != NULL)            {            number = length / sizeof (struct in_addr);            limit = (pBootpParams->routers->num < number) ?                     pBootpParams->routers->num : number;            for (loop = 0; loop < limit; loop++)                {                bcopy ( (char *)cp,                        (char *)&pBootpParams->routers->addrlist[loop],                        sizeof (struct in_addr));                cp += sizeof (struct in_addr);                }            }        pBootpParams->routers->num = limit;        }        /* Retrieve IP addresses of time servers, up to number requested. */    if (pBootpParams->timeServers != NULL &&        pBootpParams->timeServers->addrlist != NULL)        {        length = 0;        limit = 0;        cp = bootpTagFind (pBootpReply->bp_vend, TAG_TIME_SERVER, &length);        if (cp != NULL)            {            number = length / sizeof (struct in_addr);            limit = (pBootpParams->timeServers->num < number) ?                     pBootpParams->timeServers->num : number;            for (loop = 0; loop < limit; loop++)                {                bcopy ( (char *)cp,                       (char *)&pBootpParams->timeServers->addrlist[loop],                        sizeof (struct in_addr));                cp += sizeof (struct in_addr);                }            }        pBootpParams->timeServers->num = limit;        }        /* Retrieve IP addresses of name servers, up to number requested. */    if (pBootpParams->nameServers != NULL &&        pBootpParams->nameServers->addrlist != NULL)        {        length = 0;        limit = 0;        cp = bootpTagFind (pBootpReply->bp_vend, TAG_NAME_SERVER, &length);        if (cp != NULL)            {            number = length / sizeof (struct in_addr);            limit = (pBootpParams->nameServers->num < number) ?                     pBootpParams->nameServers->num : number;            for (loop = 0; loop < limit; loop++)                {                bcopy ( (char *)cp,                       (char *)&pBootpParams->nameServers->addrlist[loop],                        sizeof (struct in_addr));                cp += sizeof (struct in_addr);                }            }        pBootpParams->nameServers->num = limit;        }        /* Retrieve IP addresses of DNS servers, up to number requested. */    if (pBootpParams->dnsServers != NULL &&         pBootpParams->dnsServers->addrlist != NULL)        {        length = 0;        limit = 0;        cp = bootpTagFind (pBootpReply->bp_vend, TAG_DNS_SERVER, &length);        if (cp != NULL)            {            number = length / sizeof (struct in_addr);            limit = (pBootpParams->dnsServers->num < number) ?

⌨️ 快捷键说明

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