?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 6

Line No. Rev Author Line
1 6 kaklik /*! \file icmp.c \brief ICMP Protocol Library. */
2 //*****************************************************************************
3 //
4 // File Name : 'icmp.c'
5 // Title : ICMP (Internet Control Message Protocol) Protocol Library
6 // Author : Pascal Stang
7 // Created : 9/10/2004
8 // Revised : 7/3/2005
9 // Version : 0.1
10 // Target MCU : Atmel AVR series
11 // Editor Tabs : 4
12 //
13 //*****************************************************************************
14  
15 #include "global.h"
16 #include "net.h"
17 #include "nic.h"
18 #include "arp.h"
19 #include "icmp.h"
20  
21 #include "rprintf.h"
22 #include "debug.h"
23  
24 //extern void nicSend(unsigned int len, unsigned char* packet);
25  
26 // global variables
27  
28  
29 // functions
30 void icmpInit(void)
31 {
32 }
33  
34 void icmpIpIn(icmpip_hdr* packet)
35 {
36 // check ICMP type
37 switch(packet->icmp.type)
38 {
39 case ICMP_TYPE_ECHOREQUEST:
40 // echo request
41 icmpEchoRequest(packet);
42 break;
43 default:
44 break;
45 }
46 }
47  
48 void icmpEchoRequest(icmpip_hdr* packet)
49 {
50 uint32_t tempIp;
51  
52 // change type to reply
53 packet->icmp.type = ICMP_TYPE_ECHOREPLY;
54 // recalculate checksum
55 packet->icmp.icmpchksum = 0;
56 packet->icmp.icmpchksum = netChecksum((u08*)&packet->icmp, htons(packet->ip.len)-IP_HEADER_LEN);
57 // return to sender
58 tempIp = packet->ip.destipaddr;
59 packet->ip.destipaddr = packet->ip.srcipaddr;
60 packet->ip.srcipaddr = tempIp;
61 // add ethernet routing
62 arpIpOut((struct netEthIpHeader*)(((u08*)packet)-ETH_HEADER_LEN), 0);
63  
64 // debugging
65 #if NET_DEBUG >= 2
66 icmpPrintHeader(packet);
67 //debugPrintHexTable(htons(packet->ip.len), (u08*)packet);
68 #endif
69  
70 // send it (packet->ip.len+ETH_HEADER_LEN
71 nicSend(htons(packet->ip.len)+ETH_HEADER_LEN, (((u08*)packet)-ETH_HEADER_LEN));
72 }
73  
74 #ifdef ICMP_DEBUG_PRINT
75 void icmpPrintHeader(icmpip_hdr* packet)
76 {
77 rprintfProgStrM("ICMP Packet:\r\n");
78 // print source IP address
79 rprintfProgStrM("SrcIpAddr: "); netPrintIPAddr(htonl(packet->ip.srcipaddr)); rprintfCRLF();
80 // print dest IP address
81 rprintfProgStrM("DstIpAddr: "); netPrintIPAddr(htonl(packet->ip.destipaddr)); rprintfCRLF();
82 // print type
83 rprintfProgStrM("Type : ");
84 switch(packet->icmp.type)
85 {
86 case ICMP_TYPE_ECHOREQUEST: rprintfProgStrM("ECHO REQUEST"); break;
87 case ICMP_TYPE_ECHOREPLY: rprintfProgStrM("ECHO REPLY"); break;
88 default: rprintfProgStrM("UNKNOWN"); break;
89 }
90 rprintfCRLF();
91 // print code
92 rprintfProgStrM("Code : 0x"); rprintfu08(packet->icmp.icode); rprintfCRLF();
93 }
94 #endif
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3