📄 dhcpcbootlib.c
字号:
* This routine filters out ARP replies from incoming ethernet traffic. * It is called by the network interface driver when a new input frame comes * in from the network. It is attached to the network driver with `etherHook'* routines.** ERRNO: N/A** RETURNS: TRUE if the ethernet frame is handled by this routine. No further* processing by the network driver is needed.* FALSE if the frame is not an ARP reply. The ethernet frame is then* handled by the network driver.** NOMANUAL*/ BOOL dhcpcBootArpInputHook ( struct ifnet * pIf, /* interface where packet was received */ char * pInput, /* contents of received packet */ int length /* length of received packet */ ) { struct ether_header * pEtherHdr; /* pointer to ethernet header */ struct ether_arp * pArp; /* pointer to ethernet ARP packet */ int bufLen; pEtherHdr = (struct ether_header *)pInput; if (length <= SIZEOF_ETHERHEADER) return (FALSE); if (ntohs (pEtherHdr->ether_type != ETHERTYPE_ARP)) return (FALSE); /* * Copy the input packet one byte at a time to accomodate board * specific memory access requirements. */ bufLen = length - SIZEOF_ETHERHEADER; /* Adjust message size (ignores trailers added by some drivers). */ if (bufLen > sizeof (struct ether_arp)) bufLen = sizeof (struct ether_arp); bcopyBytes ( (char *) ( (u_char *)pInput + SIZEOF_ETHERHEADER), inputBuffer, bufLen); pArp = (struct ether_arp *)&inputBuffer; /* * Check if the packet is a valid ARP reply. */ if (pArp->arp_op != ARPOP_REPLY) return FALSE; /* Check address of sender against (our) address stored in global. */ if (bcmp ( (char *)dhcpcBootArpSpa, (char *)pArp->arp_spa, pArp->arp_pln) != 0) return FALSE; /* Valid reply: signal state machine to continue. */ semGive (dhcpcBootArpEventSem); /* Delete input hook so only one ARP message is accepted. */ if (muxDevExists (pIf->if_name, pIf->if_unit)) etherInputHookDelete (dhcpcBootArpInputHook, pIf->if_name, pIf->if_unit); else etherInputHookDelete (dhcpcBootArpInputHook, NULL, pIf->if_unit); return (TRUE); }/******************************************************************************** dhcpcBootParamsCopy - copy current network parameters.** This routine copies the retrieved set of configuration parameters to the * caller-supplied structure. It is called internally by the * dhcpcBootParamsGet() routine.** RETURNS: N/A** ERRNO: N/A** NOMANUAL*/LOCAL void dhcpcBootParamsCopy ( struct dhcp_param * pParamList ) { int loop; int limit = 0; /* Process all string parameters. */ bcopy (dhcpcBootParam->got_option, pParamList->got_option, GOTOPTSIZ); if (pParamList->sname != NULL && dhcpcBootParam->sname != NULL) strcpy (pParamList->sname, dhcpcBootParam->sname); if (pParamList->file != NULL && dhcpcBootParam->file != NULL) strcpy (pParamList->file, dhcpcBootParam->file); if (pParamList->hostname != NULL && dhcpcBootParam->hostname != NULL) strcpy (pParamList->hostname, dhcpcBootParam->hostname); if (pParamList->merit_dump != NULL && dhcpcBootParam->merit_dump != NULL) strcpy (pParamList->merit_dump, dhcpcBootParam->merit_dump); if (pParamList->dns_domain != NULL && dhcpcBootParam->dns_domain != NULL) strcpy (pParamList->dns_domain, dhcpcBootParam->dns_domain); if (pParamList->root_path != NULL && dhcpcBootParam->root_path != NULL) strcpy (pParamList->root_path, dhcpcBootParam->root_path); if (pParamList->extensions_path != NULL && dhcpcBootParam->extensions_path != NULL) strcpy (pParamList->extensions_path, dhcpcBootParam->extensions_path); if (pParamList->nis_domain != NULL && dhcpcBootParam->nis_domain != NULL) strcpy(pParamList->nis_domain, dhcpcBootParam->nis_domain); if (pParamList->nb_scope != NULL && dhcpcBootParam->nb_scope != NULL) strcpy(pParamList->nb_scope, dhcpcBootParam->nb_scope); if (pParamList->errmsg != NULL && dhcpcBootParam->errmsg != NULL) strcpy(pParamList->errmsg, dhcpcBootParam->errmsg); if (pParamList->nisp_domain != NULL && dhcpcBootParam->nisp_domain != NULL) strcpy(pParamList->nisp_domain, dhcpcBootParam->nisp_domain); /* Process all boolean parameters. */ pParamList->ip_forward = dhcpcBootParam->ip_forward; pParamList->nonlocal_srcroute = dhcpcBootParam->nonlocal_srcroute; pParamList->all_subnet_local = dhcpcBootParam->all_subnet_local; pParamList->mask_discover = dhcpcBootParam->mask_discover; pParamList->mask_supplier = dhcpcBootParam->mask_supplier; pParamList->router_discover = dhcpcBootParam->router_discover; pParamList->trailer = dhcpcBootParam->trailer; pParamList->ether_encap = dhcpcBootParam->ether_encap; pParamList->keepalive_garba = dhcpcBootParam->keepalive_garba; /* Process all single numeric parameters. */ pParamList->time_offset = dhcpcBootParam->time_offset; pParamList->bootsize = dhcpcBootParam->bootsize; pParamList->max_dgram_size = dhcpcBootParam->max_dgram_size; pParamList->default_ip_ttl = dhcpcBootParam->default_ip_ttl; pParamList->mtu_aging_timeout = dhcpcBootParam->mtu_aging_timeout; pParamList->intf_mtu = dhcpcBootParam->intf_mtu; pParamList->arp_cache_timeout = dhcpcBootParam->arp_cache_timeout; pParamList->default_tcp_ttl = dhcpcBootParam->default_tcp_ttl; pParamList->keepalive_inter = dhcpcBootParam->keepalive_inter; pParamList->nb_nodetype = dhcpcBootParam->nb_nodetype; pParamList->lease_origin = dhcpcBootParam->lease_origin; pParamList->lease_duration = dhcpcBootParam->lease_duration; pParamList->dhcp_t1 = dhcpcBootParam->dhcp_t1; pParamList->dhcp_t2 = dhcpcBootParam->dhcp_t2; /* Process multiple numeric parameters. */ if (pParamList->mtu_plateau_table != NULL && dhcpcBootParam->mtu_plateau_table != NULL) { limit = 0; if (pParamList->mtu_plateau_table->shortnum != NULL) { limit = (pParamList->mtu_plateau_table->num < dhcpcBootParam->mtu_plateau_table->num) ? pParamList->mtu_plateau_table->num : dhcpcBootParam->mtu_plateau_table->num; for (loop = 0; loop < limit; loop++) { pParamList->mtu_plateau_table->shortnum [loop] = dhcpcBootParam->mtu_plateau_table->shortnum [loop]; } } pParamList->mtu_plateau_table->num = limit; } /* Process single IP addresses. */ pParamList->server_id = dhcpcBootParam->server_id; pParamList->ciaddr = dhcpcBootParam->ciaddr; pParamList->yiaddr = dhcpcBootParam->yiaddr; pParamList->siaddr = dhcpcBootParam->siaddr; pParamList->giaddr = dhcpcBootParam->giaddr; if (pParamList->subnet_mask != NULL && dhcpcBootParam->subnet_mask != NULL) bcopy ( (char *)dhcpcBootParam->subnet_mask, (char *)pParamList->subnet_mask, sizeof (struct in_addr)); if (pParamList->swap_server != NULL && dhcpcBootParam->swap_server != NULL) bcopy ( (char *)dhcpcBootParam->swap_server, (char *)pParamList->swap_server, sizeof (struct in_addr)); if (pParamList->brdcast_addr != NULL && dhcpcBootParam->brdcast_addr != NULL) bcopy( (char *)dhcpcBootParam->brdcast_addr, (char *)pParamList->brdcast_addr, sizeof (struct in_addr)); pParamList->router_solicit = dhcpcBootParam->router_solicit; /* Process multiple IP addresses. */ if (pParamList->router != NULL && dhcpcBootParam->router != NULL) { limit = 0; if (pParamList->router->addr != NULL) { limit = (pParamList->router->num < dhcpcBootParam->router->num) ? pParamList->router->num : dhcpcBootParam->router->num; for (loop = 0; loop < limit; loop++) { bcopy( (char *)&dhcpcBootParam->router->addr [loop], (char *)&pParamList->router->addr [loop], sizeof (struct in_addr)); } } pParamList->router->num = limit; } if (pParamList->time_server != NULL && dhcpcBootParam->time_server != NULL) { limit = 0; if (pParamList->time_server->addr != NULL) { limit = (pParamList->time_server->num < dhcpcBootParam->time_server->num) ? pParamList->time_server->num : dhcpcBootParam->time_server->num; for (loop = 0; loop < limit; loop++) { bcopy ( (char *)&dhcpcBootParam->time_server->addr [loop], (char *)&pParamList->time_server->addr [loop], sizeof (struct in_addr)); } } pParamList->time_server->num = limit; } if (pParamList->name_server != NULL && dhcpcBootParam->name_server != NULL) { limit = 0; if (pParamList->name_server->addr != NULL) { limit = (pParamList->name_server->num < dhcpcBootParam->name_server->num) ? pParamList->name_server->num : dhcpcBootParam->name_server->num; for (loop = 0; loop < limit; loop++) { bcopy( (char *)&dhcpcBootParam->name_server->addr [loop], (char *)&pParamList->name_server->addr [loop], sizeof (struct in_addr)); } } pParamList->name_server->num = limit; } if (pParamList->dns_server != NULL && dhcpcBootParam->dns_server != NULL) { limit = 0; if (pParamList->dns_server->addr != NULL) { limit = (pParamList->dns_server->num < dhcpcBootParam->dns_server->num) ? pParamList->dns_server->num : dhcpcBootParam->dns_server->num; for (loop = 0; loop < limit; loop++) { bcopy( (char *)&dhcpcBootParam->dns_server->addr [loop], (char *)&pParamList->dns_server->addr [loop], sizeof (struct in_addr)); } } pParamList->dns_server->num = limit; } if (pParamList->log_server != NULL && dhcpcBootParam->log_server != NULL) { limit = 0; if (pParamList->log_server->addr != NULL) { limit = (pParamList->log_server->num < dhcpcBootParam->log_server->num) ? pParamList->log_server->num : dhcpcBootParam->log_server->num; for (loop = 0; loop < limit; loop++) { bcopy( (char *)&dhcpcBootParam->log_server->addr [loop], (char *)&pParamList->log_server->addr [loop], sizeof (struct in_addr)); } } pParamList->log_server->num = limit; } if (pParamList->cookie_server != NULL && dhcpcBootParam->cookie_server != NULL) { limit = 0; if (pParamList->cookie_server->addr != NULL) { limit = (pParamList->log_server->num < dhcpcBootParam->log_server->num) ? pParamList->log_server->num : dhcpcBootParam->log_server->num; for (loop = 0; loop < limit; loop++) { bcopy ( (char *)&dhcpcBootParam->cookie_server->addr [loop], (char *)&pParamList->cookie_server->addr [loop], sizeof (struct in_addr)); } } pParamList->cookie_server->num = limit; } if (pParamList->lpr_server != NULL && dhcpcBootParam->lpr_server != NULL) { limit = 0; if (pParamList->lpr_server->addr != NULL) { limit = (pParamList->lpr_server->num < dhcpcBootParam->lpr_server->num) ? pParamList->lpr_server->num : dhcpcBootParam->lpr_server->num; for (loop = 0; loop < limit; loop++) { bcopy( (char *)&dhcpcBootParam->lpr_server->addr [loop], (char *)&pParamList->lpr_server->addr [loop], sizeof (struct in_addr)); } } pParamList->lpr_server->num = limit; } if (pParamList->impress_server != NULL && dhcpcBootParam->impress_server != NULL) { limit = 0; if (pParamList->impress_server->addr != NULL) { limit = (pParamList->impress_server->num < dhcpcBootParam->impress_server->num) ? pParamList->impress_server->num : dhcpcBootParam->impress_server->num; for (loop = 0; loop < limit; loop++) { bcopy ( (char *)&dhcpcBootParam->impress_server->addr [loop], (char *)&pParamList->impress_server->addr [loop], sizeof (struct in_addr)); } } pParamList->impress_server->num = limit; } if (pParamList->rls_server != NULL && dhcpcBootParam->rls_server != NULL) { limit =0; if (pParamList->rls_server->addr != NULL) { limit = (pParamList->rls_server->num < dhcpcBootParam->rls_server->num) ? pParamList->rls_server->num : dhcpcBootParam->rls_server->num; for (loop = 0; loop < limit; loop++) { bcopy( (char *)&dhcpcBootParam->rls_server->addr [loop], (char *)&pParamList->rls_server->addr [loop], sizeof (struct in_addr)); } } pParamList->rls_server->num = limit; } if (pParamList->nis_server != NULL && dhcpcBootParam->nis_server != NULL) { limit = 0; if (pParamList->nis_server->addr != NULL) { limit = (pParamList->nis_server->num < dhcpcBootParam->nis_server->num) ? pParamList->nis_server->num : dhcpcBootParam->nis_server->num; for (loop = 0; loop < limit; loop++) { bcopy( (char *)&dhcpcBootParam->nis_server->addr [loop], (char *)&pParamList->nis_server->addr [loop], sizeof (struct in_addr));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -