2021-07-03 05:07:57 +01:00
<!DOCTYPE HTML>
< html >
< head >
< meta http-equiv = "Content-Type" content = "text/html;charset=US-ASCII" >
2021-12-11 11:10:58 +00:00
< meta name = "generator" content = "ZealOS V1.07" >
2021-07-03 05:07:57 +01:00
< style type = "text/css" >
2021-10-08 07:06:11 +01:00
body {background-color:#1f1f1f;}
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
.cF1{color:#4f84a6;background-color:#1f1f1f;}
.cF2{color:#73a255;background-color:#1f1f1f;}
.cF3{color:#297582;background-color:#1f1f1f;}
.cF4{color:#b34f4b;background-color:#1f1f1f;}
.cF5{color:#8a52c3;background-color:#1f1f1f;}
.cF6{color:#b7822f;background-color:#1f1f1f;}
.cF7{color:#444444;background-color:#1f1f1f;}
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
.cF9{color:#94bfde;background-color:#1f1f1f;}
.cFA{color:#a1ce97;background-color:#1f1f1f;}
.cFB{color:#6db4be;background-color:#1f1f1f;}
.cFC{color:#e88e88;background-color:#1f1f1f;}
.cFD{color:#ca94e8;background-color:#1f1f1f;}
.cFE{color:#d4b475;background-color:#1f1f1f;}
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
2021-07-03 05:07:57 +01:00
< / style >
< / head >
< body >
2021-07-05 01:12:38 +01:00
< pre style = "font-family:monospace;font-size:12pt" >
2021-07-04 23:11:34 +01:00
< a name = "l1" > < / a > < span class = cF0 > #< / span > < span class = cF1 > define< / span > < span class = cF0 > IPV4_ERR_ADDR_INVALID -< / span > < span class = cFE > 200001< / span > < span class = cF0 >
< a name = "l2" > < / a > #< / span > < span class = cF1 > define< / span > < span class = cF0 > IPV4_ERR_HOST_UNREACHABLE -< / span > < span class = cFE > 200002< / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = "l3" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l4" > < / a > #< / span > < span class = cF1 > define< / span > < span class = cF0 > IPV4_TTL < / span > < span class = cFE > 64< / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = "l5" > < / a >
< a name = "l6" > < / a > < / span > < span class = cF2 > //Look up IP Protocol Numbers online to see many more.< / span > < span class = cF0 >
2021-07-04 23:11:34 +01:00
< a name = "l7" > < / a > #< / span > < span class = cF1 > define< / span > < span class = cF0 > IP_PROTOCOL_ICMP < / span > < span class = cFE > 0x01< / span > < span class = cF0 >
< a name = "l8" > < / a > #< / span > < span class = cF1 > define< / span > < span class = cF0 > IP_PROTOCOL_TCP < / span > < span class = cFE > 0x06< / span > < span class = cF0 >
< a name = "l9" > < / a > #< / span > < span class = cF1 > define< / span > < span class = cF0 > IP_PROTOCOL_UDP < / span > < span class = cFE > 0x11< / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = "l10" > < / a >
< a name = "l11" > < / a > < / span > < span class = cF1 > class< / span > < span class = cF0 > CIPV4Packet
< a name = "l12" > < / a > {
2021-07-04 23:11:34 +01:00
< a name = "l13" > < / a > CEthernetFrame *ethernet_frame;
2021-07-03 05:07:57 +01:00
< a name = "l14" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l15" > < / a > < / span > < span class = cF9 > U32< / span > < span class = cF0 > source_ip_address;
< a name = "l16" > < / a > < / span > < span class = cF9 > U32< / span > < span class = cF0 > destination_ip_address;
2021-07-03 05:07:57 +01:00
< a name = "l17" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l18" > < / a > < / span > < span class = cF1 > U8< / span > < span class = cF0 > protocol;
< a name = "l19" > < / a > < / span > < span class = cF1 > U8< / span > < span class = cF0 > padding[< / span > < span class = cFE > 7< / span > < span class = cF0 > ];
2021-07-03 05:07:57 +01:00
< a name = "l20" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l21" > < / a > < / span > < span class = cF1 > U8< / span > < span class = cF0 > *data;
< a name = "l22" > < / a > < / span > < span class = cF9 > I64< / span > < span class = cF0 > length;
2021-07-03 05:07:57 +01:00
< a name = "l23" > < / a > };
< a name = "l24" > < / a >
< a name = "l25" > < / a > < / span > < span class = cF1 > class< / span > < span class = cF0 > CIPV4Header
< a name = "l26" > < / a > { < / span > < span class = cF2 > // note: U4's in some U8s.< / span > < span class = cF0 >
2021-07-04 23:11:34 +01:00
< a name = "l27" > < / a > < / span > < span class = cF1 > U8< / span > < span class = cF0 > version_ihl; < / span > < span class = cF2 > // Version for IPV4 is 4. IHL=Internet Header Length< / span > < span class = cF0 >
< a name = "l28" > < / a > < / span > < span class = cF1 > U8< / span > < span class = cF0 > dscp_ecn; < / span > < span class = cF2 > // DSCP=Differentiated Services Code Point. ECN=Explicit Congestion Notification< / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = "l29" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l30" > < / a > < / span > < span class = cF9 > U16< / span > < span class = cF0 > total_length; < / span > < span class = cF2 > // min 20B max 65535< / span > < span class = cF0 >
< a name = "l31" > < / a > < / span > < span class = cF9 > U16< / span > < span class = cF0 > identification;
< a name = "l32" > < / a > < / span > < span class = cF9 > U16< / span > < span class = cF0 > flags_fragment_offset; < / span > < span class = cF2 > // flags first(?) 3 bits. fragment offset min 0 max 65528< / span > < span class = cF0 >
< a name = "l33" > < / a > < / span > < span class = cF2 > // flag: bit 0: reserved must be 0. bit 1: don't fragment. bit 2: more fragments< / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = "l34" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l35" > < / a > < / span > < span class = cF1 > U8< / span > < span class = cF0 > time_to_live; < / span > < span class = cF2 > // specified in seconds, wikipedia says nowadays serves as a hop count< / span > < span class = cF0 >
< a name = "l36" > < / a > < / span > < span class = cF1 > U8< / span > < span class = cF0 > protocol;
2021-07-03 05:07:57 +01:00
< a name = "l37" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l38" > < / a > < / span > < span class = cF9 > U16< / span > < span class = cF0 > header_checksum;
2021-07-03 05:07:57 +01:00
< a name = "l39" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l40" > < / a > < / span > < span class = cF9 > U32< / span > < span class = cF0 > source_ip_address;
< a name = "l41" > < / a > < / span > < span class = cF9 > U32< / span > < span class = cF0 > destination_ip_address;
2021-07-03 05:07:57 +01:00
< a name = "l42" > < / a > };
< a name = "l43" > < / a >
< a name = "l44" > < / a > < / span > < span class = cF1 > class< / span > < span class = cF0 > CIPV4Globals
< a name = "l45" > < / a > { < / span > < span class = cF2 > // _be indicates Big Endian< / span > < span class = cF0 >
2021-07-04 23:11:34 +01:00
< a name = "l46" > < / a > < / span > < span class = cF9 > U32< / span > < span class = cF0 > local_ip;
< a name = "l47" > < / a > < / span > < span class = cF9 > U32< / span > < span class = cF0 > local_ip_be;
2021-07-03 05:07:57 +01:00
< a name = "l48" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l49" > < / a > < / span > < span class = cF9 > U32< / span > < span class = cF0 > ipv4_router_address;
< a name = "l50" > < / a > < / span > < span class = cF9 > U32< / span > < span class = cF0 > ipv4_subnet_mask;
2021-07-03 05:07:57 +01:00
< a name = "l51" > < / a >
< a name = "l52" > < / a > } ipv4_globals;
< a name = "l53" > < / a >
< a name = "l54" > < / a > < / span > < span class = cF1 > U0< / span > < span class = cF0 > IPV4GlobalsInit()
< a name = "l55" > < / a > {
2021-07-04 23:11:34 +01:00
< a name = "l56" > < / a > ipv4_globals.local_ip = < / span > < span class = cFE > 0< / span > < span class = cF0 > ;
< a name = "l57" > < / a > ipv4_globals.local_ip_be = < / span > < span class = cFE > 0< / span > < span class = cF0 > ;
< a name = "l58" > < / a > ipv4_globals.ipv4_router_address = < / span > < span class = cFE > 0< / span > < span class = cF0 > ;
< a name = "l59" > < / a > ipv4_globals.ipv4_subnet_mask = < / span > < span class = cFE > 0< / span > < span class = cF0 > ;
2021-07-03 05:07:57 +01:00
< a name = "l60" > < / a > };
< a name = "l61" > < / a >
< a name = "l62" > < / a > < / span > < span class = cF2 > // For now, trusting Shrine's implement< / span > < span class = cF0 >
< a name = "l63" > < / a > < / span > < span class = cF2 > // of checksum. Shrine links back to< / span > < span class = cF0 >
< a name = "l64" > < / a > < / span > < span class = cF2 > // http://stackoverflow.com/q/26774761/2524350< / span > < span class = cF0 >
< a name = "l65" > < / a >
< a name = "l66" > < / a > < / span > < span class = cF9 > U16< / span > < span class = cF0 > IPV4Checksum(< / span > < span class = cF1 > U8< / span > < span class = cF0 > *header, < / span > < span class = cF9 > I64< / span > < span class = cF0 > length)
2021-07-04 23:11:34 +01:00
< a name = "l67" > < / a > { < / span > < span class = cF2 > //todo. make names clearer, and better comments.< / span > < span class = cF0 >
< a name = "l68" > < / a > < / span > < span class = cF9 > I64< / span > < span class = cF0 > nleft = length;
< a name = "l69" > < / a > < / span > < span class = cF9 > U16< / span > < span class = cF0 > *w = header;
< a name = "l70" > < / a > < / span > < span class = cF9 > I64< / span > < span class = cF0 > sum = < / span > < span class = cFE > 0< / span > < span class = cF0 > ;
2021-07-03 05:07:57 +01:00
< a name = "l71" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l72" > < / a > < / span > < span class = cF1 > while< / span > < span class = cF0 > (nleft > < / span > < span class = cFE > 1< / span > < span class = cF0 > )
< a name = "l73" > < / a > < / span > < span class = cF7 > {< / span > < span class = cF0 >
< a name = "l74" > < / a > sum += *w++;
< a name = "l75" > < / a > nleft -= < / span > < span class = cFE > 2< / span > < span class = cF0 > ;
< a name = "l76" > < / a > < / span > < span class = cF7 > }< / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = "l77" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l78" > < / a > < / span > < span class = cF2 > // " mop up an odd byte, if necessary" < / span > < span class = cF0 >
< a name = "l79" > < / a > < / span > < span class = cF1 > if< / span > < span class = cF0 > (nleft == < / span > < span class = cFE > 1< / span > < span class = cF0 > )
< a name = "l80" > < / a > < / span > < span class = cF7 > {< / span > < span class = cF0 >
< a name = "l81" > < / a > sum += *w & < / span > < span class = cFE > 0x00FF< / span > < span class = cF0 > ;
< a name = "l82" > < / a > < / span > < span class = cF7 > }< / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = "l83" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l84" > < / a > < / span > < span class = cF2 > // " add back carry outs from top 16 bits to low 16 bits" < / span > < span class = cF0 >
< a name = "l85" > < / a > sum = sum > > < / span > < span class = cFE > 16< / span > < span class = cF0 > + sum & < / span > < span class = cFE > 0xFFFF< / span > < span class = cF0 > ; < / span > < span class = cF2 > // " add hi 16 to low 16" < / span > < span class = cF0 >
< a name = "l86" > < / a > sum += sum > > < / span > < span class = cFE > 16< / span > < span class = cF0 > ; < / span > < span class = cF2 > // add carry< / span > < span class = cF0 >
< a name = "l87" > < / a > < / span > < span class = cF1 > return< / span > < span class = cF0 > ~sum & < / span > < span class = cFE > 0xFFFF< / span > < span class = cF0 > ;
2021-07-03 05:07:57 +01:00
< a name = "l88" > < / a >
< a name = "l89" > < / a > }
< a name = "l90" > < / a >
< a name = "l91" > < / a > < / span > < span class = cF9 > I64< / span > < span class = cF0 > IPV4AddressMACGet(< / span > < span class = cF9 > U32< / span > < span class = cF0 > ip_address, < / span > < span class = cF1 > U8< / span > < span class = cF0 > **mac_out)
< a name = "l92" > < / a > {
2021-07-04 23:11:34 +01:00
< a name = "l93" > < / a > CARPHash *entry;
< a name = "l94" > < / a > < / span > < span class = cF9 > I64< / span > < span class = cF0 > retries;
< a name = "l95" > < / a > < / span > < span class = cF9 > I64< / span > < span class = cF0 > attempt;
2021-07-03 05:07:57 +01:00
< a name = "l96" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l97" > < / a > < / span > < span class = cF1 > if< / span > < span class = cF0 > (ip_address == < / span > < span class = cFE > 0< / span > < span class = cF0 > )
< a name = "l98" > < / a > < / span > < span class = cF7 > {< / span > < span class = cF0 >
< a name = "l99" > < / a > NetErr(< / span > < span class = cF6 > " GET MAC FOR IP: Failed. Address = 0" < / span > < span class = cF0 > );
< a name = "l100" > < / a > < / span > < span class = cF1 > return< / span > < span class = cF0 > IPV4_ERR_ADDR_INVALID;
< a name = "l101" > < / a > < / span > < span class = cF7 > }< / span > < span class = cF0 >
< a name = "l102" > < / a > < / span > < span class = cF1 > if< / span > < span class = cF0 > (ip_address == < / span > < span class = cFE > 0xFFFFFFFF< / span > < span class = cF0 > )
< a name = "l103" > < / a > < / span > < span class = cF7 > {< / span > < span class = cF0 >
< a name = "l104" > < / a > NetLog(< / span > < span class = cF6 > " GET MAC FOR IP: Returning ethernet broadcast" < / span > < span class = cF0 > );
< a name = "l105" > < / a > *mac_out = ethernet_globals.ethernet_broadcast;
2021-07-03 05:07:57 +01:00
< a name = "l106" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l107" > < / a > < / span > < span class = cF1 > return< / span > < span class = cF0 > < / span > < span class = cFE > 0< / span > < span class = cF0 > ;
< a name = "l108" > < / a > < / span > < span class = cF7 > }< / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = "l109" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l110" > < / a > < / span > < span class = cF2 > // " outside this subnet; needs routing" < / span > < span class = cF0 >
< a name = "l111" > < / a > < / span > < span class = cF1 > if< / span > < span class = cF0 > (ip_address & ipv4_globals.ipv4_subnet_mask != ipv4_globals.local_ip & ipv4_globals.ipv4_subnet_mask)
< a name = "l112" > < / a > < / span > < span class = cF7 > {< / span > < span class = cF0 >
< a name = "l113" > < / a > NetWarn(< / span > < span class = cF6 > " GET MAC FOR IP: TODO: Doing IPV4AddressMACGet recursion, could infinite loop and overflow stack." < / span > < span class = cF0 > );
< a name = "l114" > < / a > < / span > < span class = cF1 > return< / span > < span class = cF0 > IPV4AddressMACGet(ipv4_globals.ipv4_router_address, mac_out);
< a name = "l115" > < / a > < / span > < span class = cF7 > }< / span > < span class = cF0 >
< a name = "l116" > < / a > < / span > < span class = cF1 > else< / span > < span class = cF0 > < / span > < span class = cF2 > // " local network" < / span > < span class = cF0 >
< a name = "l117" > < / a > < / span > < span class = cF7 > {< / span > < span class = cF0 >
< a name = "l118" > < / a > NetLog(< / span > < span class = cF6 > " GET MAC FOR IP: Attempting ARP Find by IP for address: %0X." < / span > < span class = cF0 > , ip_address);
< a name = "l119" > < / a > entry = ARPCacheFind(ip_address);
2021-07-03 05:07:57 +01:00
< a name = "l120" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l121" > < / a > < / span > < span class = cF1 > if< / span > < span class = cF0 > (entry)
< a name = "l122" > < / a > {
< a name = "l123" > < / a > *mac_out = entry-> mac_address;
< a name = "l124" > < / a > < / span > < span class = cF1 > return< / span > < span class = cF0 > < / span > < span class = cFE > 0< / span > < span class = cF0 > ;
< a name = "l125" > < / a > }
< a name = "l126" > < / a > < / span > < span class = cF2 > //else, not in cache, need to request it< / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = "l127" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l128" > < / a > < / span > < span class = cF2 > // " Up to 4 retries, 500 ms each" < / span > < span class = cF0 >
< a name = "l129" > < / a > retries = < / span > < span class = cFE > 4< / span > < span class = cF0 > ;
< a name = "l130" > < / a > < / span > < span class = cF1 > while< / span > < span class = cF0 > (retries)
< a name = "l131" > < / a > {
< a name = "l132" > < / a > ARPSend(ARP_REQUEST,
< a name = "l133" > < / a > ethernet_globals.ethernet_broadcast,
< a name = "l134" > < / a > EthernetMACGet,
< a name = "l135" > < / a > ipv4_globals.local_ip_be,
< a name = "l136" > < / a > ethernet_globals.ethernet_null,
< a name = "l137" > < / a > < / span > < span class = cF5 > EndianU32< / span > < span class = cF7 > (< / span > < span class = cF0 > ip_address< / span > < span class = cF7 > )< / span > < span class = cF0 > );
2021-07-03 05:07:57 +01:00
< a name = "l138" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l139" > < / a > attempt = < / span > < span class = cFE > 0< / span > < span class = cF0 > ;
< a name = "l140" > < / a > < / span > < span class = cF1 > for< / span > < span class = cF0 > (attempt = < / span > < span class = cFE > 0< / span > < span class = cF0 > ; attempt < < / span > < span class = cFE > 50< / span > < span class = cF0 > ; attempt++)
< a name = "l141" > < / a > < / span > < span class = cF7 > {< / span > < span class = cF0 >
< a name = "l142" > < / a > < / span > < span class = cF5 > Sleep< / span > < span class = cF0 > (< / span > < span class = cFE > 10< / span > < span class = cF0 > );
< a name = "l143" > < / a > entry = ARPCacheFind(ip_address);
< a name = "l144" > < / a > < / span > < span class = cF1 > if< / span > < span class = cF0 > (entry)
< a name = "l145" > < / a > < / span > < span class = cF1 > break< / span > < span class = cF0 > ;
< a name = "l146" > < / a > < / span > < span class = cF7 > }< / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = "l147" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l148" > < / a > < / span > < span class = cF1 > if< / span > < span class = cF0 > (entry)
< a name = "l149" > < / a > < / span > < span class = cF7 > {< / span > < span class = cF0 >
< a name = "l150" > < / a > *mac_out = entry-> mac_address;
< a name = "l151" > < / a > < / span > < span class = cF1 > return< / span > < span class = cF0 > < / span > < span class = cFE > 0< / span > < span class = cF0 > ;
< a name = "l152" > < / a > < / span > < span class = cF7 > }< / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = "l153" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l154" > < / a > retries--;
< a name = "l155" > < / a > }
2021-07-03 05:07:57 +01:00
< a name = "l156" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l157" > < / a > < / span > < span class = cF2 > //Shrine does some in_addr mess to log error< / span > < span class = cF0 >
< a name = "l158" > < / a > NetErr(< / span > < span class = cF6 > " GET MAC FOR IP: Failed to resolve address %d" < / span > < span class = cF0 > , ip_address);
< a name = "l159" > < / a > < / span > < span class = cF1 > return< / span > < span class = cF0 > IPV4_ERR_HOST_UNREACHABLE;
< a name = "l160" > < / a > < / span > < span class = cF7 > }< / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = "l161" > < / a > }
< a name = "l162" > < / a >
< a name = "l163" > < / a > < / span > < span class = cF9 > I64< / span > < span class = cF0 > IPV4PacketAllocate(< / span > < span class = cF1 > U8< / span > < span class = cF0 > **frame_out,
2021-07-04 23:11:34 +01:00
< a name = "l164" > < / a > < / span > < span class = cF1 > U8< / span > < span class = cF0 > protocol,
< a name = "l165" > < / a > < / span > < span class = cF9 > U32< / span > < span class = cF0 > source_ip_address,
< a name = "l166" > < / a > < / span > < span class = cF9 > U32< / span > < span class = cF0 > destination_ip_address,
< a name = "l167" > < / a > < / span > < span class = cF9 > I64< / span > < span class = cF0 > length)
2021-07-03 05:07:57 +01:00
< a name = "l168" > < / a > {
2021-07-04 23:11:34 +01:00
< a name = "l169" > < / a > < / span > < span class = cF1 > U8< / span > < span class = cF0 > *ipv4_frame;
< a name = "l170" > < / a > < / span > < span class = cF1 > U8< / span > < span class = cF0 > *destination_mac_address;
< a name = "l171" > < / a > < / span > < span class = cF9 > I64< / span > < span class = cF0 > error;
< a name = "l172" > < / a > < / span > < span class = cF9 > I64< / span > < span class = cF0 > de_index;
< a name = "l173" > < / a > < / span > < span class = cF9 > I64< / span > < span class = cF0 > internet_header_length;
< a name = "l174" > < / a > CIPV4Header *header;
2021-07-03 05:07:57 +01:00
< a name = "l175" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l176" > < / a > error = IPV4AddressMACGet(destination_ip_address, & destination_mac_address);
2021-07-03 05:07:57 +01:00
< a name = "l177" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l178" > < / a > < / span > < span class = cF1 > if< / span > < span class = cF0 > (error < < / span > < span class = cFE > 0< / span > < span class = cF0 > )
< a name = "l179" > < / a > < / span > < span class = cF7 > {< / span > < span class = cF0 >
< a name = "l180" > < / a > NetLog(< / span > < span class = cF6 > " IPV4 PACKET ALLOCATE: Failed to get MAC for destination." < / span > < span class = cF0 > );
< a name = "l181" > < / a > < / span > < span class = cF1 > return< / span > < span class = cF0 > error;
< a name = "l182" > < / a > < / span > < span class = cF7 > }< / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = "l183" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l184" > < / a > de_index = EthernetFrameAllocate(& ipv4_frame,
< a name = "l185" > < / a > EthernetMACGet,
< a name = "l186" > < / a > destination_mac_address,
< a name = "l187" > < / a > ETHERTYPE_IPV4,
< a name = "l188" > < / a > < / span > < span class = cF1 > sizeof< / span > < span class = cF7 > (< / span > < span class = cF0 > CIPV4Header< / span > < span class = cF7 > )< / span > < span class = cF0 > + length);
< a name = "l189" > < / a > < / span > < span class = cF1 > if< / span > < span class = cF0 > (de_index < < / span > < span class = cFE > 0< / span > < span class = cF0 > )
< a name = "l190" > < / a > < / span > < span class = cF7 > {< / span > < span class = cF0 >
< a name = "l191" > < / a > NetLog(< / span > < span class = cF6 > " IPV4 PACKET ALLOCATE: Ethernet Frame Allocate failed." < / span > < span class = cF0 > );
< a name = "l192" > < / a > < / span > < span class = cF1 > return< / span > < span class = cF0 > de_index;
< a name = "l193" > < / a > < / span > < span class = cF7 > }< / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = "l194" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l195" > < / a > internet_header_length = < / span > < span class = cFE > 5< / span > < span class = cF0 > ;< / span > < span class = cF2 > // ... why. need a #define< / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = "l196" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l197" > < / a > header = ipv4_frame;
2021-07-03 05:07:57 +01:00
< a name = "l198" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l199" > < / a > header-> version_ihl = internet_header_length | < / span > < span class = cFE > 4< / span > < span class = cF0 > < < < / span > < span class = cFE > 4< / span > < span class = cF0 > ;< / span > < span class = cF2 > // ? TODO: needs #define< / span > < span class = cF0 >
< a name = "l200" > < / a > header-> dscp_ecn = < / span > < span class = cFE > 0< / span > < span class = cF0 > ; < / span > < span class = cF2 > // a clear define of what this actually means would be good< / span > < span class = cF0 >
< a name = "l201" > < / a > header-> total_length = < / span > < span class = cF5 > EndianU16< / span > < span class = cF0 > (internet_header_length * < / span > < span class = cFE > 4< / span > < span class = cF0 > + length); < / span > < span class = cF2 > //...why?< / span > < span class = cF0 >
< a name = "l202" > < / a > header-> identification = < / span > < span class = cFE > 0< / span > < span class = cF0 > ; < / span > < span class = cF2 > // define would be clearer< / span > < span class = cF0 >
< a name = "l203" > < / a > header-> flags_fragment_offset = < / span > < span class = cFE > 0< / span > < span class = cF0 > ; < / span > < span class = cF2 > // define would be clearer< / span > < span class = cF0 >
< a name = "l204" > < / a > header-> time_to_live = IPV4_TTL;
< a name = "l205" > < / a > header-> protocol = protocol;
< a name = "l206" > < / a > header-> header_checksum = < / span > < span class = cFE > 0< / span > < span class = cF0 > ; < / span > < span class = cF2 > // why is 0 ok?< / span > < span class = cF0 >
< a name = "l207" > < / a > header-> source_ip_address = < / span > < span class = cF5 > EndianU32< / span > < span class = cF0 > (source_ip_address);
< a name = "l208" > < / a > header-> destination_ip_address = < / span > < span class = cF5 > EndianU32< / span > < span class = cF0 > (destination_ip_address);
< a name = "l209" > < / a > header-> header_checksum = IPV4Checksum(header, internet_header_length * < / span > < span class = cFE > 4< / span > < span class = cF0 > );< / span > < span class = cF2 > //why the 4's...< / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = "l210" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l211" > < / a > *frame_out = ipv4_frame + < / span > < span class = cF1 > sizeof< / span > < span class = cF0 > (CIPV4Header);
< a name = "l212" > < / a > < / span > < span class = cF1 > return< / span > < span class = cF0 > de_index;
2021-07-03 05:07:57 +01:00
< a name = "l213" > < / a > }
< a name = "l214" > < / a >
< a name = "l215" > < / a > < / span > < span class = cF1 > U0< / span > < span class = cF0 > IPV4PacketFinish(< / span > < span class = cF9 > I64< / span > < span class = cF0 > de_index) < / span > < span class = cF2 > //alias for EthernetFrameFinish< / span > < span class = cF0 >
< a name = "l216" > < / a > {
2021-07-04 23:11:34 +01:00
< a name = "l217" > < / a > EthernetFrameFinish(de_index);
2021-07-03 05:07:57 +01:00
< a name = "l218" > < / a > }
< a name = "l219" > < / a >
< a name = "l220" > < / a > < / span > < span class = cF9 > U32< / span > < span class = cF0 > IPV4AddressGet()
< a name = "l221" > < / a > {
2021-07-04 23:11:34 +01:00
< a name = "l222" > < / a > < / span > < span class = cF1 > return< / span > < span class = cF0 > ipv4_globals.local_ip;
2021-07-03 05:07:57 +01:00
< a name = "l223" > < / a > }
< a name = "l224" > < / a >
< a name = "l225" > < / a > < / span > < span class = cF1 > U0< / span > < span class = cF0 > IPV4AddressSet(< / span > < span class = cF9 > U32< / span > < span class = cF0 > ip_address)
< a name = "l226" > < / a > {
2021-07-04 23:11:34 +01:00
< a name = "l227" > < / a > ipv4_globals.local_ip = ip_address;
< a name = "l228" > < / a > ipv4_globals.local_ip_be = < / span > < span class = cF5 > EndianU32< / span > < span class = cF0 > (ip_address);
2021-07-03 05:07:57 +01:00
< a name = "l229" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l230" > < / a > ARPLocalIPV4Set(ip_address);
< a name = "l231" > < / a >
2021-07-03 05:07:57 +01:00
< a name = "l232" > < / a > }
< a name = "l233" > < / a >
< a name = "l234" > < / a > < / span > < span class = cF1 > U0< / span > < span class = cF0 > IPV4SubnetSet(< / span > < span class = cF9 > U32< / span > < span class = cF0 > router_address, < / span > < span class = cF9 > U32< / span > < span class = cF0 > subnet_mask)
< a name = "l235" > < / a > {
2021-07-04 23:11:34 +01:00
< a name = "l236" > < / a > ipv4_globals.ipv4_router_address = router_address;
< a name = "l237" > < / a > ipv4_globals.ipv4_subnet_mask = subnet_mask;
2021-07-03 05:07:57 +01:00
< a name = "l238" > < / a > }
< a name = "l239" > < / a >
< a name = "l240" > < / a > < / span > < span class = cF2 > //I64< / span > < span class = cF0 >
< a name = "l241" > < / a > < / span > < span class = cF1 > U0< / span > < span class = cF0 > IPV4PacketParse(CIPV4Packet *packet_out, CEthernetFrame *ethernet_frame)
< a name = "l242" > < / a > {
2021-07-04 23:11:34 +01:00
< a name = "l243" > < / a > < / span > < span class = cF2 > //...if ethertype not ipv4 error?< / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = "l244" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l245" > < / a > < / span > < span class = cF2 > // TODO: Check ethernet_frame length ! ... we need to know what's appropriate< / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = "l246" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l247" > < / a > CIPV4Header *header = ethernet_frame-> data;
< a name = "l248" > < / a > < / span > < span class = cF9 > I64< / span > < span class = cF0 > header_length = (header-> version_ihl & < / span > < span class = cFE > 0x0F< / span > < span class = cF0 > ) * < / span > < span class = cFE > 4< / span > < span class = cF0 > ;< / span > < span class = cF2 > //this Has to go. at least abstract or something..< / span > < span class = cF0 >
< a name = "l249" > < / a > < / span > < span class = cF9 > U16< / span > < span class = cF0 > total_length = < / span > < span class = cF5 > EndianU16< / span > < span class = cF0 > (header-> total_length);
2021-07-03 05:07:57 +01:00
< a name = "l250" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l251" > < / a > packet_out-> ethernet_frame = ethernet_frame;
< a name = "l252" > < / a > packet_out-> source_ip_address = < / span > < span class = cF5 > EndianU32< / span > < span class = cF0 > (header-> source_ip_address);
< a name = "l253" > < / a > packet_out-> destination_ip_address = < / span > < span class = cF5 > EndianU32< / span > < span class = cF0 > (header-> destination_ip_address);
< a name = "l254" > < / a > packet_out-> protocol = header-> protocol;
< a name = "l255" > < / a > packet_out-> data = ethernet_frame-> data + header_length;
< a name = "l256" > < / a > packet_out-> length = total_length - header_length;
2021-07-03 05:07:57 +01:00
< a name = "l257" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l258" > < / a > < / span > < span class = cF2 > //< / span > < span class = cF0 > < / span > < span class = cF2 > return 0;< / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = "l259" > < / a > }
< a name = "l260" > < / a >
< a name = "l261" > < / a > < / span > < span class = cF1 > U0< / span > < span class = cF0 > IPV4Rep()
< a name = "l262" > < / a > {
2021-07-04 23:11:34 +01:00
< a name = "l263" > < / a > < / span > < span class = cF6 > " $LTBLUE$IPV4 Report:$FG$\n\n" < / span > < span class = cF0 > ;
2021-07-03 05:07:57 +01:00
< a name = "l264" > < / a >
2021-07-04 23:11:34 +01:00
< a name = "l265" > < / a > < / span > < span class = cF6 > " Local IPV4: %d.%d.%d.%d\n" < / span > < span class = cF0 > ,
< a name = "l266" > < / a > ipv4_globals.local_ip.u8[< / span > < span class = cFE > 3< / span > < span class = cF0 > ],
< a name = "l267" > < / a > ipv4_globals.local_ip.u8[< / span > < span class = cFE > 2< / span > < span class = cF0 > ],
< a name = "l268" > < / a > ipv4_globals.local_ip.u8[< / span > < span class = cFE > 1< / span > < span class = cF0 > ],
< a name = "l269" > < / a > ipv4_globals.local_ip.u8[< / span > < span class = cFE > 0< / span > < span class = cF0 > ];
< a name = "l270" > < / a > < / span > < span class = cF6 > " Router IPV4: %d.%d.%d.%d\n" < / span > < span class = cF0 > ,
< a name = "l271" > < / a > ipv4_globals.ipv4_router_address.u8[< / span > < span class = cFE > 3< / span > < span class = cF0 > ],
< a name = "l272" > < / a > ipv4_globals.ipv4_router_address.u8[< / span > < span class = cFE > 2< / span > < span class = cF0 > ],
< a name = "l273" > < / a > ipv4_globals.ipv4_router_address.u8[< / span > < span class = cFE > 1< / span > < span class = cF0 > ],
< a name = "l274" > < / a > ipv4_globals.ipv4_router_address.u8[< / span > < span class = cFE > 0< / span > < span class = cF0 > ];
< a name = "l275" > < / a > < / span > < span class = cF6 > " Subnet IPV4: %d.%d.%d.%d\n" < / span > < span class = cF0 > ,
< a name = "l276" > < / a > ipv4_globals.ipv4_subnet_mask.u8[< / span > < span class = cFE > 3< / span > < span class = cF0 > ],
< a name = "l277" > < / a > ipv4_globals.ipv4_subnet_mask.u8[< / span > < span class = cFE > 2< / span > < span class = cF0 > ],
< a name = "l278" > < / a > ipv4_globals.ipv4_subnet_mask.u8[< / span > < span class = cFE > 1< / span > < span class = cF0 > ],
< a name = "l279" > < / a > ipv4_globals.ipv4_subnet_mask.u8[< / span > < span class = cFE > 0< / span > < span class = cF0 > ];
< a name = "l280" > < / a > < / span > < span class = cF6 > " \n" < / span > < span class = cF0 > ;
2021-07-03 05:07:57 +01:00
< a name = "l281" > < / a > }
< a name = "l282" > < / a >
< a name = "l283" > < / a > < / span > < span class = cF2 > // IPV4 handler moved to NetHandlerTask file.< / span > < span class = cF0 >
< a name = "l284" > < / a > IPV4GlobalsInit;< / span > < / pre > < / body >
< / html >