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

📄 dhcpclib.c

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 C
📖 第 1 页 / 共 5 页
字号:
    int offset;    LEASE_DATA *        pLeaseData = NULL;    STATUS result = OK;    /*     * 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);        }    /*     * 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;    /* Construct and send a release request to the client monitor task.  */    result = dhcpcEventAdd (DHCP_USER_EVENT, DHCP_USER_RELEASE,                            pLeaseData, FALSE);    return (result);    }/********************************************************************************* dhcpcShutdown - disable DHCP client library** This routine schedules the lease monitor task to clean up memory and exit,* after releasing all currently active leases.  The network boot device* will be disabled if the DHCP client was used to obtain the VxWorks boot * parameters and the resulting lease is still active.  Any other interfaces * using the addressing information from leases set for automatic configuration* will also be disabled.  Notification of a disabled interface will not occur* unless an event hook has been installed.  After the processing started by* this request completes, the DHCP client library is unavailable until * restarted with the dhcpcLibInit() routine.** RETURNS: OK if shutdown scheduled, or ERROR otherwise.** ERRNO: S_dhcpcLib_NOT_INITIALIZED* */STATUS dhcpcShutdown (void)    {    STATUS 	result;    if (!dhcpcInitialized)        {        errno = S_dhcpcLib_NOT_INITIALIZED;        return (ERROR);        }    /* Construct and send a shutdown request to the client monitor task.  */    result = dhcpcEventAdd (DHCP_USER_EVENT, DHCP_USER_SHUTDOWN, NULL, FALSE);    return (result);    }/********************************************************************************* dhcpcOptionGet - retrieve an option provided to a client and store in a buffer** This routine retrieves the data for the specified <option>, if present* for the lease indicated by <pCookie>.  The data is stored in the provided * buffer, whose length must be specified.  If the <option> is found, the amount * of data available is stored in the location referenced by the <pLength> * parameter.  The option is not available if the DHCP client is not in the * bound state or if the server did not provide it.  After returning, the * provided buffer may contain IP addresses stored in network byte order.  All * other numeric values are stored in host byte order.  See RFC 1533 for specific* details on the data retrieved. * * RETURNS: OK if option available, or ERROR otherwise.** ERRNO: S_dhcpcLib_BAD_COOKIE, S_dhcpcLib_NOT_INITIALIZED, S_dhcpcLib_NOT_BOUND,*  S_dhcpcLib_OPTION_NOT_PRESENT** SEE ALSO* dhcpcOptionSet()*/STATUS dhcpcOptionGet    (    void * 	pCookie, 	/* identifier returned by dhcpcInit() */    int 	option,		/* RFC 1533 option tag */    int * 	pLength, 	/* size of provided buffer and data returned */    char *	pBuf 		/* location for option data */    )    {    char *	pData;    int  	amount;    int 	limit;    int 	offset;    LEASE_DATA * 	pLeaseData;    limit = *pLength;    /*     * 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);        }    /* Check if client is bound.  */    semTake (dhcpcMutexSem, WAIT_FOREVER);    if (!pLeaseData->leaseGood)        {        errno = S_dhcpcLib_NOT_BOUND;        semGive (dhcpcMutexSem);        return (ERROR);        }    semGive (dhcpcMutexSem);    /* Check if requested parameter is available.  */    if (!ISSET (pLeaseData->dhcpcParam->got_option, option))        {        errno = S_dhcpcLib_OPTION_NOT_PRESENT;        return (ERROR);        }    /* Find the location of option data */    pData = dhcpcOptionFind (pLeaseData, option, &amount);    if (pData == NULL)        {        errno = S_dhcpcLib_OPTION_NOT_PRESENT;        return (ERROR);        }    if (amount == 0)        {        /* Requested parameter not provided by server - no data returned.  */        *pLength = 0;        return (OK);        }    if (amount < limit)         /* Adjust for size of option data.  */        limit = amount;     bcopy (pData, pBuf, limit);    *pLength = limit;    return (OK);    }/********************************************************************************* dhcpcServerGet - retrieve the current DHCP server** This routine returns the DHCP server that supplied the configuration* parameters for the lease specified by the <pCookie> argument.  This * information is available only if the lease is in the bound state.** RETURNS: OK if in bound state and server available, or ERROR otherwise.** ERRNO: S_dhcpcLib_BAD_COOKIE, S_dhcpcLib_NOT_INITIALIZED, S_dhcpcLib_NOT_BOUND*/STATUS dhcpcServerGet    (    void * 		pCookie, 	/* identifier returned by dhcpcInit() */    struct in_addr * 	pServerAddr 	/* location for address of server */    )    {    int offset;    LEASE_DATA * 	pLeaseData;    STATUS 		result = OK;    /*     * 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);        }    semTake (dhcpcMutexSem, WAIT_FOREVER);    if (!pLeaseData->leaseGood)        result = ERROR;    semGive (dhcpcMutexSem);    if (result == ERROR)        {        errno = S_dhcpcLib_NOT_BOUND;        return (ERROR);        }    if (pLeaseData->dhcpcParam->server_id.s_addr != 0)        bcopy ( (char *)&pLeaseData->dhcpcParam->server_id,                (char *)pServerAddr, sizeof (struct in_addr));    else         result = ERROR;    return (result);    }/********************************************************************************* dhcpcTimerGet - retrieve current lease timers** This routine returns the number of clock ticks remaining on the timers* governing the DHCP lease specified by the <pCookie> argument.  This * information is only available if the lease is in the bound state.* Therefore, this routine will return ERROR if a BOOTP reply was accepted.** RETURNS: OK if in bound state and values available, or ERROR otherwise.** ERRNO: S_dhcpcLib_BAD_COOKIE, S_dhcpcLib_NOT_INITIALIZED, S_dhcpcLib_NOT_BOUND, *  S_dhcpcLib_OPTION_NOT_PRESENT, S_dhcpcLib_TIMER_ERROR*/STATUS dhcpcTimerGet    (    void * 	pCookie, 	/* identifier returned by dhcpcInit() */    int * 	pT1, 		/* time until lease renewal */    int * 	pT2 		/* time until lease rebinding */    )    {    int 	offset;    time_t	current = 0;    long	timer1;    long	timer2;    LEASE_DATA *        pLeaseData;    STATUS 		result = OK;    /*     * 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);        }    if (pLeaseData->leaseType == DHCP_BOOTP)        {#ifdef DHCPC_DEBUG        logMsg ("No timer values: BOOTP reply accepted.\n", 0, 0, 0, 0, 0, 0);#endif        errno = S_dhcpcLib_OPTION_NOT_PRESENT;        return (ERROR);        }    if (time (&current) == -1)        {#ifdef DHCPC_DEBUG        logMsg ("time() error in dhcpTimerGet().\n", 0, 0, 0, 0, 0, 0);#endif        errno = S_dhcpcLib_TIMER_ERROR;        return (ERROR);        }    semTake (dhcpcMutexSem, WAIT_FOREVER);    if (!pLeaseData->leaseGood)        result = ERROR;    semGive (dhcpcMutexSem);    if (result == ERROR)        {        errno = S_dhcpcLib_NOT_BOUND;        return (ERROR);        }    timer1 = pLeaseData->dhcpcParam->lease_origin +                  pLeaseData->dhcpcParam->dhcp_t1 - current;    timer2 = pLeaseData->dhcpcParam->lease_origin +                  pLeaseData->dhcpcParam->dhcp_t2 - current;    if (timer1 < 0)        timer1 = 0;       if (timer2 < 0)        timer2 = 0;    *pT1 = timer1 * sysClkRateGet();    *pT2 = timer2 * sysClkRateGet();    return (OK);    }/********************************************************************************* dhcpcParamsGet - retrieve current configuration parameters** This routine copies the current configuration parameters for the lease* specified by the <pCookie> argument to the user-supplied structure.  That * structure, defined in dhcp/dhcpc.h, should contain non-NULL pointers to * indicate the parameters of interest.  All other values within the structure * must be set to 0 before calling the routine.  The requested information is * only retrieved if the specified lease is in the bound state and knows that * its parameters are good.* * Many of the parameters within the user-supplied structure use one of the * following secondary data types: struct in_addrs, struct u_shorts, and * struct vendor_list.  Each of those structures accepts a length designation * and a data pointer.  For the first two data types, the 'num' member indicates * the size of the buffer in terms of the number of underlying elements.  For * example, the STATIC_ROUTE option returns one or more IP address pairs.  So, * setting the 'num' member to 2 in the static_route entry would indicate that * the corresponding buffer contained 16 bytes.  By contrast, the 'len' member * in the struct 'vendor_list' data type consists

⌨️ 快捷键说明

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