2021-07-03 05:07:57 +01:00
< ! DOCTYPE HTML >
< html >
< head >
< meta http - equiv = " Content-Type " content = " text/html;charset=US-ASCII " >
< meta name = " generator " content = " ZealOS V0.05 " >
< style type = " text/css " >
body { background - color : # 000000 ; }
. cF0 { color : # ffffff ; background - color : # 000000 ; }
. cF1 { color : # 3465 a4 ; background - color : # 000000 ; }
. cF2 { color : # 4e9 a06 ; background - color : # 000000 ; }
. cF3 { color : # 06 989 a ; background - color : # 000000 ; }
. cF4 { color : # a24444 ; background - color : # 000000 ; }
. cF5 { color : # 75507 b ; background - color : # 000000 ; }
. cF6 { color : # ce982f ; background - color : # 000000 ; }
. cF7 { color : # bcc0b9 ; background - color : # 000000 ; }
. cF8 { color : # 555753 ; background - color : # 000000 ; }
. cF9 { color : # 729f cf ; background - color : # 000000 ; }
. cFA { color : # 82 bc49 ; background - color : # 000000 ; }
. cFB { color : # 34e2 e2 ; background - color : # 000000 ; }
. cFC { color : # ac3535 ; background - color : # 000000 ; }
. cFD { color : # ad7fa8 ; background - color : # 000000 ; }
. cFE { color : # fce94f ; background - color : # 000000 ; }
. cFF { color : # 000000 ; background - color : # 000000 ; }
< / style >
< / head >
< body >
2021-07-05 01:12:38 +01:00
< pre style = " font-family:monospace;font-size:12pt " >
2021-07-03 05:07:57 +01:00
< a name = " l1 " > < / a > < span class = cF0 > # < / span > < span class = cF1 > define < / span > < span class = cF0 > ICMP_TYPE_ECHO_REPLY < / span > < span class = cFE > 0 < / span > < span class = cF0 >
< a name = " l2 " > < / a > # < / span > < span class = cF1 > define < / span > < span class = cF0 > ICMP_TYPE_ECHO_REQUEST < / span > < span class = cFE > 8 < / span > < span class = cF0 >
2021-07-04 23:11:34 +01:00
< a name = " l3 " > < / a > # < / span > < span class = cF1 > define < / span > < span class = cF0 > ICMP_CODE_ECHO < / span > < span class = cFE > 0 < / span > < span class = cF0 > < / span > < span class = cF2 > // RFC 792: "Echo or Echo Reply Message". 0 is the only code explicitly defined for Echo.</span><span class=cF0>
2021-07-03 05:07:57 +01:00
< a name = " l4 " > < / a >
< a name = " l5 " > < / a > < / span > < span class = cF1 > class < / span > < span class = cF0 > CICMPHeader
< a name = " l6 " > < / a > {
2021-07-04 23:11:34 +01:00
< a name = " l7 " > < / a > < / span > < span class = cF1 > U8 < / span > < span class = cF0 > type ;
< a name = " l8 " > < / a > < / span > < span class = cF1 > U8 < / span > < span class = cF0 > code ;
< a name = " l9 " > < / a > < / span > < span class = cF9 > U16 < / span > < span class = cF0 > checksum ;
2021-07-03 05:07:57 +01:00
< a name = " l10 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l11 " > < / a > < / span > < span class = cF9 > U16 < / span > < span class = cF0 > identifier ;
< a name = " l12 " > < / a > < / span > < span class = cF9 > U16 < / span > < span class = cF0 > sequence_number ;
2021-07-03 05:07:57 +01:00
< a name = " l13 " > < / a > } ;
< a name = " l14 " > < / a >
< a name = " l15 " > < / a >
< a name = " l16 " > < / a > < / span > < span class = cF1 > U0 < / span > < span class = cF0 > ICMPReplySend ( < / span > < span class = cF9 > U32 < / span > < span class = cF0 > destination_ip_address ,
2021-07-04 23:11:34 +01:00
< a name = " l17 " > < / a > < / span > < span class = cF9 > U16 < / span > < span class = cF0 > identifier ,
< a name = " l18 " > < / a > < / span > < span class = cF9 > U16 < / span > < span class = cF0 > sequence_number ,
< a name = " l19 " > < / a > < / span > < span class = cF9 > U16 < / span > < span class = cF0 > request_checksum ,
< a name = " l20 " > < / a > < / span > < span class = cF1 > U8 < / span > < span class = cF0 > * payload ,
< a name = " l21 " > < / a > < / span > < span class = cF9 > I64 < / span > < span class = cF0 > length )
2021-07-03 05:07:57 +01:00
< a name = " l22 " > < / a > {
2021-07-04 23:11:34 +01:00
< a name = " l23 " > < / a > < / span > < span class = cF1 > U8 < / span > < span class = cF0 > * icmp_frame ;
< a name = " l24 " > < / a > < / span > < span class = cF9 > I64 < / span > < span class = cF0 > de_index ;
< a name = " l25 " > < / a > CICMPHeader * header ;
2021-07-03 05:07:57 +01:00
< a name = " l26 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l27 " > < / a > de_index = IPV4PacketAllocate ( & amp ; icmp_frame ,
< a name = " l28 " > < / a > IP_PROTOCOL_ICMP ,
< a name = " l29 " > < / a > IPV4AddressGet ,
< a name = " l30 " > < / a > destination_ip_address ,
< a name = " l31 " > < / a > < / span > < span class = cF1 > sizeof < / span > < span class = cF7 > ( < / span > < span class = cF0 > CICMPHeader < / span > < span class = cF7 > ) < / span > < span class = cF0 > + length ) ;
< a name = " l32 " > < / a > < / span > < span class = cF1 > if < / span > < span class = cF0 > ( de_index & lt ; < / span > < span class = cFE > 0 < / span > < span class = cF0 > )
< a name = " l33 " > < / a > < / span > < span class = cF7 > { < / span > < span class = cF0 >
< a name = " l34 " > < / a > NetErr ( < / span > < span class = cF6 > & quot ; ICMP SEND REPLY : Failed to allocate IPV4 packet . & quot ; < / span > < span class = cF0 > ) ;
< a name = " l35 " > < / a > < / span > < span class = cF1 > return < / span > < span class = cF0 > ;
< a name = " l36 " > < / a > < / span > < span class = cF7 > } < / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = " l37 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l38 " > < / a > header = icmp_frame ;
2021-07-03 05:07:57 +01:00
< a name = " l39 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l40 " > < / a > header - & gt ; type = ICMP_TYPE_ECHO_REPLY ;
< a name = " l41 " > < / a > header - & gt ; code = < / span > < span class = cFE > 0 < / span > < span class = cF0 > ; < / span > < span class = cF2 > // why is 0 okay?</span><span class=cF0>
< a name = " l42 " > < / a > header - & gt ; checksum = < / span > < span class = cF5 > EndianU16 < / span > < span class = cF0 > ( < / span > < span class = cF5 > EndianU16 < / span > < span class = cF7 > ( < / span > < span class = cF0 > request_checksum < / span > < span class = cF7 > ) < / span > < span class = cF0 > + < / span > < span class = cFE > 0x0800 < / span > < span class = cF0 > ) ;
< a name = " l43 " > < / a > header - & gt ; identifier = identifier ;
< a name = " l44 " > < / a > header - & gt ; sequence_number = sequence_number ;
< a name = " l45 " > < / a > < / span > < span class = cF2 > // TODO: header checksum is awful. Shrine says hack alert.</span><span class=cF0>
2021-07-03 05:07:57 +01:00
< a name = " l46 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l47 " > < / a > < / span > < span class = cF5 > MemCopy < / span > < span class = cF0 > ( icmp_frame + < / span > < span class = cF1 > sizeof < / span > < span class = cF7 > ( < / span > < span class = cF0 > CICMPHeader < / span > < span class = cF7 > ) < / span > < span class = cF0 > , payload , length ) ;
2021-07-03 05:07:57 +01:00
< a name = " l48 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l49 " > < / a > IPV4PacketFinish ( de_index ) ;
2021-07-03 05:07:57 +01:00
< a name = " l50 " > < / a > }
< a name = " l51 " > < / a >
< a name = " l52 " > < / a > < / span > < span class = cF9 > I64 < / span > < span class = cF0 > ICMPHandler ( CIPV4Packet * packet )
< a name = " l53 " > < / a > {
2021-07-04 23:11:34 +01:00
< a name = " l54 " > < / a > CICMPHeader * header ;
2021-07-03 05:07:57 +01:00
< a name = " l55 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l56 " > < / a > < / span > < span class = cF1 > if < / span > < span class = cF0 > ( packet - & gt ; length & lt ; < / span > < span class = cF1 > sizeof < / span > < span class = cF7 > ( < / span > < span class = cF0 > CICMPHeader < / span > < span class = cF7 > ) < / span > < span class = cF0 > )
< a name = " l57 " > < / a > < / span > < span class = cF7 > { < / span > < span class = cF0 >
< a name = " l58 " > < / a > NetErr ( < / span > < span class = cF6 > & quot ; ICMP HANDLER : Caught wrong IPV4 length . & quot ; < / span > < span class = cF0 > ) ;
< a name = " l59 " > < / a > < / span > < span class = cF1 > return < / span > < span class = cF0 > - < / span > < span class = cFE > 1 < / span > < span class = cF0 > ;
< a name = " l60 " > < / a > < / span > < span class = cF7 > } < / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = " l61 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l62 " > < / a > header = packet - & gt ; data ;
2021-07-03 05:07:57 +01:00
< a name = " l63 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l64 " > < / a > < / span > < span class = cF1 > if < / span > < span class = cF0 > ( header - & gt ; type = = ICMP_TYPE_ECHO_REQUEST & amp ; & amp ; header - & gt ; code = = ICMP_CODE_ECHO )
< a name = " l65 " > < / a > < / span > < span class = cF7 > { < / span > < span class = cF0 >
< a name = " l66 " > < / a > ARPCachePut ( packet - & gt ; source_ip_address , packet - & gt ; ethernet_frame - & gt ; source_address ) ;
2021-07-03 05:07:57 +01:00
< a name = " l67 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l68 " > < / a > ICMPReplySend ( packet - & gt ; source_ip_address ,
< a name = " l69 " > < / a > header - & gt ; identifier ,
< a name = " l70 " > < / a > header - & gt ; sequence_number ,
< a name = " l71 " > < / a > header - & gt ; checksum ,
< a name = " l72 " > < / a > packet - & gt ; data + < / span > < span class = cF1 > sizeof < / span > < span class = cF7 > ( < / span > < span class = cF0 > CICMPHeader < / span > < span class = cF7 > ) < / span > < span class = cF0 > , < / span > < span class = cF2 > // Data payload at IPV4Packet data location after the ICMP header</span><span class=cF0>
< a name = " l73 " > < / a > packet - & gt ; length - < / span > < span class = cF1 > sizeof < / span > < span class = cF7 > ( < / span > < span class = cF0 > CICMPHeader < / span > < span class = cF7 > ) < / span > < span class = cF0 > ) ; < / span > < span class = cF2 > // Payload length is size of packet after dropping header.</span><span class=cF0>
< a name = " l74 " > < / a > < / span > < span class = cF7 > } < / span > < span class = cF0 >
< a name = " l75 " > < / a > < / span > < span class = cF1 > else < / span > < span class = cF0 >
< a name = " l76 " > < / a > NetWarn ( < / span > < span class = cF6 > & quot ; ICMP HANDLER : Unhandled ICMP packet . type , code : 0 x % X , 0 x % X & quot ; < / span > < span class = cF0 > , header - & gt ; type , header - & gt ; code ) ;
2021-07-03 05:07:57 +01:00
< a name = " l77 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l78 " > < / a > NetLog ( < / span > < span class = cF6 > & quot ; ICMP HANDLER : Exiting . & quot ; < / span > < span class = cF0 > ) ;
2021-07-03 05:07:57 +01:00
< a name = " l79 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l80 " > < / a > < / span > < span class = cF1 > return < / span > < span class = cF0 > < / span > < span class = cFE > 0 < / span > < span class = cF0 > ;
2021-07-03 05:07:57 +01:00
< a name = " l81 " > < / a > } < / span > < / pre > < / body >
< / html >