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

📄 dhcpclib.c

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 C
📖 第 1 页 / 共 5 页
字号:
    pLeaseData->ifData.endDrvFlag = muxDevExists (pIf->if_name, pIf->if_unit);    /* Change htype and hlen setup from hard-coded Ethernet to ioctls.  */    pLeaseData->ifData.haddr.htype = ETHER;    pLeaseData->ifData.haddr.hlen = _ETHERADDRLEN;    bcopy ( (char *) ( (struct arpcom *)pIf)->ac_enaddr,           (char *)&pLeaseData->ifData.haddr.haddr,            pLeaseData->ifData.haddr.hlen);     /* set duration of client's wait for multiple offers */    pReqSpec->waitsecs = dhcpcOfferTimeout;     /* set default lease - may be overridden with dhcpcOptionSet().  */    pReqSpec->lease = dhcpcDefaultLease;    pReqSpec->reqlist.len = 0;    /* No options requested yet.  */    /*     * If executing with startup lease, or if automatic configuration is     * requested, initialize request list with tags for options required      * by all network interfaces, using RFC 1533 tag values.     */    if (pLeaseData->autoConfig || pLeaseData->leaseType == DHCP_AUTOMATIC)        {        pReqSpec->reqlist.list [pReqSpec->reqlist.len++] =                                                        _DHCP_SUBNET_MASK_TAG;        pReqSpec->reqlist.list [pReqSpec->reqlist.len++] =                                                        _DHCP_BRDCAST_ADDR_TAG;        }    /*     * For now, create a separate watchdog timer for each lease.  Eventually,     * a single watchdog timer will suffice for all leases, when combined     * with a sorted queue containing relative firing times.  This enhancement     * can wait.     */    /* Create event timer for state machine.  */    pLeaseData->timer = wdCreate ();    if (pLeaseData->timer == NULL)        {        free (pLeaseData);        errno = S_dhcpcLib_MEM_ERROR;        return (NULL);        }    /* Create signalling semaphore for completion of negotiation process.  */    pLeaseData->leaseSem = semBCreate (SEM_Q_FIFO, SEM_EMPTY);    if (pLeaseData->leaseSem == NULL)        {        wdDelete (pLeaseData->timer);        free (pLeaseData);        errno = S_dhcpcLib_MEM_ERROR;        return (NULL);        }    /*      * Manual leases will not reset the network interface unless specifically     * requested to do so.  This lease type is replaced with DHCP_AUTOMATIC for      * the lease established during system startup.  The parameters for     * an automatic lease are always applied to the underlying interface.     */    pLeaseData->leaseType = DHCP_MANUAL;    pLeaseData->initFlag = TRUE;    /* Store the lease-specific data in the global list.  */    dhcpcLeaseList [offset] = pLeaseData;    return (pCookie);    }/********************************************************************************* dhcpcEventHookAdd - add a routine to handle configuration parameters** This routine installs a hook routine to handle changes in the configuration* parameters provided for the lease indicated by <pCookie>.  The hook provides * an alternate configuration method for DHCP leases and uses the following * interface:* .CS* void dhcpcEventHookRtn*     (*     int 	leaseEvent,	/@ new or expired parameters @/*     void * 	pCookie 	/@ lease identifier from dhcpcInit() @/*     )* .CE** The routine is called with the <leaseEvent> parameter set to DHCPC_LEASE_NEW* whenever a lease is successfully established.  The DHCPC_LEASE_NEW event* does not occur when a lease is renewed by the same DHCP server, since the* parameters do not change in that case.  However, it does occur if the * client rebinds to a different DHCP server.  The DHCPC_LEASE_INVALID event* indicates that the configuration parameters for the corresponding lease may* no longer be used.  That event occurs when a lease expires or a renewal* or verification attempt fails, and coincides with re-entry into the initial * state of the negotiation process.** If the lease initialization specified automatic configuration of the* corresponding network interface, any installed hook routine will be invoked* after the new address information is applied.** RETURNS: OK if notification hook added, or ERROR otherwise.** ERRNO: S_dhcpcLib_BAD_COOKIE, S_dhcpcLib_NOT_INITIALIZED*/STATUS dhcpcEventHookAdd    (    void * 	pCookie, 	/* identifier returned by dhcpcInit() */    FUNCPTR 	pEventHook	/* routine to handle lease parameters */    )    {    LEASE_DATA * 	pLeaseData;    int offset;    /*     * Use the cookie to access the lease-specific data structures.  For now,     * just typecast the cookie.  This translation could be replaced with a more     * sophisticated lookup at some point.     */    pLeaseData = (LEASE_DATA *)pCookie;    for (offset = 0; offset < dhcpcMaxLeases; offset++)        if (dhcpcLeaseList [offset] != NULL &&                dhcpcLeaseList [offset] == pLeaseData)            break;    if (offset == dhcpcMaxLeases)        {        errno = S_dhcpcLib_BAD_COOKIE;        return (ERROR);        }    if (!dhcpcInitialized || !pLeaseData->initFlag)        {        errno = S_dhcpcLib_NOT_INITIALIZED;        return (ERROR);        }    /* Assign the event notification hook.  */    pLeaseData->eventHookRtn = pEventHook;    return (OK);    }/********************************************************************************* dhcpcEventHookDelete - remove the configuration parameters handler** This routine removes the hook routine that handled changes in the * configuration parameters for the lease indicated by <pCookie>.* If the lease initialization specified automatic configuration of the* corresponding network interface, the assigned address could change* without warning after this routine is executed.** RETURNS: OK if notification hook removed, or ERROR otherwise.** ERRNO: S_dhcpcLib_BAD_COOKIE, S_dhcpcLib_NOT_INITIALIZED* */STATUS dhcpcEventHookDelete    (    void * 	pCookie 	/* identifier returned by dhcpcInit() */    )    {    LEASE_DATA * 	pLeaseData;    int offset;    /*     * Use the cookie to access the lease-specific data structures. For now,     * just typecast the cookie. This translation could be replaced with a more     * sophisticated lookup at some point.     */    pLeaseData = (LEASE_DATA *)pCookie;    for (offset = 0; offset < dhcpcMaxLeases; offset++)        if (dhcpcLeaseList [offset] != NULL &&                dhcpcLeaseList [offset] == pLeaseData)            break;    if (offset == dhcpcMaxLeases)        {        errno = S_dhcpcLib_BAD_COOKIE;        return (ERROR);        }    if (!dhcpcInitialized || !pLeaseData->initFlag)        {        errno = S_dhcpcLib_NOT_INITIALIZED;        return (ERROR);        }    /* Remove the event notification hook. */    pLeaseData->eventHookRtn = NULL;    return (OK);    }/********************************************************************************* dhcpcCacheHookAdd - add a routine to store and retrieve lease data** This routine adds a hook routine that is called at the bound state* (to store the lease data) and during the INIT_REBOOT state (to re-use the* parameters if the lease is still active).  The calling sequence of the * input hook routine is:* .CS* STATUS dhcpcCacheHookRtn*     (*     int command,			/@ requested cache operation @/*     unsigned long *pTimeStamp,	/@ lease timestamp data @/*     int *pDataLen,			/@ length of data to access @/*     char *pBuffer			/@ pointer to data buffer @/*     )** .CE* The hook routine should return OK if the requested operation is completed* successfully, or ERROR otherwise.  All the supplied pointers reference memory * locations that are reused upon return from the hook.  The hook routine * must copy the data elsewhere.** NOTE* The setting of the cache hook routine during a dhcpcInit() call is* recorded and used by the resulting lease throughout its lifetime.* Since the hook routine is intended to store a single lease record,* a separate hook routine should be specified before the dhcpcInit()* call for each lease which will re-use its parameters across reboots.** IMPLEMENTATION* The <command> parameter specifies one of the following operations:* .IP DHCP_CACHE_WRITE 25* Save the indicated data.  The write operation must preserve the value* referenced by <pTimeStamp> and the contents of <pBuffer>.  The <pDataLen> * parameter indicates the number of bytes in that buffer.* .IP DHCP_CACHE_READ * Restore the saved data.  The read operation must copy the data from the* most recent write operation into the location indicated by <pBuffer>,* set the contents of <pDataLen> to the amount of data provided, and store * the corresponding timestamp value in <pTimeStamp>.* .IP* The read operation has very specific requirements.  On entry, the value * referenced by <pDataLen> indicates the maximum buffer size available at* <pBuffer>.  If the amount of data stored by the previous write exceeds this * value, the operation must return ERROR.  A read must also return ERROR if the * saved timestamp value is 0.  Finally, the read operation must return ERROR if * it is unable to retrieve all the data stored by the write operation or if the* previous write was unsuccessful.* .IP DHCP_CACHE_ERASE * Ignore all stored data.  Following this operation, subsequent read operations* must return ERROR until new data is written.  All parameters except * <command> are NULL.* .LP** RETURNS: OK, always.** ERRNO: N/A*/STATUS dhcpcCacheHookAdd    (    FUNCPTR 	pCacheHookRtn 	/* routine to store/retrieve lease data */    )    {    dhcpcCacheHookRtn = pCacheHookRtn;    return (OK);    }/********************************************************************************* dhcpcCacheHookDelete - delete a lease data storage routine** This routine deletes the hook used to store lease data, preventing* re-use of the configuration parameters across system reboots for* all subsequent lease attempts.  Currently active leases will continue* to use the routine specified before the lease initialization.** RETURNS: OK, always.** ERRNO: N/A*/STATUS dhcpcCacheHookDelete (void)    {    dhcpcCacheHookRtn = NULL;    return (OK);    }/********************************************************************************* dhcpcOptionSet - add an option to the option request list** This routine sets most client-to-server transmission options for the lease * indicated by the <pCookie> parameter.  The <option> parameter specifies an * option tag as defined in RFC 1533 and the updates published in the Internet * Draft of November 1996.   For a listing of defined aliases for the known * option tags, see dhcp/dhcp.h.  This routine cannot set the options associated * with the following tags: **     _DHCP_PAD_TAG*     _DHCP_OPT_OVERLOAD_TAG*     _DHCP_MSGTYPE_TAG*     _DHCP_SERVER_ID_TAG*     _DHCP_REQ_LIST_TAG *     _DHCP_MAXMSGSIZE_TAG*     _DHCP_END_TAG** Most options only require specification of the appropriate tag in the * <option> parameter.  In those cases, the dhcpcOptionSet() call adds the * specified option tag to the option request list, if possible.  However, some * options require additional information.  The tags for these options are: **     _DHCP_VENDOR_SPEC_TAG *     _DHCP_REQUEST_IPADDR_TAG *     _DHCP_LEASE_TIME_TAG  *     _DHCP_ERRMSG_TAG *     _DHCP_CLASS_ID_TAG *     _DHCP_CLIENT_ID_TAG ** The _DHCP_LEASE_TIME_TAG and _DHCP_CLIENT_ID_TAG options each use the* <value> parameter.  For _DHCP_LEASE_TIME_TAG, <value> specifies the desired * lease length.  For _DHCP_CLIENT_ID_TAG, <value> specifies the type for a * type/value pair.  No other options use this parameter.** The _DHCP_VENDOR_SPEC_TAG, _DHCP_CLASS_ID_TAG and _DHCP_CLIENT_ID_TAG* tags each require a value for the <length> parameter to specify the number * of bytes of data provided.  No other options use this parameter.** The <pData> parameter is relevant to the following option tags:* .IP _DHCP_VENDOR_SPEC_TAG 25 * The <pData> parameter references a list of <length> bytes of options * in the format specified by RFC 1533. * .IP _DHCP_REQUEST_IPADDR_TAG* The <pData> parameter indicates the string representation of the * desired Internet address for the client in dot notation.* .IP _DHCP_ERRMSG_TAG* The <pData> parameter indicates the error message to send to the server * when releasing the current IP address.  That location must be valid until* the release is completed, since the message is not copied or stored in * any way.* .IP _DHCP_CLASS_ID_TAG* The <pData> parameter references <length> bytes used as the value * for the vendor class identifier.* .IP _DHCP_CLIENT_ID_TAG* The <pData> parameter references <length> bytes used as the value * of a type/value pair.* .IP* The <pData> parameter is not used by any other options.* .LP** NOTE: With the exception of the _DHCP_ERRMSG_TAG option, the DHCP * specification forbids changing options after a lease has been * established.  Therefore, this routine should not be used after the * dhcpcBind() call.  Changing any option other than the error message at* that point could have unpredictable results.** RETURNS: OK if the option was set successfully, or ERROR if the option* is invalid or storage failed.** ERRNO: S_dhcpcLib_BAD_OPTION, S_dhcpcLib_OPTION_NOT_STORED**/STATUS dhcpcOptionSet    (    void * 	pCookie, 	/* identifier returned by dhcpcInit() */    int 	option,		/* RFC 1533 tag of desired option */    long 	value,		/* numeric value for option */

⌨️ 快捷键说明

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