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

📄 dhcpcshow.c

📁 vxworks的完整的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* dhcpcShow.c - DHCP run-time client information display routines *//* Copyright 1984 - 2001 Wind River Systems, Inc.  */#include "copyright_wrs.h"/*modification history--------------------01q,12may02,kbw  man page edits01p,10may02,kbw  making man page edits01o,23apr02,wap  use dhcpTime() instead of time() (SPR #68900)01n,15oct01,rae  merge from truestack ver 01m, base 01l01m,16oct00,niq  Integrating T3 DHCP01l,17jan98,kbw  removed NOMANUAL from dhcpcShowInit()01k,14dec97,kbw  making minor man page fixes01j,10dec97,kbw  making minor man page fixes01i,04dec97,spm  added code review modifications01h,21oct97,kbw  making minor man page fixes01g,26aug97,spm  major overhaul: changed user interface to support multiple                  leases at run-time; changed function names and renamed                 module to comply with coding standards01f,06aug97,spm  removed parameters linked list to reduce memory required01e,30jul97,kbw  fixed man page problems found in beta review01d,02jun97,spm  updated man pages and added ERRNO entries01c,17apr97,kbw  fixed minor format errors in man page, spell-checked01b,07apr97,spm  corrected array indexing bugs, modified displayed parameter                  descriptions, rewrote documentation01a,31jan97,spm  created by extracting routines from netShow.c*//*DESCRIPTIONThis library provides routines that display various data related tothe DHCP run-time client library such as the lease timers and responding server.  The dhcpcShowInit() routine links the show facility into the VxWorksimage.  This happens automatically if INCLUDE_NET_SHOW and INCLUDE_DHCPC are defined at the time the image is built.INCLUDE FILES: dhcpcLib.hSEE ALSO: dhcpcLib*/#include <stdio.h>#include "vxWorks.h"#include "inetLib.h"#include "dhcpcLib.h"#include "dhcp/dhcpcCommonLib.h"#include "dhcp/dhcpcStateLib.h"#include "time.h"IMPORT SEM_ID           dhcpcMutexSem;   /* protects the status indicators *//* forward declarations */STATUS dhcpcServerShow (void *);STATUS dhcpcTimersShow (void *);STATUS dhcpcParamsShow (void *);/******************************************************************************** dhcpcShowInit - initialize the DHCP show facility** This routine links the DHCP show facility into the VxWorks system image. * It is called from usrNetwork.c automatically if INCLUDE_DHCP and * INCLUDE_NET_SHOW are defined at the time the image is constructed.**/void dhcpcShowInit (void)    {    return;    }/********************************************************************************* dhcpcServerShow - display current DHCP server** This routine prints the IP address of the DHCP server that provided the * parameters for the lease identified by <pCookie>.  It has no effect if the* indicated lease is not currently active.** RETURNS: OK, or ERROR if lease identifier unknown.** ERRNO: *  S_dhcpcLib_BAD_COOKIE**/STATUS dhcpcServerShow     (    void * 	pCookie 	/* identifier returned by dhcpcInit() */    )    {    int 		offset;    LEASE_DATA * 	pLeaseData = NULL;    char 		addrBuf [INET_ADDR_LEN];    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);        }    /* Ignore show request if lease is not initialized or not bound.  */    if (!dhcpcInitialized || !pLeaseData->initFlag)        return (OK);    semTake (dhcpcMutexSem, WAIT_FOREVER);    if (!pLeaseData->leaseGood)        result = ERROR;    semGive (dhcpcMutexSem);    if (result == ERROR)        return (OK);    if (pLeaseData->leaseType == DHCP_BOOTP)        {        printf ("DHCP server (BOOTP proxy): ");         inet_ntoa_b (pLeaseData->dhcpcParam->siaddr, addrBuf);        printf ("%-18s\n", addrBuf);        return (OK);        }    printf ("DHCP server: ");    inet_ntoa_b (pLeaseData->dhcpcParam->server_id, addrBuf);    printf("%-18s\n", addrBuf);    return (OK);    }/********************************************************************************* dhcpcTimersShow - display current lease timers** This routine prints the time remaining with each of the DHCP lease timers* for the lease identified by <pCookie>.  It has no effect if the indicated* lease is not currently active.** RETURNS: OK if show routine completes, or ERROR otherwise.** ERRNO: *  S_dhcpcLib_BAD_COOKIE**/STATUS dhcpcTimersShow    (    void * 	pCookie 	/* identifier returned by dhcpcInit() */    )    {    int 		offset;    LEASE_DATA * 	pLeaseData = NULL;    STATUS 		result = OK;    time_t current = 0;    long t1;    long t2;    /*     * 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);        }    /* Ignore show request if lease is not initialized or not bound.  */    if (!dhcpcInitialized || !pLeaseData->initFlag)        return (OK);    semTake (dhcpcMutexSem, WAIT_FOREVER);    if (!pLeaseData->leaseGood)        result = ERROR;    semGive (dhcpcMutexSem);    if (result == ERROR)        return (OK);    if (pLeaseData->leaseType == DHCP_BOOTP)        {        printf ("No timer values: BOOTP reply accepted.\n");        return (OK);        }     if (dhcpTime (&current) == -1)        {        printf ("time() error in dhcpcTimerShow() routine.\n");        return (ERROR);        }    t1 = pLeaseData->dhcpcParam->lease_origin +              pLeaseData->dhcpcParam->dhcp_t1 - current;    t2 = pLeaseData->dhcpcParam->lease_origin +              pLeaseData->dhcpcParam->dhcp_t2 - current;       if (t1 <= 0)        printf ("Timer T1 expired.\n");    else        printf ("Timer T1: %ld seconds remaining.\n", t1);       if (t2 <= 0)        printf ("Timer T2 expired.\n");    else        printf ("Timer T2: %ld seconds remaining.\n", t2);    return (OK);    }/******************************************************************************** dhcpcParamsShow - display current lease parameters** This routine prints all lease parameters for the lease identified by * <pCookie>.  It has no effect if the indicated lease is not currently active.* * RETURNS: OK, or ERROR if lease identifier unknown.** ERRNO: *  S_dhcpcLib_BAD_COOKIE**/STATUS dhcpcParamsShow    (    void * 	pCookie 	/* identifier returned by dhcpcInit() */    )    {    int 		offset;    LEASE_DATA * 	pLeaseData = NULL;    STATUS 		result = OK;    int loop;    struct dhcp_param * 	pDhcpcParam;    char addrBuf [INET_ADDR_LEN];    /*     * 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);        }    /* Ignore show request if lease is not initialized or not bound.  */    if (!dhcpcInitialized || !pLeaseData->initFlag)        return (OK);    semTake (dhcpcMutexSem, WAIT_FOREVER);    if (!pLeaseData->leaseGood)        result = ERROR;    semGive (dhcpcMutexSem);    if (result == ERROR)        return (OK);    if (pLeaseData->leaseType == DHCP_BOOTP)        {        printf ("No parameter values: BOOTP reply accepted.\n");        return (OK);        }    pDhcpcParam = pLeaseData->dhcpcParam;    /* Print any string parameters.  */    if (pDhcpcParam->sname != NULL)        printf ("DHCP server name: %s\n", pDhcpcParam->sname);     if (pDhcpcParam->file != NULL)        printf ("Boot file name: %s\n", pDhcpcParam->file);    if (pDhcpcParam->hostname != NULL)        printf ("DHCP client name: %s\n", pDhcpcParam->hostname);    if (pDhcpcParam->merit_dump != NULL)        printf ("Merit dump file: %s\n", pDhcpcParam->merit_dump);    if (pDhcpcParam->dns_domain != NULL)        printf ("DNS domain name: %s\n", pDhcpcParam->dns_domain);    if (pDhcpcParam->root_path != NULL)        printf ("Client root path: %s\n", pDhcpcParam->root_path);    if (pDhcpcParam->extensions_path != NULL)        printf ("Options extension path: %s\n", pDhcpcParam->extensions_path);    if (pDhcpcParam->nis_domain != NULL)        printf ("NIS domain: %s\n", pDhcpcParam->nis_domain);    if (pDhcpcParam->nb_scope != NULL)        printf ("NetBIOS over TCP/IP scope: %s\n", pDhcpcParam->nb_scope);    if (pDhcpcParam->errmsg != NULL)        printf ("Error message: %s\n", pDhcpcParam->errmsg);    if (pDhcpcParam->nisp_domain != NULL)        printf ("NIS+ domain: %s\n", pDhcpcParam->nisp_domain);    /* Print all TRUE boolean parameters.  */    if (pDhcpcParam->ip_forward)        printf ("IP forwarding enabled.\n");    if (pDhcpcParam->nonlocal_srcroute)        printf ("Non-local source route forwarding enabled.\n");    if (pDhcpcParam->all_subnet_local)        printf ("All subnets are local is TRUE.\n");     if (pDhcpcParam->mask_discover)        printf ("ICMP mask discovery enabled.\n");    if (pDhcpcParam->mask_supplier)        printf ("ICMP mask supplier is TRUE.\n");    if (pDhcpcParam->router_discover)        printf ("Router discovery enabled.\n");    if (pDhcpcParam->trailer)        printf ("ARP trailers enabled.\n");      if (pDhcpcParam->ether_encap)        printf ("RFC 1042 Ethernet encapsulation enabled.\n");    else        printf ("RFC 894 Ethernet encapsulation enabled.\n");    if (pDhcpcParam->keepalive_garba)        printf ("TCP keepalive garbage octet enabled.\n");    /* Print all non-zero single numeric parameters.  */    if (pDhcpcParam->time_offset != 0)        printf ("Client time offset: %ld\n", pDhcpcParam->time_offset);    if (pDhcpcParam->bootsize != 0)        printf ("Boot image size: %d\n", pDhcpcParam->bootsize);     if (pDhcpcParam->max_dgram_size != 0)        printf ("Maximum datagram size: %d\n", pDhcpcParam->max_dgram_size);    if (pDhcpcParam->default_ip_ttl != 0)        printf ("Default IP Time-to-live: %d\n",                pDhcpcParam->default_ip_ttl);    if (pDhcpcParam->mtu_aging_timeout != 0)        printf ("Path MTU timeout: %ld\n", pDhcpcParam->mtu_aging_timeout);    if (pDhcpcParam->intf_mtu != 0)        printf ("Interface MTU: %d\n", pDhcpcParam->intf_mtu);    if (pDhcpcParam->arp_cache_timeout != 0)        printf ("ARP cache timeout: %ld\n", pDhcpcParam->arp_cache_timeout);    if (pDhcpcParam->default_tcp_ttl != 0)        printf ("Default TCP Time-to-live: %d\n",                pDhcpcParam->default_tcp_ttl);    if (pDhcpcParam->keepalive_inter != 0)        printf ("TCP keepalive interval: %ld\n",                pDhcpcParam->keepalive_inter);    if (pDhcpcParam->nb_nodetype != 0)        printf ("NetBIOS node type: %d\n", pDhcpcParam->nb_nodetype);    printf ("Client lease origin: %ld\n", pDhcpcParam->lease_origin);    printf ("Client lease duration: %ld\n", pDhcpcParam->lease_duration);    if (pDhcpcParam->dhcp_t1 != 0)        printf ("Client renewal (T1) time value: %ld\n",                pDhcpcParam->dhcp_t1);    if (pDhcpcParam->dhcp_t2 != 0)        printf ("Client rebinding (T2) time value: %ld\n",                pDhcpcParam->dhcp_t2);    /* Print multiple numeric parameters.  */    if (pDhcpcParam->mtu_plateau_table != NULL)        {         printf ("MTU plateau table:\n ");         if (pDhcpcParam->mtu_plateau_table->shortnum != NULL)            {            for (loop = 0; loop < pDhcpcParam->mtu_plateau_table->num; loop++)               printf ("%d ", pDhcpcParam->mtu_plateau_table->shortnum [loop]);            printf ("\n");            }         else            printf ("empty.\n");        }    /* Print any single IP addresses.  */    if (pDhcpcParam->server_id.s_addr != 0)        {        printf ("DHCP server: ");        inet_ntoa_b (pDhcpcParam->server_id, addrBuf);        printf ("%-18s\n", addrBuf);        }    if (pDhcpcParam->ciaddr.s_addr != 0)        {        printf ("Client IP address: ");        inet_ntoa_b (pDhcpcParam->ciaddr, addrBuf);        printf ("%-18s\n", addrBuf);        }    if (pDhcpcParam->yiaddr.s_addr != 0)        {        printf ("Assigned IP address: ");        inet_ntoa_b (pDhcpcParam->yiaddr, addrBuf);        printf ("%-18s\n", addrBuf);        }    if (pDhcpcParam->siaddr.s_addr != 0)        {        printf ("Next server IP address: ");        inet_ntoa_b (pDhcpcParam->siaddr, addrBuf);        printf ("%-18s\n", addrBuf);        }    if (pDhcpcParam->giaddr.s_addr != 0)        {        printf ("Relay agent IP address: ");        inet_ntoa_b (pDhcpcParam->giaddr, addrBuf);        printf ("%-18s\n", addrBuf);        }    if (pDhcpcParam->subnet_mask != NULL)

⌨️ 快捷键说明

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