📄 dhcpc_8c-source.html
字号:
00509 *buf_ptr++=DHCP_OPT_DNS_SERVER;00510 *buf_ptr++=DHCP_OPT_HOST_NAME;00511 *buf_ptr++=DHCP_OPT_LEASE_TIME;00512 *buf_ptr++=DHCP_OPT_T1_VALUE;00513 *buf_ptr++=DHCP_OPT_T2_VALUE;00514 <span class="keywordflow">break</span>; 00515 00516 <span class="keywordflow">default</span>:00517 <span class="keywordflow">break</span>;00518 }00519 00520 <span class="comment">/* end option */</span>00521 *buf_ptr++=DHCP_OPT_END;00522 <span class="keywordflow">while</span>(buf_ptr<(net_buf+<a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a>+300))00523 *buf_ptr++=0x00;00524 00525 <span class="comment">/* send message. Send unicast when server's IP is available (only</span>00526 <span class="comment"> * in selected states, check RFC) and allowed (also check RFCs).</span>00527 <span class="comment"> * Check RFCs in any case :-)</span>00528 <span class="comment"> */</span>00529 <span class="keywordflow">if</span>((<a class="code" href="dhcpc_8c.html#a0">dhcpc_state</a>==DHCP_STATE_BOUND)00530 ||(<a class="code" href="dhcpc_8c.html#a0">dhcpc_state</a>==DHCP_STATE_RENEWING))00531 <span class="keywordflow">return</span> <a class="code" href="udp_8c.html#a7">udp_send</a>(<a class="code" href="dhcpc_8c.html#a2">dhcpc_soc_handle</a>,<a class="code" href="dhcpc_8c.html#a6">dhcpc_server_identifier</a>,DHCP_SERVER_PORT,net_buf+<a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a>,<a class="code" href="group__opentcp__config.html#a4">NETWORK_TX_BUFFER_SIZE</a>-<a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a>,buf_ptr-(net_buf+<a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a>));00532 <span class="keywordflow">else</span>00533 <span class="keywordflow">return</span> <a class="code" href="udp_8c.html#a7">udp_send</a>(<a class="code" href="dhcpc_8c.html#a2">dhcpc_soc_handle</a>,IP_BROADCAST_ADDRESS,DHCP_SERVER_PORT,net_buf+<a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a>,<a class="code" href="group__opentcp__config.html#a4">NETWORK_TX_BUFFER_SIZE</a>-<a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a>,buf_ptr-(net_buf+<a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a>));00534 00535 }00536 <a name="l00549"></a><a class="code" href="dhcpc_8c.html#a12">00549</a> UINT32 <a class="code" href="dhcpc_8c.html#a12">dhcpc_read_n_bytes</a>(UINT8 n){00550 UINT32 ret_value=0;00551 <span class="comment">/* read n bytes and return value of last of them (max 4, can be less)*/</span>00552 <span class="keywordflow">while</span>(n--){00553 ret_value=(ret_value<<8)|<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00554 }00555 <span class="keywordflow">return</span> ret_value;00556 }00557 <a name="l00568"></a><a class="code" href="dhcpc_8c.html#a8">00568</a> INT32 <a class="code" href="dhcpc_8c.html#a8">dhcpc_eventlistener</a>(INT8 cbhandle, UINT8 event, UINT32 ipaddr, UINT16 port, UINT16 buffindex, UINT16 datalen)00569 {00570 UINT32 temp;00571 UINT32 yiaddr; <span class="comment">/* assigned IP */</span>00572 UINT8 i;00573 UINT8 msg_type=0;00574 00575 <span class="keywordflow">if</span>(cbhandle!=<a class="code" href="dhcpc_8c.html#a2">dhcpc_soc_handle</a>){00576 DEBUGOUT(<span class="stringliteral">"DHCP Client: Not my handle!!!!\r\n"</span>);00577 <span class="keywordflow">return</span> (-1);00578 }00579 00580 <span class="keywordflow">switch</span>(event){00581 <span class="keywordflow">case</span> <a class="code" href="tcp__ip_8h.html#a31">UDP_EVENT_DATA</a>:00582 DEBUGOUT(<span class="stringliteral">"DHCP Client: Received data...."</span>);00583 <span class="comment">/* initial correctness checking */</span>00584 <span class="keywordflow">if</span>(datalen<236){00585 DEBUGOUT(<span class="stringliteral">"length not OK, dumping packet\r\n"</span>);00586 <span class="keywordflow">return</span> (-1);00587 }00588 00589 <span class="comment">/* op */</span>00590 <span class="keywordflow">if</span>(<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>()!=BOOT_REPLY){00591 DEBUGOUT(<span class="stringliteral">"op not BOOT_REPLY, dumping packet\r\n"</span>);00592 <span class="keywordflow">return</span> (-1);00593 }00594 00595 <span class="comment">/* skip htype, hlen, hops */</span>00596 <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00597 <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00598 <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00599 00600 <span class="comment">/* check xid */</span>00601 temp=0;00602 temp|=((UINT32)<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>())<<24;00603 temp|=((UINT32)<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>())<<16;00604 temp|=((UINT32)<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>())<<8;00605 temp|=<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00606 <span class="keywordflow">if</span>(temp!=0xAABBCCDD){00607 DEBUGOUT(<span class="stringliteral">"xid not OK, dumping packet\r\n"</span>);00608 <span class="keywordflow">return</span> (-1);00609 }00610 00611 <span class="comment">/* skip secs, flags, ciaddr and find yiaddr*/</span>00612 <span class="keywordflow">for</span>(i=0;i<12;i++)00613 yiaddr=(yiaddr<<8)|<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00614 00615 <span class="comment">/* skip siaddr, giaddr, chaddr, sname, file. </span>00616 <span class="comment"> * We get all the info we need from options.</span>00617 <span class="comment"> */</span>00618 <span class="keywordflow">for</span>(i=0;i<216;i++)00619 <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00620 00621 <span class="comment">/* check magic cookie */</span>00622 temp=0;00623 temp|=((UINT32)<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>())<<24;00624 temp|=((UINT32)<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>())<<16;00625 temp|=((UINT32)<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>())<<8;00626 temp|=<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00627 <span class="keywordflow">if</span>(temp!=0x63825363){00628 DEBUGOUT(<span class="stringliteral">"magic cookie not OK, dumping packet\r\n"</span>);00629 <span class="keywordflow">return</span> (-1);00630 }00631 DEBUGOUT(<span class="stringliteral">"initial check OK, proceeding...\r\n"</span>);00632 <span class="comment">/* process further received message, depends on state we're in */</span>00633 <span class="keywordflow">switch</span>(dhcpc_state){00634 <span class="keywordflow">case</span> DHCP_STATE_SELECTING:00635 <span class="comment">/* select first DHCPOFFER */</span>00636 <a class="code" href="dhcpc_8c.html#a6">dhcpc_server_identifier</a>=0;00637 DEBUGOUT(<span class="stringliteral">"DHCP Client state=SELECTING; "</span>);00638 <span class="comment">/* iterate through parameters and try to find if </span>00639 <span class="comment"> * this really is DHCPOFFER. Besides that, we're</span>00640 <span class="comment"> * only interested in SERVERIDENTIFIER option (which</span>00641 <span class="comment"> * is actually server's IP address)</span>00642 <span class="comment"> */</span>00643 <span class="keywordflow">while</span>((i=<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>())!=DHCP_OPT_END){00644 <span class="comment">/* there are still options to process*/</span>00645 <span class="keywordflow">switch</span>(i){00646 <span class="keywordflow">case</span> DHCP_OPT_MSG_TYPE:00647 <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00648 msg_type=<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>(); 00649 <span class="keywordflow">break</span>;00650 <span class="keywordflow">case</span> DHCP_OPT_SERV_IDENT:00651 <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00652 <span class="comment">/* Read SERVER IDENTIFIER */</span>00653 <a class="code" href="dhcpc_8c.html#a6">dhcpc_server_identifier</a>|=((UINT32)<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>())<<24;00654 <a class="code" href="dhcpc_8c.html#a6">dhcpc_server_identifier</a>|=((UINT32)<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>())<<16;00655 <a class="code" href="dhcpc_8c.html#a6">dhcpc_server_identifier</a>|=((UINT32)<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>())<<8;00656 <a class="code" href="dhcpc_8c.html#a6">dhcpc_server_identifier</a>|=<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00657 <span class="keywordflow">break</span>;00658 <span class="keywordflow">case</span> DHCP_OPT_OVERLOAD:00659 <span class="comment">/* we can't process overloaded messages */</span>00660 DEBUGOUT(<span class="stringliteral">"Overloaded DHCP message, can't process...\r\n"</span>);00661 <span class="keywordflow">return</span> (-1);00662 <span class="keywordflow">break</span>;00663 <span class="keywordflow">default</span>:00664 <span class="comment">/* not interesting parameter for now */</span>00665 <span class="keywordflow">if</span>(i==DHCP_OPT_PAD)00666 <span class="keywordflow">break</span>;00667 i=<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>(); <span class="comment">/* parameter length */</span>00668 <span class="keywordflow">while</span>(i--){00669 <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00670 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -