/// <summary> /// used to get original datagram info on icmp troubles msg. the icmp msg should contain internet header and 64 bits of original datagram /// </summary> /// <param name="raw_databool"></param> /// <param name="b_most_important_info_only"></param> /// <returns></returns> private static string decode_internet_header_and_64_bits_of_original_datagram(byte[] raw_data, bool b_most_important_info_only) { if (raw_data == null) { return(""); } string ret = ""; byte ret_decode; // decode easy_socket.ip_header.ipv4_header ipv4h = new easy_socket.ip_header.ipv4_header(); ret_decode = ipv4h.decode(raw_data); if ((ret_decode != easy_socket.ip_header.ipv4_header.error_success) && (ret_decode != easy_socket.ip_header.ipv4_header.error_datagram_not_complete) && (ret_decode != easy_socket.ip_header.ipv4_header.error_datagram_length_not_matching)) { return(easy_socket.hexa_convert.byte_to_hexa(raw_data)); } string[] data = null; // case of no data in original datagram if (ipv4h.data == null) { data = packet_ToStringArray.ip_raw(ref ipv4h, b_most_important_info_only); } else if (ipv4h.data.Length < 1) { data = packet_ToStringArray.ip_raw(ref ipv4h, b_most_important_info_only); } // assume there's data in original ip datagram else// data !=null && length>1 { switch (ipv4h.protocol) { // if icmp protocol case easy_socket.ip_header.ipv4_header.protocol_icmp: switch (ipv4h.data[0])// switch type (see icmp protocol) { case easy_socket.icmp.icmp.EchoReply: easy_socket.icmp.icmp_echo_reply icmper = new easy_socket.icmp.icmp_echo_reply(); if (icmper.decode(ipv4h.data) == easy_socket.icmp.icmp.error_success) { data = packet_ToStringArray.icmp_echo_reply(ref ipv4h, ref icmper, b_most_important_info_only); } break; case easy_socket.icmp.icmp.DestinationUnreachable: easy_socket.icmp.icmp_destination_unreachable icmpdu = new easy_socket.icmp.icmp_destination_unreachable(); if (icmpdu.decode(ipv4h.data) == easy_socket.icmp.icmp.error_success) { data = packet_ToStringArray.icmp_destination_unreachable(ref ipv4h, ref icmpdu, b_most_important_info_only); } break; case easy_socket.icmp.icmp.SourceQuench: easy_socket.icmp.icmp_source_quench icmpsq = new easy_socket.icmp.icmp_source_quench(); if (icmpsq.decode(ipv4h.data) == easy_socket.icmp.icmp.error_success) { data = packet_ToStringArray.icmp_source_quench(ref ipv4h, ref icmpsq, b_most_important_info_only); } break; case easy_socket.icmp.icmp.Redirect: easy_socket.icmp.icmp_redirect icmpr = new easy_socket.icmp.icmp_redirect(); if (icmpr.decode(ipv4h.data) == easy_socket.icmp.icmp.error_success) { data = packet_ToStringArray.icmp_redirect(ref ipv4h, ref icmpr, b_most_important_info_only); } break; case easy_socket.icmp.icmp.Echo: easy_socket.icmp.icmp_echo icmpe = new easy_socket.icmp.icmp_echo(); if (icmpe.decode(ipv4h.data) == easy_socket.icmp.icmp.error_success) { data = packet_ToStringArray.icmp_echo(ref ipv4h, ref icmpe, b_most_important_info_only); } break; case easy_socket.icmp.icmp.TimeExceeded: easy_socket.icmp.icmp_time_exceeded_message icmptem = new easy_socket.icmp.icmp_time_exceeded_message(); if (icmptem.decode(ipv4h.data) == easy_socket.icmp.icmp.error_success) { data = packet_ToStringArray.icmp_time_exceeded_message(ref ipv4h, ref icmptem, b_most_important_info_only); } break; case easy_socket.icmp.icmp.ParameterProblem: easy_socket.icmp.icmp_parameter_problem icmppp = new easy_socket.icmp.icmp_parameter_problem(); if (icmppp.decode(ipv4h.data) == easy_socket.icmp.icmp.error_success) { data = packet_ToStringArray.icmp_parameter_problem(ref ipv4h, ref icmppp, b_most_important_info_only); } break; case easy_socket.icmp.icmp.Timestamp: easy_socket.icmp.icmp_timestamp icmpt = new easy_socket.icmp.icmp_timestamp(); if (icmpt.decode(ipv4h.data) == easy_socket.icmp.icmp.error_success) { data = packet_ToStringArray.icmp_timestamp(ref ipv4h, ref icmpt, b_most_important_info_only); } break; case easy_socket.icmp.icmp.TimestampReply: easy_socket.icmp.icmp_timestamp_reply icmptr = new easy_socket.icmp.icmp_timestamp_reply(); if (icmptr.decode(ipv4h.data) == easy_socket.icmp.icmp.error_success) { data = packet_ToStringArray.icmp_timestamp_reply(ref ipv4h, ref icmptr, b_most_important_info_only); } break; case easy_socket.icmp.icmp.InformationRequest: easy_socket.icmp.icmp_information_request icmpirequest = new easy_socket.icmp.icmp_information_request(); if (icmpirequest.decode(ipv4h.data) == easy_socket.icmp.icmp.error_success) { data = packet_ToStringArray.icmp_information_request(ref ipv4h, ref icmpirequest, b_most_important_info_only); } break; case easy_socket.icmp.icmp.InformationReply: easy_socket.icmp.icmp_information_reply icmpireply = new easy_socket.icmp.icmp_information_reply(); if (icmpireply.decode(ipv4h.data) == easy_socket.icmp.icmp.error_success) { data = packet_ToStringArray.icmp_information_reply(ref ipv4h, ref icmpireply, b_most_important_info_only); } break; //default: }// end of icmp switch break; // if udp protocol case easy_socket.ip_header.ipv4_header.protocol_udp: easy_socket.udp_header.udp_header udph = new easy_socket.udp_header.udp_header(); udph.decode(ipv4h.source_address, ipv4h.destination_address, ipv4h.data, false); // don't check checksum data = packet_ToStringArray.udp(ref ipv4h, ref udph, false); // show max info of original packet break; // if tcp protocol case easy_socket.ip_header.ipv4_header.protocol_tcp: easy_socket.tcp_header.tcp_header tcph = new easy_socket.tcp_header.tcp_header(); tcph.decode(ipv4h.source_address, ipv4h.destination_address, ipv4h.data, false); // don't check checksum data = packet_ToStringArray.tcp(ref ipv4h, ref tcph, b_most_important_info_only); // show max info of original packet break; // other protocol default: data = packet_ToStringArray.ip_raw(ref ipv4h, b_most_important_info_only); break; } // end of protocol switch } // end of ip data test // Join data (string[]) to a string if (data != null) { ret = System.String.Join(" ", data); } return(ret); }
public static string[] icmp_timestamp(ref easy_socket.ip_header.ipv4_header ipv4h, ref easy_socket.icmp.icmp_timestamp icmp, bool b_most_important_info_only) { string str_global_info; str_global_info = "Timestamp"; if (!b_most_important_info_only) { str_global_info += ", Type:" + icmp.Type; str_global_info += ", Code:" + icmp.code; str_global_info += ", Checksum:" + icmp.Checksum; } str_global_info += ", Identifier:" + icmp.Identifier; str_global_info += ", SeqNum:" + icmp.SequenceNumber; str_global_info += ", Originate:" + icmp.OriginateTimestamp; str_global_info += ", Receive:" + icmp.ReceiveTimestamp; str_global_info += ", Transmit:" + icmp.TransmitTimestamp; string[] ret = new string[4 + 4]; System.Array.Copy(packet_ToStringArray.ip_raw(ref ipv4h, b_most_important_info_only), 0, ret, 0, 4); ret[4] = ""; ret[5] = ""; ret[6] = str_global_info; ret[7] = ""; return(ret); }