{"id":408115,"date":"2024-06-29T19:58:01","date_gmt":"2024-06-29T19:58:01","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=408115"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=408115","title":{"rendered":"<span>C++, ping \u0438 traceroute<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u041f\u0440\u0435\u0434\u044b\u0441\u0442\u043e\u0440\u0438\u044f<\/h2>\n<p>\u0418\u0437\u0443\u0447\u0430\u044f \u0441\u0435\u0442\u0435\u0432\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0438\u043c\u0435\u044f \u0432 \u043f\u043e\u0440\u0442\u0444\u043e\u043b\u0438\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u043a\u043e\u0432 \u043d\u0430 C++, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u0441\u0435\u0442\u0435\u0432\u044b\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c, \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435.<\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 &#8212; \u0443\u0442\u0438\u043b\u0438\u0442\u0430 ping. <\/p>\n<blockquote>\n<p>Ping \u2014 \u0443\u0442\u0438\u043b\u0438\u0442\u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0432 \u0441\u0435\u0442\u044f\u0445 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 TCP\/IP, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u0438\u0445\u043e\u0434\u043d\u043e\u0435 \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0430\u043c\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/p>\n<\/blockquote>\n<p>\u042f \u043f\u043e\u0434\u0443\u043c\u0430\u043b, \u0447\u0442\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0432 \u0434\u043e\u043a\u0438: <a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc792\" rel=\"noopener noreferrer nofollow\">https:\/\/www.rfc-editor.org\/rfc\/rfc792<\/a>, \u0441\u043c\u043e\u0433\u0443 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e. <\/p>\n<h2>Ping<\/h2>\n<p>\u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u0440\u043e\u0441\u0442 \u0438 \u043f\u043e\u043d\u044f\u0442\u0435\u043d: \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0448\u044c \u043f\u0430\u043a\u0435\u0442 \u0438 \u0437\u0430\u0441\u0435\u043a\u0430\u0435\u0448\u044c \u0432\u0440\u0435\u043c\u044f \u0434\u043e \u043e\u0442\u0432\u0435\u0442\u0430. <\/p>\n<p>\u0421\u043f\u0443\u0441\u0442\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043d\u0435\u0439 \u0431\u044b\u043b \u0433\u043e\u0442\u043e\u0432 \u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u044b\u0439 <a href=\"https:\/\/github.com\/maxtamoian\/ping\" rel=\"noopener noreferrer nofollow\">\u0432\u0430\u0440\u0438\u0430\u043d\u0442 ping-\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0435\u0441\u0442\u044c \u043d\u0430 Github<\/a>.<\/p>\n<p>\u0414\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b traceroute \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u043c\u0435\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0440\u0430\u0431\u043e\u0442\u0435 ping-\u0430, \u0442\u0430\u043a \u0447\u0442\u043e \u0440\u0430\u0437\u0431\u043e\u0440 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430 \u043d\u0435 \u043f\u043e\u0432\u0440\u0435\u0434\u0438\u0442.<\/p>\n<pre><code class=\"cpp\">pid_t ppid = getppid();<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u0442\u043e\u043a\u0430 \u043d\u0430\u0448\u0435\u0433\u043e ping-a, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043e \u043f\u043e\u043b\u0435 \u0432 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0435 ICMP.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 ICMP \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430:<\/p>\n<pre><code class=\"cpp\">struct icmpHeader {     uint8_t type;     uint8_t code;     uint16_t checksum;      union {         struct {             uint16_t identifier;             uint16_t sequence;             uint64_t payload;         } echo;          struct ICMP_PACKET_POINTER_HEADER {             uint8_t pointer;         } pointer;          struct ICMP_PACKET_REDIRECT_HEADER {             uint32_t gatewayAddress;         } redirect;     } meta; };<\/code><\/pre>\n<p>\u041f\u043e\u043b\u044f type, code, checksum &#8212; \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435. \u0412 \u043f\u0438\u043d\u0433\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e echo, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0438\u0437 7 &#8212; 11 \u0441\u0442\u0440\u043e\u043a, \u043d\u043e \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b &#8212; \u043e\u0441\u043a\u043e\u043b\u043a\u0438 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 ICMP, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0443\u0431\u0440\u0430\u0442\u044c. \u0412 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0442\u0435 \u0436\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u0432 traceroute.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0438\u0434\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442-\u0447\u0435\u043a\u0441\u0443\u043c\u043c\u044b:<\/p>\n<pre><code class=\"cpp\">uint16_t checksum(const void *data, size_t len) {     auto p = reinterpret_cast&lt;const uint16_t *>(data);      uint32_t sum = 0;      if (len &amp; 1) {         sum = reinterpret_cast&lt;const uint8_t *>(p)[len - 1];     }      len \/= 2;      while (len--) {         sum += *p++;         if (sum &amp; 0xffff0000) {             sum = (sum >> 16) + (sum &amp; 0xffff);         }     }      return static_cast&lt;uint16_t>(~sum); }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043f\u0430\u043a\u0435\u0442\u0430, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0441\u0435\u0447\u044c \u0432\u0440\u0435\u043c\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0430\u043a\u0435\u0442 \u0448\u0435\u043b \u043e\u0442 \u043d\u0430\u0441 \u043a \u0446\u0435\u043b\u0438 \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e:<\/p>\n<pre><code class=\"cpp\"> long int send_flag = sendto(sock, &amp;icmpPacket, sizeof(icmpPacket), 0,                               (struct sockaddr *) &amp;in_addr,                              socklen_t(sizeof(in_addr)));          sent++;          uint64_t ms_before = duration_cast&lt;milliseconds>(system_clock::now().time_since_epoch()).count();           if (send_flag &lt; 0) {             perror(\"send error\");             return;         }          char buf[1024];          auto *icmpResponseHeader = (struct icmpHeader *) buf;          struct timeval tv;         tv.tv_sec = response_timeout;         tv.tv_usec = 0;          setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &amp;tv, sizeof(tv));         setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &amp;tv, sizeof(tv));           int data_length_byte = recv(sock, icmpResponseHeader, sizeof(buf), 0);          if(data_length_byte == -1) {             cout &lt;&lt; \"\\033[1;31m\" &lt;&lt; \"Host unreachable or response timeout.\" &lt;&lt; \"\\033[0m\" &lt;&lt; \"   \";             cout &lt;&lt; \"Sequence: \" &lt;&lt; \"\\033[1;35m\" &lt;&lt; i &lt;&lt; \"\\033[0m\" &lt;&lt; \"    \";             cout &lt;&lt; \"Process id: \" &lt;&lt; \"\\033[1;35m\" &lt;&lt; ppid &lt;&lt; \"\\033[0m\" &lt;&lt; endl;             continue;         }          uint64_t ms_after = duration_cast&lt;milliseconds>(system_clock::now().time_since_epoch()).count();<\/code><\/pre>\n<p>\u0421\u0442\u0440\u043e\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0430\u043a\u0435\u0442\u0430 \u0438 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u044f \u0435\u0433\u043e \u043f\u043e\u043b\u044f\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u043f\u0443\u0449\u0435\u043d\u044b, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0430\u0436\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e, \u0447\u0442\u043e ICMP \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u0435 \u0434\u043b\u044f \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u043a\u043e\u0434\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u043d\u0430\u0431\u043e\u0440\u043e\u043c \u0435\u0434\u0438\u043d\u0438\u0446 \u0438 \u043d\u0443\u043b\u0435\u0439.<\/p>\n<h2>Traceroute<\/h2>\n<p>\u0418\u0437 \u0412\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u0438:<\/p>\n<blockquote>\n<p>Traceroute \u2014 \u044d\u0442\u043e \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u0430\u044f \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u0430\u044f \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0441\u0435\u0442\u044f\u0445 TCP\/IP.<\/p>\n<\/blockquote>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u044f \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b \u043f\u0430\u043a\u0435\u0442\u044b \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043b\u0438\u043d\u0443\u043a\u0441\u043e\u0432\u043e\u0433\u043e traceroute Wireshark-\u043e\u043c. <\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 &#171;\u0441\u044b\u0440\u044b\u0445&#187; \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0440\u0443\u0442-\u043f\u0440\u0438\u0432\u0438\u043b\u0435\u043d\u0438\u0439, traceroute \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 UDP, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044f \u043f\u0430\u043a\u0435\u0442\u044b \u0441 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u0441\u044f TTL \u043d\u0430 \u0440\u0430\u043d\u0434\u043e\u043c\u043d\u044b\u0439 \u043f\u043e\u0440\u0442 \u0446\u0435\u043b\u0438 \u0438 \u0436\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u043e \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u0441\u0442\u0438 \u043f\u043e\u0440\u0442\u0430. <\/p>\n<p>\u0412\u0441\u0435 \u0436\u0435 \u044f \u043f\u043e\u0434\u0443\u043c\u0430\u043b, \u0447\u0442\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 ICMP \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0449\u0435, \u0445\u043e\u0442\u044c \u0438 \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043d\u0443\u0436\u0435\u043d \u0431\u0443\u0434\u0435\u0442 \u0440\u0443\u0442. <\/p>\n<p>Traceroute \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u0445\u043e-\u043f\u0430\u043a\u0435\u0442\u044b \u0441 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u043c\u0441\u044f TTL. TTL &#8212; Time To Live, \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u043f\u0430\u043a\u0435\u0442\u0430 \u0438 \u043f\u043e \u0434\u0435\u0444\u043e\u043b\u0442\u0443 \u043e\u043d \u0440\u0430\u0432\u0435\u043d 30. \u0412\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u043f\u0430\u043a\u0435\u0442\u0430 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0438\u043c \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u0437\u043b\u0430 \u0432 \u0441\u0435\u0442\u0438. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043d\u0430\u0439\u0442\u0438 \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u0434\u043e 1.1.1.1:<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u0430\u043a\u0435\u0442 \u0441 TTL 1, \u0442\u043e \u043e\u043d \u0443\u043f\u0440\u0435\u0442\u0441\u044f \u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u0443\u0437\u0435\u043b (\u043e\u0431\u044b\u0447\u043d\u043e \u0432 \u0432\u0430\u0448 \u0440\u043e\u0443\u0442\u0435\u0440 192.168.0.1 \u0438\u043b\u0438 \u0432 \u043f\u043e\u0434\u0441\u0435\u0442\u044c) \u0438 \u0442\u043e\u0442 \u0432\u0435\u0440\u043d\u0435\u0442 \u043e\u0442\u0432\u0435\u0442: TTL exceeded, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 &#171;\u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u0438\u0441\u0442\u0435\u043a\u043b\u043e&#187;. \u0418\u0437 \u0435\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0442\u0430\u0449\u0438\u0442\u044c ip_src \u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0443\u0437\u043d\u0430\u0442\u044c IP-\u0430\u0434\u0440\u0435\u0441 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0443\u0437\u043b\u0430. \u0412\u0437\u044f\u0432 TTL 2, \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c IP-\u0430\u0434\u0440\u0435\u0441 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0443\u0437\u043b\u0430 \u0438 \u0442.\u0434<\/p>\n<p>\u041d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 <a href=\"https:\/\/www.ip-lookup.org\/visual\/traceroute\" rel=\"noopener noreferrer nofollow\">https:\/\/www.ip-lookup.org\/visual\/traceroute<\/a><\/p>\n<p><a href=\"https:\/\/github.com\/maxtamoian\/traceroute\" rel=\"noopener noreferrer nofollow\">Traceroute \u0442\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u043d\u0430 Github<\/a><\/p>\n<p>\u041c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u0438\u043f \u043f\u0430\u043a\u0435\u0442\u0430 (8) \u0438 \u043a\u0430\u0436\u0434\u0443\u044e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e \u0446\u0438\u043a\u043b\u0430 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f TTL.<\/p>\n<pre><code class=\"cpp\">icmp_packet.type = 8; icmp_packet.code = 0; icmp_packet.checksum = 0; icmp_packet.meta.echo.identifier = ppid; icmp_packet.meta.echo.sequence = i; icmp_packet.meta.echo.payload = 0b101101010110100101; \/\/ random binary data icmp_packet.checksum = checksum(&amp;icmp_packet, sizeof(icmp_packet));<\/code><\/pre>\n<pre><code class=\"cpp\">int ttl = i + 1;  setsockopt(sock, IPPROTO_IP, IP_TTL, &amp;ttl, sizeof(ttl));<\/code><\/pre>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043a\u043e\u0434\u0435 \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u043e\u0442 \u043a\u043e\u0433\u043e \u043f\u0440\u0438\u0448\u0435\u043b \u043e\u0442\u0432\u0435\u0442 &#8212; \u043e\u0442 \u0446\u0435\u043b\u0438 \u0438\u043b\u0438 \u043d\u0435\u0442. \u0415\u0441\u043b\u0438 \u043e\u0442 \u0446\u0435\u043b\u0438, \u0442\u043e \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u0435\u043c \u0446\u0438\u043a\u043b \u0438 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b. <\/p>\n<pre><code class=\"cpp\">if (strcmp(inet_ntoa(src_addr.sin_addr), ip) == 0) {     cout &lt;&lt; endl &lt;&lt; \"\\033[1;35m\" &lt;&lt; ttl &lt;&lt; \"\\033[0m\" &lt;&lt; \" hops between you and \" &lt;&lt; ip &lt;&lt; endl;     break; }<\/code><\/pre>\n<p>\u042f \u0441\u0447\u0438\u0442\u0430\u044e, \u0447\u0442\u043e traceroute \u0438 ping &#8212; \u0443\u0442\u0438\u043b\u0438\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u043b\u0443\u0447\u0448\u0430\u0442 \u043f\u043e\u0440\u0442\u0444\u043e\u043b\u0438\u043e \u0438 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0433\u043b\u0443\u0431\u0436\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u0441\u0435\u0442\u0435\u0432\u044b\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c. \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u043b\u044f \u043e\u0431\u0449\u0435\u0433\u043e \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc791\" rel=\"noopener noreferrer nofollow\">https:\/\/www.rfc-editor.org\/rfc\/rfc791<\/a> (\u043f\u0440\u043e \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b IP).<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/726714\/\"> https:\/\/habr.com\/ru\/articles\/726714\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u041f\u0440\u0435\u0434\u044b\u0441\u0442\u043e\u0440\u0438\u044f<\/h2>\n<p>\u0418\u0437\u0443\u0447\u0430\u044f \u0441\u0435\u0442\u0435\u0432\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0438\u043c\u0435\u044f \u0432 \u043f\u043e\u0440\u0442\u0444\u043e\u043b\u0438\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u043a\u043e\u0432 \u043d\u0430 C++, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u0441\u0435\u0442\u0435\u0432\u044b\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c, \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435.<\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 &#8212; \u0443\u0442\u0438\u043b\u0438\u0442\u0430 ping. <\/p>\n<blockquote>\n<p>Ping \u2014 \u0443\u0442\u0438\u043b\u0438\u0442\u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0432 \u0441\u0435\u0442\u044f\u0445 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 TCP\/IP, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u0438\u0445\u043e\u0434\u043d\u043e\u0435 \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0430\u043c\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/p>\n<\/blockquote>\n<p>\u042f \u043f\u043e\u0434\u0443\u043c\u0430\u043b, \u0447\u0442\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0432 \u0434\u043e\u043a\u0438: <a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc792\" rel=\"noopener noreferrer nofollow\">https:\/\/www.rfc-editor.org\/rfc\/rfc792<\/a>, \u0441\u043c\u043e\u0433\u0443 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e. <\/p>\n<h2>Ping<\/h2>\n<p>\u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u0440\u043e\u0441\u0442 \u0438 \u043f\u043e\u043d\u044f\u0442\u0435\u043d: \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0448\u044c \u043f\u0430\u043a\u0435\u0442 \u0438 \u0437\u0430\u0441\u0435\u043a\u0430\u0435\u0448\u044c \u0432\u0440\u0435\u043c\u044f \u0434\u043e \u043e\u0442\u0432\u0435\u0442\u0430. <\/p>\n<p>\u0421\u043f\u0443\u0441\u0442\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043d\u0435\u0439 \u0431\u044b\u043b \u0433\u043e\u0442\u043e\u0432 \u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u044b\u0439 <a href=\"https:\/\/github.com\/maxtamoian\/ping\" rel=\"noopener noreferrer nofollow\">\u0432\u0430\u0440\u0438\u0430\u043d\u0442 ping-\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0435\u0441\u0442\u044c \u043d\u0430 Github<\/a>.<\/p>\n<p>\u0414\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b traceroute \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u043c\u0435\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0440\u0430\u0431\u043e\u0442\u0435 ping-\u0430, \u0442\u0430\u043a \u0447\u0442\u043e \u0440\u0430\u0437\u0431\u043e\u0440 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430 \u043d\u0435 \u043f\u043e\u0432\u0440\u0435\u0434\u0438\u0442.<\/p>\n<pre><code class=\"cpp\">pid_t ppid = getppid();<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u0442\u043e\u043a\u0430 \u043d\u0430\u0448\u0435\u0433\u043e ping-a, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043e \u043f\u043e\u043b\u0435 \u0432 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0435 ICMP.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 ICMP \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430:<\/p>\n<pre><code class=\"cpp\">struct icmpHeader {     uint8_t type;     uint8_t code;     uint16_t checksum;      union {         struct {             uint16_t identifier;             uint16_t sequence;             uint64_t payload;         } echo;          struct ICMP_PACKET_POINTER_HEADER {             uint8_t pointer;         } pointer;          struct ICMP_PACKET_REDIRECT_HEADER {             uint32_t gatewayAddress;         } redirect;     } meta; };<\/code><\/pre>\n<p>\u041f\u043e\u043b\u044f type, code, checksum &#8212; \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435. \u0412 \u043f\u0438\u043d\u0433\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e echo, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0438\u0437 7 &#8212; 11 \u0441\u0442\u0440\u043e\u043a, \u043d\u043e \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b &#8212; \u043e\u0441\u043a\u043e\u043b\u043a\u0438 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 ICMP, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0443\u0431\u0440\u0430\u0442\u044c. \u0412 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0442\u0435 \u0436\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u0432 traceroute.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0438\u0434\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442-\u0447\u0435\u043a\u0441\u0443\u043c\u043c\u044b:<\/p>\n<pre><code class=\"cpp\">uint16_t checksum(const void *data, size_t len) {     auto p = reinterpret_cast&lt;const uint16_t *>(data);      uint32_t sum = 0;      if (len &amp; 1) {         sum = reinterpret_cast&lt;const uint8_t *>(p)[len - 1];     }      len \/= 2;      while (len--) {         sum += *p++;         if (sum &amp; 0xffff0000) {             sum = (sum >> 16) + (sum &amp; 0xffff);         }     }      return static_cast&lt;uint16_t>(~sum); }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043f\u0430\u043a\u0435\u0442\u0430, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0441\u0435\u0447\u044c \u0432\u0440\u0435\u043c\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0430\u043a\u0435\u0442 \u0448\u0435\u043b \u043e\u0442 \u043d\u0430\u0441 \u043a \u0446\u0435\u043b\u0438 \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e:<\/p>\n<pre><code class=\"cpp\"> long int send_flag = sendto(sock, &amp;icmpPacket, sizeof(icmpPacket), 0,                               (struct sockaddr *) &amp;in_addr,                              socklen_t(sizeof(in_addr)));          sent++;          uint64_t ms_before = duration_cast&lt;milliseconds>(system_clock::now().time_since_epoch()).count();           if (send_flag &lt; 0) {             perror(\"send error\");             return;         }          char buf[1024];          auto *icmpResponseHeader = (struct icmpHeader *) buf;          struct timeval tv;         tv.tv_sec = response_timeout;         tv.tv_usec = 0;          setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &amp;tv, sizeof(tv));         setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &amp;tv, sizeof(tv));           int data_length_byte = recv(sock, icmpResponseHeader, sizeof(buf), 0);          if(data_length_byte == -1) {             cout &lt;&lt; \"\\033[1;31m\" &lt;&lt; \"Host unreachable or response timeout.\" &lt;&lt; \"\\033[0m\" &lt;&lt; \"   \";             cout &lt;&lt; \"Sequence: \" &lt;&lt; \"\\033[1;35m\" &lt;&lt; i &lt;&lt; \"\\033[0m\" &lt;&lt; \"    \";             cout &lt;&lt; \"Process id: \" &lt;&lt; \"\\033[1;35m\" &lt;&lt; ppid &lt;&lt; \"\\033[0m\" &lt;&lt; endl;             continue;         }          uint64_t ms_after = duration_cast&lt;milliseconds>(system_clock::now().time_since_epoch()).count();<\/code><\/pre>\n<p>\u0421\u0442\u0440\u043e\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0430\u043a\u0435\u0442\u0430 \u0438 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u044f \u0435\u0433\u043e \u043f\u043e\u043b\u044f\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u043f\u0443\u0449\u0435\u043d\u044b, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0430\u0436\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e, \u0447\u0442\u043e ICMP \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u0435 \u0434\u043b\u044f \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u043a\u043e\u0434\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u043d\u0430\u0431\u043e\u0440\u043e\u043c \u0435\u0434\u0438\u043d\u0438\u0446 \u0438 \u043d\u0443\u043b\u0435\u0439.<\/p>\n<h2>Traceroute<\/h2>\n<p>\u0418\u0437 \u0412\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u0438:<\/p>\n<blockquote>\n<p>Traceroute \u2014 \u044d\u0442\u043e \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u0430\u044f \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u0430\u044f \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0441\u0435\u0442\u044f\u0445 TCP\/IP.<\/p>\n<\/blockquote>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u044f \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b \u043f\u0430\u043a\u0435\u0442\u044b \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043b\u0438\u043d\u0443\u043a\u0441\u043e\u0432\u043e\u0433\u043e traceroute Wireshark-\u043e\u043c. <\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 &#171;\u0441\u044b\u0440\u044b\u0445&#187; \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0440\u0443\u0442-\u043f\u0440\u0438\u0432\u0438\u043b\u0435\u043d\u0438\u0439, traceroute \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 UDP, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044f \u043f\u0430\u043a\u0435\u0442\u044b \u0441 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u0441\u044f TTL \u043d\u0430 \u0440\u0430\u043d\u0434\u043e\u043c\u043d\u044b\u0439 \u043f\u043e\u0440\u0442 \u0446\u0435\u043b\u0438 \u0438 \u0436\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u043e \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u0441\u0442\u0438 \u043f\u043e\u0440\u0442\u0430. <\/p>\n<p>\u0412\u0441\u0435 \u0436\u0435 \u044f \u043f\u043e\u0434\u0443\u043c\u0430\u043b, \u0447\u0442\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 ICMP \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0449\u0435, \u0445\u043e\u0442\u044c \u0438 \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043d\u0443\u0436\u0435\u043d \u0431\u0443\u0434\u0435\u0442 \u0440\u0443\u0442. <\/p>\n<p>Traceroute \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u0445\u043e-\u043f\u0430\u043a\u0435\u0442\u044b \u0441 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u043c\u0441\u044f TTL. TTL &#8212; Time To Live, \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u043f\u0430\u043a\u0435\u0442\u0430 \u0438 \u043f\u043e \u0434\u0435\u0444\u043e\u043b\u0442\u0443 \u043e\u043d \u0440\u0430\u0432\u0435\u043d 30. \u0412\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u043f\u0430\u043a\u0435\u0442\u0430 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0438\u043c \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u0437\u043b\u0430 \u0432 \u0441\u0435\u0442\u0438. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043d\u0430\u0439\u0442\u0438 \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u0434\u043e 1.1.1.1:<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u0430\u043a\u0435\u0442 \u0441 TTL 1, \u0442\u043e \u043e\u043d \u0443\u043f\u0440\u0435\u0442\u0441\u044f \u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u0443\u0437\u0435\u043b (\u043e\u0431\u044b\u0447\u043d\u043e \u0432 \u0432\u0430\u0448 \u0440\u043e\u0443\u0442\u0435\u0440 192.168.0.1 \u0438\u043b\u0438 \u0432 \u043f\u043e\u0434\u0441\u0435\u0442\u044c) \u0438 \u0442\u043e\u0442 \u0432\u0435\u0440\u043d\u0435\u0442 \u043e\u0442\u0432\u0435\u0442: TTL exceeded, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 &#171;\u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u0438\u0441\u0442\u0435\u043a\u043b\u043e&#187;. \u0418\u0437 \u0435\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0442\u0430\u0449\u0438\u0442\u044c ip_src \u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0443\u0437\u043d\u0430\u0442\u044c IP-\u0430\u0434\u0440\u0435\u0441 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0443\u0437\u043b\u0430. \u0412\u0437\u044f\u0432 TTL 2, \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c IP-\u0430\u0434\u0440\u0435\u0441 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0443\u0437\u043b\u0430 \u0438 \u0442.\u0434<\/p>\n<p>\u041d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 <a href=\"https:\/\/www.ip-lookup.org\/visual\/traceroute\" rel=\"noopener noreferrer nofollow\">https:\/\/www.ip-lookup.org\/visual\/traceroute<\/a><\/p>\n<p><a href=\"https:\/\/github.com\/maxtamoian\/traceroute\" rel=\"noopener noreferrer nofollow\">Traceroute \u0442\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u043d\u0430 Github<\/a><\/p>\n<p>\u041c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u0438\u043f \u043f\u0430\u043a\u0435\u0442\u0430 (8) \u0438 \u043a\u0430\u0436\u0434\u0443\u044e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e \u0446\u0438\u043a\u043b\u0430 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f TTL.<\/p>\n<pre><code class=\"cpp\">icmp_packet.type = 8; icmp_packet.code = 0; icmp_packet.checksum = 0; icmp_packet.meta.echo.identifier = ppid; icmp_packet.meta.echo.sequence = i; icmp_packet.meta.echo.payload = 0b101101010110100101; \/\/ random binary data icmp_packet.checksum = checksum(&amp;icmp_packet, sizeof(icmp_packet));<\/code><\/pre>\n<pre><code class=\"cpp\">int ttl = i + 1;  setsockopt(sock, IPPROTO_IP, IP_TTL, &amp;ttl, sizeof(ttl));<\/code><\/pre>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043a\u043e\u0434\u0435 \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u043e\u0442 \u043a\u043e\u0433\u043e \u043f\u0440\u0438\u0448\u0435\u043b \u043e\u0442\u0432\u0435\u0442 &#8212; \u043e\u0442 \u0446\u0435\u043b\u0438 \u0438\u043b\u0438 \u043d\u0435\u0442. \u0415\u0441\u043b\u0438 \u043e\u0442 \u0446\u0435\u043b\u0438, \u0442\u043e \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u0435\u043c \u0446\u0438\u043a\u043b \u0438 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b. <\/p>\n<pre><code class=\"cpp\">if (strcmp(inet_ntoa(src_addr.sin_addr), ip) == 0) {     cout &lt;&lt; endl &lt;&lt; \"\\033[1;35m\" &lt;&lt; ttl &lt;&lt; \"\\033[0m\" &lt;&lt; \" hops between you and \" &lt;&lt; ip &lt;&lt; endl;     break; }<\/code><\/pre>\n<p>\u042f \u0441\u0447\u0438\u0442\u0430\u044e, \u0447\u0442\u043e traceroute \u0438 ping &#8212; \u0443\u0442\u0438\u043b\u0438\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u043b\u0443\u0447\u0448\u0430\u0442 \u043f\u043e\u0440\u0442\u0444\u043e\u043b\u0438\u043e \u0438 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0433\u043b\u0443\u0431\u0436\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u0441\u0435\u0442\u0435\u0432\u044b\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c. \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u043b\u044f \u043e\u0431\u0449\u0435\u0433\u043e \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc791\" rel=\"noopener noreferrer nofollow\">https:\/\/www.rfc-editor.org\/rfc\/rfc791<\/a> (\u043f\u0440\u043e \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b IP).<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/726714\/\"> https:\/\/habr.com\/ru\/articles\/726714\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-408115","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/408115","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=408115"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/408115\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=408115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=408115"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=408115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}