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

📄 dhcpccommonlib.c

📁 VxWorks BSP框架源代码包含头文件和驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
            if (pDest == NULL)                {                errno = S_dhcpcLib_OPTION_NOT_STORED;                return (ERROR);                }            else                pOptList->pTag21 = pDest;            break;        case _DHCP_STATIC_ROUTE_TAG: 		/* Option Tag 33 */            pDest = dhcpcOptionMerge (pOptList, option, pOptList->pTag33,                                      pData, length);            if (pDest == NULL)                {                errno = S_dhcpcLib_OPTION_NOT_STORED;                return (ERROR);                }            else                pOptList->pTag33 = pDest;            break;        case _DHCP_VENDOR_SPEC_TAG: 		/* Option Tag 43 */            pDest = dhcpcOptionMerge (pOptList, option, pOptList->pTag43,                                      pData, length);            if (pDest == NULL)                {                errno = S_dhcpcLib_OPTION_NOT_STORED;                return (ERROR);                }            else                pOptList->pTag43 = pDest;            break;        case _DHCP_REQ_LIST_TAG: 		/* Option Tag 55 */            pDest = dhcpcOptionMerge (pOptList, option, pOptList->pTag55,                                      pData, length);            if (pDest == NULL)                {                errno = S_dhcpcLib_OPTION_NOT_STORED;                return (ERROR);                }            else                {                /* Add new list. Ignore dhcpcOptionSet() routine results. */                pReqSpec->reqlist.len = 0;                pOptList->pTag55 = pDest;                }            break;        /*         * Variable-length values. Add new entry or replace existing one.         * Store tag value and length before option body.         */        case _DHCP_HOSTNAME_TAG: 		/* Option Tag 12 */            pDest = dhcpcOptCreate (pOptList, option, pOptList->pTag12,                                    pData, length);            if (pDest == NULL)                {                errno = S_dhcpcLib_OPTION_NOT_STORED;                return (ERROR);                }            else                pOptList->pTag12 = pDest;            break;        case _DHCP_MERIT_DUMP_TAG: 		/* Option Tag 14 */            pDest = dhcpcOptCreate (pOptList, option, pOptList->pTag14,                                    pData, length);            if (pDest == NULL)                {                errno = S_dhcpcLib_OPTION_NOT_STORED;                return (ERROR);                }            else                pOptList->pTag14 = pDest;            break;        case _DHCP_DNS_DOMAIN_TAG: 		/* Option Tag 15 */            pDest = dhcpcOptCreate (pOptList, option, pOptList->pTag15,                                    pData, length);            if (pDest == NULL)                {                errno = S_dhcpcLib_OPTION_NOT_STORED;                return (ERROR);                }            else                pOptList->pTag15 = pDest;            break;        case _DHCP_ROOT_PATH_TAG: 		/* Option Tag 17 */            pDest = dhcpcOptCreate (pOptList, option, pOptList->pTag17,                                    pData, length);            if (pDest == NULL)                {                errno = S_dhcpcLib_OPTION_NOT_STORED;                return (ERROR);                }            else                pOptList->pTag17 = pDest;            break;        case _DHCP_EXTENSIONS_PATH_TAG: 	/* Option Tag 18 */            pDest = dhcpcOptCreate (pOptList, option, pOptList->pTag18,                                    pData, length);            if (pDest == NULL)                {                errno = S_dhcpcLib_OPTION_NOT_STORED;                return (ERROR);                }            else                pOptList->pTag18 = pDest;            break;        case _DHCP_NIS_DOMAIN_TAG: 		/* Option Tag 40 */            pDest = dhcpcOptCreate (pOptList, option, pOptList->pTag40,                                    pData, length);            if (pDest == NULL)                {                errno = S_dhcpcLib_OPTION_NOT_STORED;                return (ERROR);                }            else                pOptList->pTag40 = pDest;            break;        case _DHCP_NB_SCOPE_TAG: 		/* Option Tag 47 */            pDest = dhcpcOptCreate (pOptList, option, pOptList->pTag47,                                    pData, length);            if (pDest == NULL)                {                errno = S_dhcpcLib_OPTION_NOT_STORED;                return (ERROR);                }            else                pOptList->pTag47 = pDest;            break;        case _DHCP_ERRMSG_TAG: 			/* Option Tag 56 */            pDest = dhcpcOptCreate (pOptList, option, pOptList->pTag56,                                    pData, length);            if (pDest == NULL)                {                errno = S_dhcpcLib_OPTION_NOT_STORED;                return (ERROR);                }            else                pOptList->pTag56 = pDest;            break;        case _DHCP_CLASS_ID_TAG: 		/* Option Tag 60 */            pDest = dhcpcOptCreate (pOptList, option, pOptList->pTag60,                                    pData, length);            if (pDest == NULL)                {                errno = S_dhcpcLib_OPTION_NOT_STORED;                return (ERROR);                }            else                pOptList->pTag60 = pDest;            break;        case _DHCP_CLIENT_ID_TAG: 		/* Option Tag 61 */            /*             * This option is also stored separately since it is included             * independently in DECLINE and RELEASE messages.             */            if (pReqSpec->clid == NULL)                {                pReqSpec->clid = malloc (sizeof (struct client_id));                if (pReqSpec->clid == NULL)                    {                    errno = S_dhcpcLib_OPTION_NOT_STORED;                    return (ERROR);                    }                bzero ( (char *)pReqSpec->clid, sizeof (struct client_id));                }            if (pReqSpec->clid->id != NULL)                free (pReqSpec->clid->id);            pReqSpec->clid->id = malloc (length * sizeof (char));            if (pReqSpec->clid->id == NULL)                {                free (pReqSpec->clid);                pReqSpec->clid = NULL;                errno = S_dhcpcLib_OPTION_NOT_STORED;                return (ERROR);                }            bcopy (pData, pReqSpec->clid->id, length);            pReqSpec->clid->len = length;            pDest = dhcpcOptCreate (pOptList, option, pOptList->pTag61,                                    pData, length);            if (pDest == NULL)                {                free (pReqSpec->clid->id);                free (pReqSpec->clid);                pReqSpec->clid = NULL;                errno = S_dhcpcLib_OPTION_NOT_STORED;                return (ERROR);                }            else                pOptList->pTag61 = pDest;            break;        case _DHCP_NISP_DOMAIN_TAG: 		/* Option Tag 64 */            pDest = dhcpcOptCreate (pOptList, option, pOptList->pTag64,                                    pData, length);            if (pDest == NULL)                {                errno = S_dhcpcLib_OPTION_NOT_STORED;                return (ERROR);                }            else                pOptList->pTag64 = pDest;            break;        case _DHCP_TFTP_SERVERNAME_TAG: 	/* Option Tag 66 */            pDest = dhcpcOptCreate (pOptList, option, pOptList->pTag66,                                    pData, length);            if (pDest == NULL)                {                errno = S_dhcpcLib_OPTION_NOT_STORED;                return (ERROR);                }            else                pOptList->pTag66 = pDest;            break;        case _DHCP_BOOTFILE_TAG: 		/* Option Tag 67 */            pDest = dhcpcOptCreate (pOptList, option, pOptList->pTag67,                                    pData, length);            if (pDest == NULL)                {                errno = S_dhcpcLib_OPTION_NOT_STORED;                return (ERROR);                }            else                pOptList->pTag67 = pDest;            break;        }    if (option != _DHCP_REQUEST_IPADDR_TAG)        {        if (pDest != NULL)            pReqSpec->pOptList->optlen += *(UINT8 *)(pDest + 1) + 2;        else            pReqSpec->pOptList->optlen += length + 2;        }    SETBIT (pOptList->optmask, option);    return (OK);    }/********************************************************************************* dhcpcOptionMerge - combine options into a single body** The dhcpcOptionAdd() routine uses this routine to extend an existing option* body, if any, with new data. This merge operation is required when the same* option is inserted more than once for a given tag. If no option currently* exists, this routine just creates the new option subfield. The <pOrig>* parameter contains the current option subfield, or NULL if none exists yet.* The <pData> parameter contains <length> bytes of additional option data.* The <pOptList> parameter is a pointer to the option list structure where* this option will be stored.** RETURNS: Pointer to new option subfield, or NULL if error occurs.** NOMANUAL*/UCHAR * dhcpcOptionMerge    (    struct dhcpcOpts *	pOptList,/* pointer to option list */    UCHAR		option,	/* RFC 2132 tag of desired option */    UCHAR * 		pOrig, 	/* current option subfield, or NULL if none */    UCHAR * 		pData, 	/* additional/first option body */    int 		length 	/* amount of new data */    )    {    int optlen; 	/* Size of current subfield */    int newlen; 	/* Size of new subfield */    UCHAR * pDest;    if (pOrig != NULL)        {        optlen = * (pOrig + 1);        /* Subtract length of data that was previously stored here. */        if (pOptList != NULL)            pOptList->optlen -= optlen + 2;        }    else        optlen = 0;    optlen += 2; 	/* Adjust for tag (1 byte) and			 * length (1 byte) values (2 bytes). */    newlen = optlen + length;    if (newlen > 255) 	/* Merged option exceeds maximum length. */        return (NULL);    pDest = malloc (newlen);    if (pDest != NULL)        {        if (pOrig != NULL)            {            bcopy (pOrig, pDest, optlen);            free (pOrig);            }        else            *pDest = option;        * (pDest + 1) = newlen - 2;    /* Update length field to new value.					* (This is the length of the option					* data _only_, we must not include					* the option tag and length bytes					* themselves here.) */        bcopy (pData, pDest + optlen, length);        }    return (pDest);    }/********************************************************************************* dhcpcOptCreate - generate a new subfield for variable-length options** The dhcpcOptionAdd() routine uses this routine to create or replace an* option subfield. The <pOrig> parameter contains the current option subfield,* or NULL if none exists yet. The <pData> parameter contains <length> bytes of* option data for the new (or initial) subfield. The <pOptList> parameter* is a pointer to the option list structure where this option will be* stored.** RETURNS: Pointer to new option subfield, or NULL if error occurs.** NOMANUAL*/UCHAR * dhcpcOptCreate    (    struct dhcpcOpts *	pOptList,/* pointer to option list */    UCHAR		option,	/* RFC 2132 tag of desired option */    UCHAR * 		pOrig, 	/* current option subfield, or NULL if none */    UCHAR * 		pData, 	/* additional/first option body */    int 		length 	/* amount of new data */    )    {    UCHAR * pDest;    pDest = malloc (length + 2);    /* Adjusts for tag and length */    if (pDest != NULL)        {        *pDest = option;        * (pDest + 1) = length;        bcopy (pData, pDest + 2, length);        if (pOrig != NULL)            {            /* Subtract length of data that was previously stored here. */            if (pOptList != NULL)                pOptList->optlen -= *(UCHAR *)(pOrig + 1) + 2;            free (pOrig);            }        }    return (pDest);    }/********************************************************************************* dhcpcOptFieldCreate - fill in the options field for outgoing messages** The boot-time and run-time DHCP clients use this routine to fill the* options field for all outgoing messages from the 

⌨️ 快捷键说明

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