📄 dhcpccommonlib.c
字号:
** RETURNS: OK if processing completed, or ERROR if it fails. ** ERRNO: N/A** NOMANUAL*/STATUS dhcpcEventHandle ( EVENT_DATA * pNewEvent /* pointer to event descriptor */ ) { STATUS result; LEASE_DATA * pLeaseData; /* * 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 *)pNewEvent->leaseId; /* * Execute routines from the state machine until processing is complete. * In general, all processing is performed by a single routine. If * additional routines are needed, the called routine returns DHCPC_MORE, * and the next routine is executed immediately. Processing always stops * once the occurrence of a subsequent timeout or message arrival is * guaranteed. The processing routine returns OK at that point, allowing * the monitor task to handle the next event. If a routine returns * ERROR, the state machine for the lease is reset to the initial state. * Finally, a routine returns DHCPC_DONE after releasing its lease and * removing the data structures. */ result = DHCPC_MORE; while (result == DHCPC_MORE) { result = (*fsm [pLeaseData->currState]) (pNewEvent); if (result == ERROR) {#ifdef DHCPC_DEBUG logMsg ("Error in finite state machine.\n", 0, 0, 0, 0, 0, 0);#endif /* Lease negotiation failed - set to execute init() routine. */ pLeaseData->prevState = DHCPC_ERROR; pLeaseData->currState = INIT; /* Disable the underlying network interface if necessary. */ if (pLeaseData->autoConfig || pLeaseData->leaseType == DHCP_AUTOMATIC) { down_if (&pLeaseData->ifData); } /* * Signal the (failed) completion of the negotiation process * if the dhcpcBind() call is executing synchronously. */ if (pLeaseData->waitFlag) semGive (pLeaseData->leaseSem); /* Send a notification of the failure to any event hook routine. */ if (pLeaseData->eventHookRtn != NULL) result = (* pLeaseData->eventHookRtn) (DHCPC_LEASE_INVALID, pNewEvent->leaseId); return (ERROR); } /* * When a lease entry is removed, return an indicator to the monitor * task so that is will reset the corresponding list entry to NULL. */ if (result == DHCPC_DONE) return (DHCPC_DONE); if (pLeaseData->currState == BOUND && pLeaseData->prevState != BOUND) { /* * Signal the successful completion of the negotiation * process if the dhcpBind() call is executing synchronously. */ if (pLeaseData->waitFlag) semGive (pLeaseData->leaseSem); /* Set the bound routine to exit after starting the timer. */ pNewEvent->type = DHCPC_STATE_BEGIN; }#ifdef DHCPC_DEBUG logMsg ("Next state= %d\n", pLeaseData->currState, 0, 0, 0, 0, 0);#endif } return (OK); }/********************************************************************************* dhcpcOptionFind - find the requested option** This routine returns the address and length of a requested option* for use by dhcpcOptionGet(). It should only be called internally.** RETURNS: Pointer to start of data for option, or NULL if not present.** ERRNO: N/A** NOMANUAL** INTERNAL* The <pAmount> parameter is dereferenced unconditionally, but since this* routine is only called internally, it is never NULL.*/char *dhcpcOptionFind ( LEASE_DATA * pLeaseData, /* lease-specific data structures */ int option, /* RFC 1533 option tag */ int * pAmount /* Number of bytes for option */ ) { char * pData = NULL; /* Location of option data. */ struct dhcp_param * pDhcpcParam; pDhcpcParam = pLeaseData->dhcpcParam; switch (option) { case _DHCP_SUBNET_MASK_TAG: if (pDhcpcParam->subnet_mask != NULL) { *pAmount = sizeof (struct in_addr); pData = (char *)pDhcpcParam->subnet_mask; } break; case _DHCP_TIME_OFFSET_TAG: *pAmount = sizeof (long); pData = (char *)&pDhcpcParam->time_offset; break; case _DHCP_ROUTER_TAG: if (pDhcpcParam->router != NULL) { *pAmount = pDhcpcParam->router->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->router->addr; } break; case _DHCP_TIME_SERVER_TAG: if (pDhcpcParam->time_server != NULL) { *pAmount = pDhcpcParam->time_server->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->time_server->addr; } break; case _DHCP_NAME_SERVER_TAG: if (pDhcpcParam->name_server != NULL) { *pAmount = pDhcpcParam->name_server->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->name_server->addr; } break; case _DHCP_DNS_SERVER_TAG: if (pDhcpcParam->dns_server != NULL) { *pAmount = pDhcpcParam->dns_server->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->dns_server->addr; } break; case _DHCP_LOG_SERVER_TAG: if (pDhcpcParam->log_server != NULL) { *pAmount = pDhcpcParam->log_server->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->log_server->addr; } break; case _DHCP_COOKIE_SERVER_TAG: if (pDhcpcParam->cookie_server != NULL) { *pAmount = pDhcpcParam->cookie_server->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->cookie_server->addr; } break; case _DHCP_LPR_SERVER_TAG: if (pDhcpcParam->lpr_server != NULL) { *pAmount = pDhcpcParam->lpr_server->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->lpr_server->addr; } break; case _DHCP_IMPRESS_SERVER_TAG: if (pDhcpcParam->impress_server != NULL) { *pAmount = pDhcpcParam->impress_server->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->impress_server->addr; } break; case _DHCP_RLS_SERVER_TAG: if (pDhcpcParam->rls_server != NULL) { *pAmount = pDhcpcParam->rls_server->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->rls_server->addr; } break; case _DHCP_HOSTNAME_TAG: *pAmount = strlen (pDhcpcParam->hostname); pData = pDhcpcParam->hostname; break; case _DHCP_BOOTSIZE_TAG: *pAmount = sizeof (unsigned short); pData = (char *)&pDhcpcParam->bootsize; break; case _DHCP_MERIT_DUMP_TAG: *pAmount = strlen (pDhcpcParam->merit_dump); pData = pDhcpcParam->merit_dump; break; case _DHCP_DNS_DOMAIN_TAG: *pAmount = strlen (pDhcpcParam->dns_domain); pData = pDhcpcParam->dns_domain; break; case _DHCP_SWAP_SERVER_TAG: if (pDhcpcParam->swap_server != NULL) { *pAmount = sizeof (struct in_addr); pData = (char *)pDhcpcParam->swap_server; } break; case _DHCP_ROOT_PATH_TAG: *pAmount = strlen (pDhcpcParam->root_path); pData = pDhcpcParam->root_path; break; case _DHCP_EXTENSIONS_PATH_TAG: *pAmount = strlen (pDhcpcParam->extensions_path); pData = pDhcpcParam->extensions_path; break; case _DHCP_IP_FORWARD_TAG: *pAmount = sizeof (unsigned char); pData = (char *)&pDhcpcParam->ip_forward; break; case _DHCP_NONLOCAL_SRCROUTE_TAG: *pAmount = sizeof (unsigned char); pData = (char *)&pDhcpcParam->nonlocal_srcroute; break; case _DHCP_POLICY_FILTER_TAG: if (pDhcpcParam->policy_filter != NULL) { *pAmount = pDhcpcParam->policy_filter->num * 2 * sizeof (struct in_addr); pData = (char *)pDhcpcParam->policy_filter->addr; } break; case _DHCP_MAX_DGRAM_SIZE_TAG: *pAmount = sizeof (unsigned short); pData = (char *)&pDhcpcParam->max_dgram_size; break; case _DHCP_DEFAULT_IP_TTL_TAG: *pAmount = sizeof (unsigned char); pData = (char *)&pDhcpcParam->default_ip_ttl; break; case _DHCP_MTU_AGING_TIMEOUT_TAG: *pAmount = sizeof (unsigned long); pData = (char *)&pDhcpcParam->mtu_aging_timeout; break; case _DHCP_MTU_PLATEAU_TABLE_TAG: if (pDhcpcParam->mtu_plateau_table != NULL) { *pAmount = pDhcpcParam->mtu_plateau_table->num * sizeof (unsigned short); pData = (char *)pDhcpcParam->mtu_plateau_table->shortnum; } break; case _DHCP_IF_MTU_TAG: *pAmount = sizeof (unsigned short); pData = (char *)&pDhcpcParam->intf_mtu; break; case _DHCP_ALL_SUBNET_LOCAL_TAG: *pAmount = sizeof (unsigned char); pData = (char *)&pDhcpcParam->all_subnet_local; break; case _DHCP_BRDCAST_ADDR_TAG: if (pDhcpcParam->brdcast_addr != NULL) { *pAmount = sizeof (struct in_addr); pData = (char *)pDhcpcParam->brdcast_addr; } break; case _DHCP_MASK_DISCOVER_TAG: *pAmount = sizeof (unsigned char); pData = (char *)&pDhcpcParam->mask_discover; break; case _DHCP_MASK_SUPPLIER_TAG: *pAmount = sizeof (unsigned char); pData = (char *)&pDhcpcParam->mask_supplier; break; case _DHCP_ROUTER_DISCOVER_TAG: *pAmount = sizeof (unsigned char); pData = (char *)&pDhcpcParam->router_discover; break; case _DHCP_ROUTER_SOLICIT_TAG: if (pDhcpcParam->router_solicit.s_addr != 0) { *pAmount = sizeof (struct in_addr); pData = (char *)&pDhcpcParam->router_solicit; } break; case _DHCP_STATIC_ROUTE_TAG: if (pDhcpcParam->static_route != NULL) { *pAmount = pDhcpcParam->static_route->num * 2 * sizeof (struct in_addr); pData = (char *)pDhcpcParam->static_route->addr; } break; case _DHCP_TRAILER_TAG: *pAmount = sizeof (unsigned char); pData = (char *)&pDhcpcParam->trailer; break; case _DHCP_ARP_CACHE_TIMEOUT_TAG: *pAmount = sizeof (unsigned long); pData = (char *)&pDhcpcParam->arp_cache_timeout; break; case _DHCP_ETHER_ENCAP_TAG: *pAmount = sizeof (unsigned char); pData = (char *)&pDhcpcParam->ether_encap; break; case _DHCP_DEFAULT_TCP_TTL_TAG: *pAmount = sizeof (unsigned char); pData = (char *)&pDhcpcParam->default_tcp_ttl; break; case _DHCP_KEEPALIVE_INTERVAL_TAG: *pAmount = sizeof (unsigned long); pData = (char *)&pDhcpcParam->keepalive_inter; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -