📄 dhcpccommonlib.c
字号:
errno = S_dhcpcLib_OPTION_NOT_STORED; return (ERROR); } else pOptList->pTag12 = pDest; break; case _DHCP_MERIT_DUMP_TAG: /* Option Tag 14 */ pDest = dhcpcOptCreate (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (option, pOptList->pTag67, pData, length); if (pDest == NULL) { errno = S_dhcpcLib_OPTION_NOT_STORED; return (ERROR); } else pOptList->pTag67 = pDest; break; } 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.** RETURNS: Pointer to new option subfield, or NULL if error occurs.** NOMANUAL*/UCHAR * dhcpcOptionMerge ( 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); else optlen = 0; optlen += 2; /* Adjust for tag and length values. */ 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; /* Update length field to new value. */ 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.** RETURNS: Pointer to new option subfield, or NULL if error occurs.** NOMANUAL*/UCHAR * dhcpcOptCreate ( 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) 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 available entries in* the <pOptList> structure. Any memory used for variable-length subfields* within that structure is released. The <pOptions> parameter indicates the* destination for the options to be included in all outgoing messages. This* routine ignores the contents for the "requested IP address" option, if* present, since that option cannot always be included in the initial message.** RETURNS: N/A** NOMANUAL*/void dhcpcOptFieldCreate ( struct dhcpcOpts * pOptList, /* Available options for message */ UCHAR * pOptions /* Resulting message field */ ) { int loop; int optlen = 0; UCHAR * pData = NULL; UCHAR * pDest; BOOL copyFlag; pDest = pOptions; for (loop = 0; loop < MAXTAGNUM; loop++) { if (ISSET (pOptList->optmask, loop)) { copyFlag = FALSE; /* * For fixed size options, copy option body after inserting * option tag and length. */ switch (loop) { /* 1 byte values */ case _DHCP_IP_FORWARD_TAG: /* Option Tag 19 */ optlen = 1; pData = &pOptList->tag19; copyFlag = TRUE; break; case _DHCP_NONLOCAL_SRCROUTE_TAG: /* Option Tag 20 */ optlen = 1; pData = &pOptList->tag20; copyFlag = TRUE; break; case _DHCP_DEFAULT_IP_TTL_TAG: /* Option Tag 23 */ optlen = 1; pData = &pOptList->tag23; copyFlag = TRUE; break; case _DHCP_ALL_SUBNET_LOCAL_TAG: /* Option Tag 27 */ optlen = 1; pData = &pOptList->tag27; copyFlag = TRUE; break; case _DHCP_MASK_DISCOVER_TAG: /* Option Tag 29 */ optlen = 1; pData = &pOptList->tag29; copyFlag = TRUE; break; case _DHCP_MASK_SUPPLIER_TAG: /* Option Tag 30 */ optlen = 1; pData = &pOptList->tag30; copyFlag = TRUE; break; case _DHCP_ROUTER_DISCOVER_TAG: /* Option Tag 31 */ optlen = 1; pData = &pOptList->tag31; copyFlag = TRUE; break; case _DHCP_TRAILER_TAG: /* Option Tag 34 */ optlen = 1; pData = &pOptList->tag34; copyFlag = TRUE; break; case _DHCP_ETHER_ENCAP_TAG: /* Option Tag 36 */ optlen = 1; pData = &pOptList->tag36; copyFlag = TRUE; break; case _DHCP_DEFAULT_TCP_TTL_TAG: /* Option Tag 37 */ optlen = 1; pData = &pOptList->tag37; copyFlag = TRUE; break; case _DHCP_KEEPALIVE_GARBAGE_TAG: /* Option Tag 39 */ optlen = 1; pData = &pOptList->tag39; copyFlag = TRUE; break; case _DHCP_NB_NODETYPE_TAG: /* Option Tag 46 */ optlen = 1; pData = &pOptList->tag46; copyFlag = TRUE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -