📄 ip.lst
字号:
C51 COMPILER V6.23a IP 05/11/2004 18:03:26 PAGE 1
C51 COMPILER V6.23a, COMPILATION OF MODULE IP
OBJECT MODULE PLACED IN ip.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE ip.c LARGE ROM(COMPACT) BROWSE DEBUG OBJECTEXTEND
stmt level source
1
2 #include "ethernet.h"
3 #include "arp.h"
4 #include "ip.h"
5 #include "icmp.h"
6 #include "udp.h"
7 extern Net_inf_struc net_inf;
8 void ip_config(Uint8 *pip_local, Uint8 *pip_remote,Uint8 *pip_gateway,Uint8 *pip_mask)
9 {
10 1 if(pip_local==NULL)
11 1 memset(net_inf.ip_local,0,INADDR_LEN);
12 1 else
13 1 memcpy(net_inf.ip_local,pip_local,INADDR_LEN);
14 1 if(pip_remote==NULL)
15 1 memset(net_inf.ip_remote,0,INADDR_LEN);
16 1 else
17 1 memcpy(net_inf.ip_remote,pip_remote,INADDR_LEN);
18 1 if(pip_gateway==NULL)
19 1 memset(net_inf.ip_gateway,0,INADDR_LEN);
20 1 else
21 1 memcpy(net_inf.ip_gateway,pip_gateway,INADDR_LEN);
22 1 if(pip_mask==NULL)
23 1 memset(net_inf.ip_mask,0,INADDR_LEN);
24 1 else
25 1 memcpy(net_inf.ip_mask,pip_mask,INADDR_LEN);
26 1
27 1 }
28 Uint16 cpu_checksum( Uint16* pBuffer, Uint16 aLength)
29 {
30 1 Uint32 checksum=0;
31 1 Uint16 i;
32 1 for(i=0;i<aLength;i++)
33 1 checksum+=(Uint32)(*pBuffer++);
34 1 checksum=(checksum>>16)+(checksum&0xffff);
35 1 checksum=(checksum>>16)+(checksum&0xffff);
36 1 return (Uint16)(~checksum);
37 1 }
38
39
40 //-----------------------------------------------------------------
41 Bool ip_send(Uint8 *pBuffer)
42 {
43 1 Ether_header_struc* ethHdr;
44 1 Ip_struc* ipPkt;
45 1 Uint8 *pmac;
46 1 ethHdr = ( Ether_header_struc*)pBuffer;
47 1 ipPkt = ( Ip_struc*) (pBuffer + sizeof(Ether_header_struc));
48 1 ipPkt->ip_sum =0;
49 1 ipPkt->ip_sum = cpu_checksum(( Uint16 *) ipPkt, 10);
50 1
51 1 pmac= get_macaddr(ipPkt->ip_dst);
52 1 if(pmac==NULL){
53 2 //can't find
54 2 arp_send(ARPOP_REQUEST, 0, ipPkt->ip_dst);
55 2 memset(ethHdr->ether_dhost, 0xff, ETHER_ADDR_LEN);
C51 COMPILER V6.23a IP 05/11/2004 18:03:26 PAGE 2
56 2 }
57 1 else{
58 2 memcpy(ethHdr->ether_dhost,pmac, ETHER_ADDR_LEN);
59 2 }
60 1 // MAC
61 1 ethHdr->ether_type = ETHERTYPE_IP;
62 1 memcpy(ethHdr->ether_shost,net_inf.mac,ETHER_ADDR_LEN);
63 1 return ethernet_send(pBuffer, ipPkt->ip_len + sizeof(Ether_header_struc));
64 1 }
65
66 //-----------------------------------------------------------------
67 // IP packet receive & action
68 Bool ip_receive(Uint8* pBuffer)
69 {
70 1 Ip_struc* ipPkt;
71 1 Uint8 i;
72 1 ipPkt = ( Ip_struc*) (pBuffer + sizeof( Ether_header_struc));
73 1 if(ipPkt->ip_hl_v != IPVERSION_HEADERLEN)
74 1 return FALSE;
75 1 i = memcmp(net_inf.ip_local,ipPkt->ip_dst, INADDR_LEN);
76 1 if(i){//not for this ip, check boardcast addr
77 2 for(i=0;i<INADDR_LEN;i++){
78 3 if(ipPkt->ip_dst[i] != net_inf.ip_local[i]){
79 4 if(ipPkt->ip_dst[i] != 0xff)
80 4 return FALSE;
81 4 }
82 3 }
83 2 }
84 1 if (cpu_checksum(( Uint16 *) ipPkt, 10) == 0){
85 2 switch(ipPkt->ip_p){
86 3 case IPPROTO_ICMP:{
87 4 icmp_receive(pBuffer);
88 4 break;
89 4 }
90 3 case IPPROTO_UDP:{
91 4 udp_process((Uint8*)ipPkt + sizeof(Ip_struc));
92 4 break;
93 4 }
94 3 case IPPROTO_TCP:{
95 4 // tcp_receive(ipPkt->ip_len - sizeof(Ip_struc));
96 4 break;
97 4 }
98 3 default:
99 3 return FALSE;
100 3 }
101 2 }
102 1 return TRUE;
103 1 }
104
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1047 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- 41
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -