📄 dhcpc_8c-source.html
字号:
00671 <span class="keywordflow">break</span>;00672 }00673 }00674 <span class="comment">/* ok, processed all, got what we were looking for ? */</span>00675 <span class="keywordflow">if</span>((!<a class="code" href="dhcpc_8c.html#a6">dhcpc_server_identifier</a>)||(msg_type!=DHCP_OFFER)){00676 DEBUGOUT(<span class="stringliteral">" Not a DHCP offer or no server identifier; Aborting...\r\n"</span>);00677 <span class="keywordflow">return</span>(-1);00678 }00679 00680 DEBUGOUT(<span class="stringliteral">" DHCP offer valid, sending DHCP REQUEST; State SELECTING-->REQUESTING\r\n"</span>);00681 <span class="comment">/* we have the offer, contact the server! */</span>00682 <a class="code" href="dhcpc_8c.html#a0">dhcpc_state</a>=DHCP_STATE_REQUESTING;00683 <a class="code" href="dhcpc_8c.html#a7">dhcpc_requested_ip</a>=yiaddr; <span class="comment">/* offered IP ! */</span>00684 00685 <a class="code" href="dhcpc_8c.html#a9">dhcpc_send_message</a>(DHCP_REQUEST);00686 00687 <a class="code" href="dhcpc_8c.html#a4">dhcpc_t1</a>=4; <span class="comment">/* 4 secs for first retransmission */</span>00688 <a class="code" href="dhcpc_8c.html#a5">dhcpc_t2</a>=8; <span class="comment">/* next one after 8 secs */</span>00689 <span class="keywordflow">break</span>;00690 00691 <span class="keywordflow">case</span> DHCP_STATE_REQUESTING:00692 <span class="comment">/* wait for DHCPACK */</span>00693 00694 DEBUGOUT(<span class="stringliteral">"DHCP Client state=REQUESTING; "</span>);00695 00696 <span class="comment">/* is message from the same server who sent the offer </span>00697 <span class="comment"> * and assigned IP == offered IP? This will also reject</span>00698 <span class="comment"> * subsequent DHCPOFFERs from slow DHCP servers.</span>00699 <span class="comment"> */</span>00700 <span class="keywordflow">if</span>((<a class="code" href="dhcpc_8c.html#a6">dhcpc_server_identifier</a>!=ipaddr)||(yiaddr!=<a class="code" href="dhcpc_8c.html#a7">dhcpc_requested_ip</a>)){00701 DEBUGOUT(<span class="stringliteral">"Server or requested IP not the same, dumping..\r\n"</span>);00702 <span class="keywordflow">return</span> (-1);00703 }00704 00705 <span class="comment">/* ok, go through param list and process them. We expect to get</span>00706 <span class="comment"> * all the params here and that this is DHCPACK message</span>00707 <span class="comment"> */</span>00708 DEBUGOUT(<span class="stringliteral">"Received params: "</span>);00709 <span class="keywordflow">while</span>((i=<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>())!=DHCP_OPT_END){00710 00711 <span class="keywordflow">switch</span>(i){00712 <span class="keywordflow">case</span> DHCP_OPT_PAD:00713 <span class="keywordflow">break</span>;00714 <span class="keywordflow">case</span> DHCP_OPT_SUBNET_MASK:00715 temp=<a class="code" href="dhcpc_8c.html#a12">dhcpc_read_n_bytes</a>(<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>());00716 <span class="comment">/* temp holds subnet mask, for now just show it and set params*/</span>00717 localmachine.netmask=temp;00718 DEBUGOUT(<span class="stringliteral">"Subnet mask;"</span>);00719 <span class="keywordflow">break</span>;00720 <span class="keywordflow">case</span> DHCP_OPT_ROUTER:00721 temp=<a class="code" href="dhcpc_8c.html#a12">dhcpc_read_n_bytes</a>(<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>());00722 <span class="comment">/* temp holds gateway IP */</span>00723 localmachine.defgw=temp;00724 DEBUGOUT(<span class="stringliteral">"Gateway IP; "</span>);00725 <span class="keywordflow">break</span>;00726 <span class="keywordflow">case</span> DHCP_OPT_DNS_SERVER:00727 temp=<a class="code" href="dhcpc_8c.html#a12">dhcpc_read_n_bytes</a>(<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>());00728 DEBUGOUT(<span class="stringliteral">"DNS IP;"</span>);00729 <span class="keywordflow">break</span>;00730 <span class="keywordflow">case</span> DHCP_OPT_HOST_NAME:00731 <span class="comment">/* Read host name here and store it */</span>00732 i=<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>(); <span class="comment">/* length of host name */</span>00733 <span class="keywordflow">while</span>(i--){00734 <span class="comment">/* read host name. Store this if necessary */</span>00735 <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00736 }00737 DEBUGOUT(<span class="stringliteral">"Host name; "</span>);00738 <span class="keywordflow">break</span>;00739 <span class="keywordflow">case</span> DHCP_OPT_LEASE_TIME:00740 temp=<a class="code" href="dhcpc_8c.html#a12">dhcpc_read_n_bytes</a>(<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>());00741 <span class="comment">/* time calculation from RFC! These values can also</span>00742 <span class="comment"> * be received directly in options</span>00743 <span class="comment"> */</span>00744 <a class="code" href="dhcpc_8c.html#a4">dhcpc_t1</a>=0.5*temp;00745 <a class="code" href="dhcpc_8c.html#a5">dhcpc_t2</a>=0.875*temp;00746 DEBUGOUT(<span class="stringliteral">"Lease time;"</span>); 00747 <span class="keywordflow">break</span>;00748 <span class="keywordflow">case</span> DHCP_OPT_OVERLOAD:00749 DEBUGOUT(<span class="stringliteral">"Overloaded DHCP message, can't process...\r\n"</span>);00750 <span class="keywordflow">return</span> (-1);00751 <span class="keywordflow">break</span>;00752 <span class="keywordflow">case</span> DHCP_OPT_MSG_TYPE:00753 <span class="comment">/* if this is DHCPACK we can switch state and assume</span>00754 <span class="comment"> * that the parameters are OK</span>00755 <span class="comment"> */</span>00756 <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00757 <span class="keywordflow">if</span>(<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>()==DHCP_ACK){00758 DEBUGOUT(<span class="stringliteral">"DHCP_ACK Message!; State REQUESTING-->BOUND; "</span>);00759 <a class="code" href="dhcpc_8c.html#a0">dhcpc_state</a>=DHCP_STATE_BOUND;00760 00761 <span class="comment">/* we should actually probe the received IP with</span>00762 <span class="comment"> * ARP first, but let's wait with that for </span>00763 <span class="comment"> * now.....</span>00764 <span class="comment"> */</span>00765 localmachine.localip=<a class="code" href="dhcpc_8c.html#a7">dhcpc_requested_ip</a>;00766 <span class="comment">/* dhcpc_requested_ip holds the assigned IP</span>00767 <span class="comment"> * address. USE IT OR LOOSE IT!</span>00768 <span class="comment"> */</span>00769 DEBUGOUT(<span class="stringliteral">"IP address;"</span>);00770 }<span class="keywordflow">else</span>{00771 DEBUGOUT(<span class="stringliteral">"NOT DHCPACK message; dumping...\r\n"</span>);00772 <span class="keywordflow">return</span>(-1);00773 } 00774 <span class="keywordflow">break</span>;00775 <span class="keywordflow">case</span> DHCP_OPT_T1_VALUE:00776 DEBUGOUT(<span class="stringliteral">"T1;"</span>);00777 <a class="code" href="dhcpc_8c.html#a4">dhcpc_t1</a>=<a class="code" href="dhcpc_8c.html#a12">dhcpc_read_n_bytes</a>(<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>());00778 <span class="keywordflow">break</span>;00779 <span class="keywordflow">case</span> DHCP_OPT_T2_VALUE:00780 DEBUGOUT(<span class="stringliteral">"T2; "</span>);00781 <a class="code" href="dhcpc_8c.html#a5">dhcpc_t2</a>=<a class="code" href="dhcpc_8c.html#a12">dhcpc_read_n_bytes</a>(<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>());00782 <span class="keywordflow">break</span>;00783 <span class="keywordflow">default</span>:00784 <a class="code" href="dhcpc_8c.html#a12">dhcpc_read_n_bytes</a>(<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>());00785 <span class="keywordflow">break</span>;00786 }00787 }00788 DEBUGOUT(<span class="stringliteral">"\r\n"</span>);00789 <span class="keywordflow">break</span>;00790 <span class="keywordflow">case</span> DHCP_STATE_RENEWING:00791 <span class="keywordflow">case</span> DHCP_STATE_REBINDING:00792 <span class="keywordflow">case</span> DHCP_STATE_REBOOTING:00793 <span class="comment">/* wait for DHCPACK. If we get DHCPNAK restart. Here</span>00794 <span class="comment"> * we're only interested in ACK and T1 and T2 parameters.</span>00795 <span class="comment"> * NOTE: other parameters can change as well during time(</span>00796 <span class="comment"> * DNS, gateway etc. Add cases similar to those in</span>00797 <span class="comment"> * REQUESTING state here as well if you want those.</span>00798 <span class="comment"> */</span>00799 DEBUGOUT(<span class="stringliteral">"DHCP Client state=REQUESTING or REBINDING; "</span>);00800 <span class="keywordflow">while</span>((i=<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>())!=DHCP_OPT_END){00801 <span class="keywordflow">switch</span>(i){00802 <span class="keywordflow">case</span> DHCP_OPT_PAD:00803 <span class="keywordflow">break</span>;00804 <span class="keywordflow">case</span> DHCP_OPT_LEASE_TIME:00805 DEBUGOUT(<span class="stringliteral">"Lease time; "</span>);00806 temp=<a class="code" href="dhcpc_8c.html#a12">dhcpc_read_n_bytes</a>(<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>());00807
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -