📄 dhcpccommonlib.c
字号:
case _DHCP_KEEPALIVE_GARBAGE_TAG: *pAmount = sizeof (unsigned char); pData = (char *)&pDhcpcParam->keepalive_garba; break; case _DHCP_NIS_DOMAIN_TAG: *pAmount = strlen (pDhcpcParam->nis_domain); pData = pDhcpcParam->nis_domain; break; case _DHCP_NIS_SERVER_TAG: if (pDhcpcParam->nis_server != NULL) { *pAmount = pDhcpcParam->nis_server->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->nis_server->addr; } break; case _DHCP_NTP_SERVER_TAG: if (pDhcpcParam->ntp_server != NULL) { *pAmount = pDhcpcParam->ntp_server->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->ntp_server->addr; } break; case _DHCP_NBN_SERVER_TAG: if (pDhcpcParam->nbn_server != NULL) { *pAmount = pDhcpcParam->nbn_server->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->nbn_server->addr; } break; case _DHCP_NBDD_SERVER_TAG: if (pDhcpcParam->nbdd_server != NULL) { *pAmount = pDhcpcParam->nbdd_server->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->nbdd_server->addr; } break; case _DHCP_NB_NODETYPE_TAG: *pAmount = sizeof (unsigned char); pData = (char *)&pDhcpcParam->nb_nodetype; break; case _DHCP_NB_SCOPE_TAG: *pAmount = strlen (pDhcpcParam->nb_scope); pData = pDhcpcParam->nb_scope; break; case _DHCP_XFONT_SERVER_TAG: if (pDhcpcParam->xfont_server != NULL) { *pAmount = pDhcpcParam->xfont_server->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->xfont_server->addr; } break; case _DHCP_XDISPLAY_MANAGER_TAG: if (pDhcpcParam->xdisplay_manager != NULL) { *pAmount = pDhcpcParam->xdisplay_manager->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->xdisplay_manager->addr; } break; case _DHCP_LEASE_TIME_TAG: *pAmount = sizeof (unsigned long); pData = (char *)&pDhcpcParam->lease_duration; break; case _DHCP_SERVER_ID_TAG: *pAmount = sizeof (struct in_addr); pData = (char *)&pDhcpcParam->server_id; break; case _DHCP_ERRMSG_TAG: *pAmount = strlen (pDhcpcParam->errmsg); pData = pDhcpcParam->errmsg; break; case _DHCP_T1_TAG: *pAmount = sizeof (unsigned long); pData = (char *)&pDhcpcParam->dhcp_t1; break; case _DHCP_T2_TAG: *pAmount = sizeof (unsigned long); pData = (char *)&pDhcpcParam->dhcp_t2; break; case _DHCP_NISP_DOMAIN_TAG: *pAmount = strlen (pDhcpcParam->nisp_domain); pData = pDhcpcParam->nisp_domain; break; case _DHCP_NISP_SERVER_TAG: if (pDhcpcParam->nisp_server != NULL) { *pAmount = pDhcpcParam->nisp_server->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->nisp_server->addr; } break; case _DHCP_MOBILEIP_HA_TAG: if (pDhcpcParam->mobileip_ha != NULL) { *pAmount = pDhcpcParam->mobileip_ha->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->mobileip_ha->addr; } break; case _DHCP_SMTP_SERVER_TAG: if (pDhcpcParam->smtp_server != NULL) { *pAmount = pDhcpcParam->smtp_server->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->smtp_server->addr; } break; case _DHCP_POP3_SERVER_TAG: if (pDhcpcParam->pop3_server != NULL) { *pAmount = pDhcpcParam->pop3_server->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->pop3_server->addr; } break; case _DHCP_NNTP_SERVER_TAG: if (pDhcpcParam->nntp_server != NULL) { *pAmount = pDhcpcParam->nntp_server->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->nntp_server->addr; } break; case _DHCP_DFLT_WWW_SERVER_TAG: if (pDhcpcParam->dflt_www_server != NULL) { *pAmount = pDhcpcParam->dflt_www_server->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->dflt_www_server->addr; } break; case _DHCP_DFLT_FINGER_SERVER_TAG: if (pDhcpcParam->dflt_finger_server != NULL) { *pAmount = pDhcpcParam->dflt_finger_server->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->dflt_finger_server->addr; } break; case _DHCP_DFLT_IRC_SERVER_TAG: if (pDhcpcParam->dflt_irc_server != NULL) { *pAmount = pDhcpcParam->dflt_irc_server->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->dflt_irc_server->addr; } break; case _DHCP_STREETTALK_SERVER_TAG: if (pDhcpcParam->streettalk_server != NULL) { *pAmount = pDhcpcParam->streettalk_server->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->streettalk_server->addr; } break; case _DHCP_STDA_SERVER_TAG: if (pDhcpcParam->stda_server != NULL) { *pAmount = pDhcpcParam->stda_server->num * sizeof (struct in_addr); pData = (char *)pDhcpcParam->stda_server->addr; } break; default: break; } return (pData); }/********************************************************************************* dhcpcDestCheck - prepare incoming messages for further examination** This routine checks incoming network traffic for UDP packets arriving* at the DHCP client port. Any Ethernet frames which match those criteria* are copied to an interface-specific buffer for further testing. This * routine is called by the internal packet filter as the first step in * retrieving DHCP server replies.** RETURNS: OK if tests pass, or ERROR if message doesn't match expected values.** ERRNO: N/A** NOMANUAL*/ LOCAL STATUS dhcpcDestCheck ( char * pInput, /* contents of received packet */ int length /* length of received packet */ ) { struct ether_header * pEtherHdr; /* pointer to ethernet header */ struct ip * pIpHdr; /* pointer to IP header */ struct udphdr * pUdpHdr; /* pointer to UDP header */ pEtherHdr = (struct ether_header *) pInput; pIpHdr = (struct ip *) &pInput [SIZEOF_ETHERHEADER];#if BSD<44 pUdpHdr = (struct udphdr *) &pInput [SIZEOF_ETHERHEADER + (pIpHdr->ip_v_hl & 0xf) * _BYTESPERWORD];#else pUdpHdr = (struct udphdr *) &pInput [SIZEOF_ETHERHEADER + pIpHdr->ip_hl * _BYTESPERWORD];#endif if (length <= SIZEOF_ETHERHEADER) return (ERROR); if (ntohs (pEtherHdr->ether_type) != ETHERTYPE_IP) return (ERROR); if (pIpHdr->ip_p != IPPROTO_UDP) return (ERROR); if (pUdpHdr->uh_dport != dhcpc_port) return (ERROR); /* * Copy the input packet one byte at a time to accomodate board * specific memory access requirements. Use offset to provide * 4-byte alignment of IP header needed by Sun BSP's. */ bcopyBytes (pInput, &dhcpif.rbuf [DHCPC_OFF], length); /* WIDE project DHCP code: initializes pointers. */ align_msg (&dhcpcIfMsg, &dhcpif.rbuf [DHCPC_OFF]); return (OK); }/********************************************************************************* dhcpcXidVerify - verify that the transaction ID belongs to a known lease** This routine compares the transaction identifier in an incoming DHCP * message with all known transaction identifiers in use by the available* leases. If no match is found, the corresponding DHCP message will be* rejected.** RETURNS: Lease identifier if transaction ID recognized, or NULL otherwise.** ERRNO: N/A** NOMANUAL*/void * dhcpcXidVerify ( unsigned long transId ) { int loop; void * pLeaseId = NULL; for (loop = 0; loop < dhcpcMaxLeases; loop++) if (dhcpcLeaseList [loop] != NULL && transId == dhcpcLeaseList [loop]->xid) { pLeaseId = dhcpcLeaseList [loop]; break; } if (loop == dhcpcMaxLeases) return (NULL); return (pLeaseId); }/********************************************************************************* dhcpcBodyCheck - verify that a received packet is a valid server reply** This routine examines an IP message received at the DHCP client port to* determine if it is a DHCP or BOOTP server reply. It is used internally by * the Ethernet input hook as the final step in detecting incoming DHCP/BOOTP* messages.** RETURNS: OK if message recognized, or ERROR otherwise.** ERRNO: N/A** NOMANUAL*/STATUS dhcpcBodyCheck (void) { u_short ripcksum = 0; u_short rudpcksum = 0; struct ps_udph rpudph; /* Check if UDP and DHCP portions are present (set by align_msg). */ if (dhcpcIfMsg.udp == NULL || dhcpcIfMsg.dhcp == NULL) return (ERROR); /* Construct a UDP pseudo-header. */ bzero ( (char *)&rpudph, sizeof (rpudph)); ripcksum = dhcpcIfMsg.ip->ip_sum; dhcpcIfMsg.ip->ip_sum = 0; rudpcksum = dhcpcIfMsg.udp->uh_sum; dhcpcIfMsg.udp->uh_sum = 0; rpudph.zero = 0; rpudph.prto = IPPROTO_UDP; rpudph.srcip.s_addr = dhcpcIfMsg.ip->ip_src.s_addr; rpudph.dstip.s_addr = dhcpcIfMsg.ip->ip_dst.s_addr; rpudph.ulen = dhcpcIfMsg.udp->uh_ulen; /* Check lengths of each portion of message. */ if (ntohs (dhcpcIfMsg.ip->ip_len) < DFLTBOOTPLEN + UDPHL + IPHL) return (ERROR); if (ntohs (dhcpcIfMsg.udp->uh_ulen) < DFLTBOOTPLEN + UDPHL) return (ERROR); /* Verify message received at client port. */ if (dhcpcIfMsg.udp->uh_dport != dhcpc_port) return (ERROR); /* Check message IP checksum. */#if BSD<44 if (ripcksum != checksum ( (u_short *)dhcpcIfMsg.ip, (dhcpcIfMsg.ip->ip_v_hl & 0xf) << 2))#else if (ripcksum != checksum ( (u_short *)dhcpcIfMsg.ip, dhcpcIfMsg.ip->ip_hl << 2))#endif return (ERROR); /* Check message UDP checksum. */ if (dhcpcIfMsg.udp->uh_sum != 0 && rudpcksum != udp_cksum (&rpudph, (char *)dhcpcIfMsg.udp, ntohs (rpudph.ulen))) return (ERROR); /* Check DHCP message opcode, transaction ID, and magic cookie. */ if (dhcpcIfMsg.dhcp->op != BOOTREPLY) return (ERROR); if (bcmp (dhcpcIfMsg.dhcp->options, (char *)dhcpCookie, MAGIC_LEN) != 0) return (ERROR); return (OK); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -