{"id":336,"date":"2010-06-14T16:07:10","date_gmt":"2010-06-14T07:07:10","guid":{"rendered":"http:\/\/labs.gree.jp\/blog\/?p=336"},"modified":"2021-04-27T15:03:15","modified_gmt":"2021-04-27T06:03:15","slug":"post336","status":"publish","type":"post","link":"https:\/\/labs.gree.jp\/blog\/2010\/06\/336\/","title":{"rendered":"Ping \u3092\u4f5c\u308d\u3046"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3002\u30d7\u30e9\u30c3\u30c8\u30d5\u30a9\u30fc\u30e0\u958b\u767a\u90e8\u306e ebisawa \u3067\u3059\u3002\u3088\u308d\u3057\u304f\u304a\u9858\u3044\u3057\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f\u304a\u306a\u3058\u307f ping \u306e\u304a\u8a71\u3067\u3059\u3002<\/p>\n<h3 id=\"hs_3fa6af8e08ab71c6d25661b9b0ab3d10_header_0\"> \u305f\u304b\u304c ping \u3055\u308c\u3069 ping<\/h3>\n<p>\u3053\u306e\u30d6\u30ed\u30b0\u3092\u3054\u89a7\u306e\u65b9\u306a\u3089\u307e\u305a\u9593\u9055\u3044\u306a\u304f\u3054\u5b58\u77e5\u306e ping \u30b3\u30de\u30f3\u30c9\u3067\u3059\u304c\u3001\u3082\u3061\u308d\u3093\u30b0\u30ea\u30fc\u306e\u30a4\u30f3\u30d5\u30e9\u904b\u7528\u3067\u3082\u69d8\u3005\u306a\u5834\u9762\u3067\u6d3b\u8e8d\u3057\u3066\u3044\u307e\u3059\u3002\u30b5\u30fc\u30d3\u30b9\u306e\u30a4\u30f3\u30d5\u30e9\u3092\u69cb\u6210\u3059\u308b\u30b5\u30fc\u30d0\u3084\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u6a5f\u5668\u306f\u3001\u5e38\u306b\u69d8\u3005\u306a\u65b9\u6cd5\u3067\u6b63\u5e38\u306b\u7a3c\u50cd\u3057\u3066\u3044\u308b\u304b\u76e3\u8996\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001ping \u306b\u3088\u308b\u6b7b\u6d3b\u76e3\u8996\u306f\u3001\u4e2d\u3067\u3082\u6700\u3082\u57fa\u672c\u7684\u3067\u91cd\u8981\u3068\u3044\u3048\u308b\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u305d\u3093\u306a ping \u3067\u3059\u304c\u3001ping \u76f8\u5f53\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u3044\u3066\u307f\u305f\u3068\u304b\u3001\u3069\u3046\u3044\u3046\u4ed5\u7d44\u307f\u3067\u52d5\u3044\u3066\u3044\u308b\u304b\u307e\u3067\u7406\u89e3\u3059\u308b\u6a5f\u4f1a\u306f\u5c11\u306a\u3044\u306e\u3067\u306f\u306a\u3044\u304b\u3068\u601d\u3044\u307e\u3059\u3002\u305d\u3053\u3067\u3001\u4eca\u56de\u306f ping \u306b\u3064\u3044\u3066\u66f8\u3044\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u306a\u304a\u3001\u4ee5\u4e0b\u306b\u51fa\u3066\u304f\u308b\u4f8b\u306f\u3001\u4e3b\u306b Debian GNU\/Linux (lenny) \u30de\u30b7\u30f3\u3067\u8a66\u3057\u305f\u3082\u306e\u3067\u3059\u3002<\/p>\n<h5 id=\"hs_3fa6af8e08ab71c6d25661b9b0ab3d10_header_1\"> \u76ee\u6b21<\/h5>\n<ul>\n<li> ping \u306e\u3057\u304f\u307f<\/li>\n<li> ping \u306e\u4f5c\u308a\u304b\u305f<\/li>\n<li> \u4f5c\u3063\u3066\u307f\u305f<\/li>\n<\/ul>\n<h3 id=\"hs_3fa6af8e08ab71c6d25661b9b0ab3d10_header_2\"> ping \u306e\u3057\u304f\u307f<\/h3>\n<h4 id=\"hs_3fa6af8e08ab71c6d25661b9b0ab3d10_header_3\"> ICMP \u30a8\u30b3\u30fc\u30ea\u30af\u30a8\u30b9\u30c8<\/h4>\n<p>\u591a\u304f\u306e ping \u306e\u5b9f\u88c5\u3067\u306f\u3001ICMP \u306e Echo Request \u3092\u5229\u7528\u3057\u3066\u3044\u307e\u3059\u3002ICMP \u306f\u3001\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u306b\u304a\u3044\u3066\u5230\u9054\u4e0d\u80fd\u7b49\u306e\u30a8\u30e9\u30fc\u901a\u77e5\u7b49\u306b\u7528\u3044\u3089\u308c\u308b\u30d7\u30ed\u30c8\u30b3\u30eb\u3067\u3001RFC792 \u7b49\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u307e\u3059\u3002ICMP \u306b\u306f\u3001\u30a8\u30b3\u30fc\u3068\u547c\u3070\u308c\u308b\u3001\u5b9b\u5148\u304b\u3089\u306e\u8fd4\u7b54\u3092\u8981\u6c42\u3059\u308b\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u3092\u5229\u7528\u3057\u305f\u306e\u304c\u3044\u308f\u3086\u308b ping \u3067\u3059\u3002<\/p>\n<pre class=\"superpre \">\n14:22:59.663727 IP 10.129.0.112 > 10.129.0.1: ICMP echo request, id 62558, seq 0, length 64\n    0x0000:  4500 0054 11f4 0000 4001 5343 0a81 0070\n    0x0010:  0a81 0001 0800 c3a3 f45e 0000 b38d 084c\n    0x0020:  8f20 0a00 0809 0a0b 0c0d 0e0f 1011 1213\n    0x0030:  1415 1617 1819 1a1b 1c1d 1e1f 2021 2223\n    0x0040:  2425 2627 2829 2a2b 2c2d 2e2f 3031 3233\n    0x0050:  3435                                   \n14:22:59.729068 IP 10.129.0.1 > 10.129.0.112: ICMP echo reply, id 62558, seq 0, length 64\n    0x0000:  4500 0054 11f4 0000 ff01 9442 0a81 0001\n    0x0010:  0a81 0070 0000 cba3 f45e 0000 b38d 084c\n    0x0020:  8f20 0a00 0809 0a0b 0c0d 0e0f 1011 1213\n    0x0030:  1415 1617 1819 1a1b 1c1d 1e1f 2021 2223\n    0x0040:  2425 2627 2829 2a2b 2c2d 2e2f 3031 3233\n    0x0050:  3435                                   <\/pre>\n<p>tcpdump \u3057\u3066\u307f\u308b\u3068\u4e0a\u306e\u4f8b\u306e\u3088\u3046\u306a\u30d1\u30b1\u30c3\u30c8\u306e\u6d41\u308c\u304c\u898b\u3089\u308c\u307e\u3059\u3002\u78ba\u304b\u306b ICMP \u30a8\u30b3\u30fc\u30ea\u30af\u30a8\u30b9\u30c8\u306b\u5bfe\u3057\u3001\u5b9b\u5148\u30db\u30b9\u30c8\u304c\u30ea\u30d7\u30e9\u30a4\u3092\u8fd4\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>RFC792 \u306b\u3088\u308c\u3070\u3001\u30a8\u30b3\u30fc\u306e\u5834\u5408\u306e ICMP \u30d8\u30c3\u30c0\u5f62\u5f0f\u304c\u6b21\u306e\u3088\u3046\u306b\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u3053\u306e\u5f62\u5f0f\u306e\u30d8\u30c3\u30c0\u306b\u6240\u5b9a\u306e\u30b3\u30fc\u30c9\u3092\u30bb\u30c3\u30c8\u3057\u3066\u9001\u4fe1\u3059\u308c\u3070\u3001\u30a8\u30b3\u30fc\u30ea\u30af\u30a8\u30b9\u30c8 (\u307e\u305f\u306f\u30ea\u30d7\u30e9\u30a4) \u306b\u306a\u308b\u308f\u3051\u3067\u3059\u3002\u306a\u304a\u3001Data \u306e\u9818\u57df\u306b\u306f\u4efb\u610f\u306e\u30c7\u30fc\u30bf\u3092\u30bb\u30c3\u30c8\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002(\u4e0a\u306e\u30c0\u30f3\u30d7\u4f8b\u3067\u306f\u4f55\u304b\u306e\u30c7\u30fc\u30bf\u304c\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u306d)<\/p>\n<pre class=\"superpre \">\nEcho or Echo Reply Message\n\n    0                   1                   2                   3\n    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1\n   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n   |     Type      |     Code      |          Checksum             |\n   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n   |           Identifier          |        Sequence Number        |\n   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n   |     Data ...\n   +-+-+-+-+-<\/pre>\n<h4 id=\"hs_3fa6af8e08ab71c6d25661b9b0ab3d10_header_4\"> \u5230\u9054\u4e0d\u80fd\u691c\u77e5<\/h4>\n<p>\u5b9b\u5148\u30db\u30b9\u30c8\u3084\u9014\u4e2d\u306e\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u7d4c\u8def\u306b\u554f\u984c\u304c\u3042\u308b\u3068\u304d\u306f\u3001ICMP \u306e \"Destination Unreachable\" \u30e1\u30c3\u30bb\u30fc\u30b8\u306b\u3088\u308a\u7570\u5e38\u3092\u901a\u77e5\u3055\u308c\u308b\u3053\u3068\u304c\u3042\u308a\u3001\u3053\u306e\u5834\u5408\u306f\u660e\u3089\u304b\u306b\u5230\u9054\u4e0d\u80fd\u3068\u5224\u65ad\u3067\u304d\u307e\u3059\u3002\u3057\u304b\u3057\u3001ICMP \u306b\u3088\u308b\u901a\u77e5\u306f\u5fc5\u305a\u53d7\u4fe1\u3067\u304d\u308b\u308f\u3051\u3067\u306f\u306a\u3044\u305f\u3081\u3001\u6700\u7d42\u7684\u306b\u306f\u3001\u30a8\u30b3\u30fc\u30ea\u30d7\u30e9\u30a4\u53d7\u4fe1\u5f85\u3061\u306e\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u306b\u3088\u308a\u3001\u5b9b\u5148\u3078\u5230\u9054\u3067\u304d\u306a\u304b\u3063\u305f\u3068\u5224\u65ad\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h4 id=\"hs_3fa6af8e08ab71c6d25661b9b0ab3d10_header_5\"> RTT \u306e\u8a08\u6e2c<\/h4>\n<p>\u591a\u304f\u306e ping \u306e\u5b9f\u88c5\u306b\u306f\u3001\u30ea\u30d7\u30e9\u30a4\u306e\u53d7\u4fe1\u307e\u3067\u306b\u304b\u304b\u3063\u305f\u6642\u9593 (\u30e9\u30a6\u30f3\u30c9\u30c8\u30ea\u30c3\u30d7\u30bf\u30a4\u30e0) \u3092\u8868\u793a\u3059\u308b\u6a5f\u80fd\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u306f\u3001\u30ea\u30af\u30a8\u30b9\u30c8\u9001\u4fe1\u6642\u523b\u3092\u8a18\u9332\u3057\u3066\u304a\u304d\u3001\u30ea\u30d7\u30e9\u30a4\u53d7\u4fe1\u6642\u306e\u6642\u523b\u3068\u306e\u5dee\u3092\u6c42\u3081\u308b\u3053\u3068\u3067\u5b9f\u73fe\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u65e2\u5b58\u306e ping \u306e\u5b9f\u88c5\u3067\u306f\u3001ICMP \u306e Data \u9818\u57df\u306b\u9001\u4fe1\u6642\u523b\u60c5\u5831\u3092\u4fdd\u5b58\u3059\u308b\u30c6\u30af\u30cb\u30c3\u30af\u304c\u3088\u304f\u4f7f\u308f\u308c\u3066\u3044\u307e\u3059\u3002Data \u9818\u57df\u306f\u3001\u30ea\u30d7\u30e9\u30a4\u30e1\u30c3\u30bb\u30fc\u30b8\u306b\u305d\u306e\u307e\u307e\u30b3\u30d4\u30fc\u3055\u308c\u308b\u305f\u3081\u3001\u30ea\u30d7\u30e9\u30a4\u53d7\u4fe1\u6642\u306b\u53c2\u7167\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u4e0a\u306e ICMP \u30a8\u30b3\u30fc\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u30c0\u30f3\u30d7\u7d50\u679c\u306e\u3046\u3061\u3001Data \u9818\u57df\u3092\u6539\u3081\u3066\u307f\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre class=\"superpre \">\n    0x0010:                                b38d 084c\n    0x0020:  8f20 0a00 0809 0a0b 0c0d 0e0f 1011 1213\n    0x0030:  1415 1617 1819 1a1b 1c1d 1e1f 2021 2223\n    0x0040:  2425 2627 2829 2a2b 2c2d 2e2f 3031 3233\n    0x0050:  3435     <\/pre>\n<p>1 \u30aa\u30af\u30c6\u30c3\u30c8\u3054\u3068\u306b\u30a4\u30f3\u30af\u30ea\u30e1\u30f3\u30c8\u3055\u308c\u3066\u3044\u308b\u3001\u3044\u304b\u306b\u3082\u30c0\u30df\u30fc\u30c7\u30fc\u30bf\u3068\u3044\u3046\u611f\u3058\u3067\u3059\u304c\u3001\u3088\u304f\u898b\u308b\u3068\u5148\u982d\u306e 8 \u30aa\u30af\u30c6\u30c3\u30c8\u3060\u3051\u7570\u306a\u308a\u307e\u3059\u3002\u5b9f\u306f\u3053\u306e\u90e8\u5206\u304c\u9001\u4fe1\u6642\u523b\u60c5\u5831 (struct timeval) \u3067\u3059\u3002<\/p>\n<p>\u3054\u5b58\u77e5\u306e\u901a\u308a\u3001\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u3067\u306f\u30d1\u30b1\u30c3\u30c8\u306e\u6d88\u5931\u3084\u914d\u9001\u9806\u5e8f\u306e\u9006\u8ee2\u304c\u8d77\u3053\u308a\u5f97\u308b\u305f\u3081\u3001\u9001\u4fe1\u6642\u523b\u60c5\u5831\u306e\u7ba1\u7406\u304c\u8907\u96d1\u306b\u306a\u308a\u304c\u3061\u3067\u3059\u304c\u3001\u3053\u306e\u5834\u5408\u306f\u3001\u5358\u7d14\u306b\u53d7\u4fe1\u3057\u305f\u30d1\u30b1\u30c3\u30c8\u304b\u3089\u9001\u4fe1\u6642\u523b\u60c5\u5831\u3092\u53d6\u308a\u51fa\u305b\u3070\u3044\u3044\u306e\u3067\u3001\u3068\u3066\u3082\u30b7\u30f3\u30d7\u30eb\u306b\u5b9f\u88c5\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u306a\u304a\u3001\u4e0a\u306e\u30d1\u30b1\u30c3\u30c8\u30c0\u30f3\u30d7\u4f8b\u306f x86 32bit \u30de\u30b7\u30f3\u3067\u5b9f\u884c\u3057\u305f\u3082\u306e\u3067\u3059\u3002\u4e0b\u306e\u30c0\u30f3\u30d7\u4f8b\u306f x86 64bit \u30de\u30b7\u30f3\u3067\u5b9f\u884c\u3057\u305f\u3082\u306e\u3067\u3059\u304c\u3001\u4e0a\u306e\u4f8b\u3068\u5fae\u5999\u306b\u7570\u306a\u308b\u306e\u304c\u304a\u308f\u304b\u308a\u3067\u3057\u3087\u3046\u304b\u3002struct timeval \u306e\u30b5\u30a4\u30ba\u306e\u9055\u3044\u304c\u898b\u3066\u53d6\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"superpre \">\n03:26:58.674303 IP 127.0.0.1 > 127.0.0.1: ICMP echo request, id 37930, seq 1, length 64\n    0x0000:  4500 0054 0000 4000 4001 3ca7 7f00 0001\n    0x0010:  7f00 0001 0800 3310 942a 0001 825b 104c\n    0x0020:  0000 0000 d549 0a00 0000 0000 1011 1213\n    0x0030:  1415 1617 1819 1a1b 1c1d 1e1f 2021 2223\n    0x0040:  2425 2627 2829 2a2b 2c2d 2e2f 3031 3233\n    0x0050:  3435                                   <\/pre>\n<h3 id=\"hs_3fa6af8e08ab71c6d25661b9b0ab3d10_header_6\"> ping \u306e\u4f5c\u308a\u65b9<\/h3>\n<p>\u8981\u3059\u308b\u306b ICMP echo \u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u9001\u53d7\u4fe1\u3059\u308c\u3070 ping \u7684\u306a\u30d7\u30ed\u30b0\u30e9\u30e0\u306b\u306a\u308a\u307e\u3059\u3002\u305d\u3053\u3067\u3001ICMP \u30d1\u30b1\u30c3\u30c8\u3092\u9001\u53d7\u4fe1\u3059\u308b\u305f\u3081\u306e socket API \u306e\u4f7f\u3044\u65b9\u3092\u898b\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>TCP \u3067\u3082 UDP \u3067\u3082\u306a\u3044 ICMP \u306f\u3001raw socket \u3068\u547c\u3070\u308c\u308b\u7279\u6b8a\u306a socket \u3092\u4f7f\u3063\u3066\u9001\u53d7\u4fe1\u3057\u307e\u3059\u3002raw socket \u3092\u7528\u3044\u308b\u3068\u3001\u30d7\u30ed\u30c8\u30b3\u30eb\u30d8\u30c3\u30c0\u307e\u3067\u542b\u3081\u3066\u9001\u53d7\u4fe1\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u57fa\u672c\u7684\u306a\u624b\u9806\u306f\u6b21\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n<ul>\n<li> raw socket \u751f\u6210<\/li>\n<li> ICMP \u30a8\u30b3\u30fc\u30ea\u30af\u30a8\u30b9\u30c8\u30d1\u30b1\u30c3\u30c8\u3092\u69cb\u7bc9<\/li>\n<li> sendto() \u7b49\u3067\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u9001\u4fe1<\/li>\n<li> recvfrom() \u7b49\u3067\u30ea\u30d7\u30e9\u30a4\u3092\u53d7\u4fe1<\/li>\n<li> \u53d7\u4fe1\u3057\u305f\u30d1\u30b1\u30c3\u30c8\u3092\u5206\u6790<\/li>\n<\/ul>\n<h4 id=\"hs_3fa6af8e08ab71c6d25661b9b0ab3d10_header_7\"> socket \u306e\u4f5c\u6210<\/h4>\n<pre class=\"superpre c\">\n    s = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);<\/pre>\n<p>\u307e\u305a\u306f\u304a\u306a\u3058\u307f socket() \u30b7\u30b9\u30c6\u30e0\u30b3\u30fc\u30eb\u3067\u3059\u3002type \u3068\u3057\u3066 SOCK_RAW \u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u666e\u6bb5\u306f\u307b\u3068\u3093\u3069\u4f7f\u308f\u306a\u3044 3 \u756a\u76ee\u306e\u5f15\u6570\u3067\u3059\u304c\u3001raw socket \u306e\u5834\u5408\u306f\u660e\u793a\u7684\u306b\u6307\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u4eca\u56de\u306f ICMP \u3092\u6271\u3044\u305f\u3044\u306e\u3067 IPPROTO_ICMP \u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>raw socket \u306e\u751f\u6210\u306b\u306f root \u6a29\u9650\u304c\u5fc5\u8981\u3067\u3059\u3002\u3069\u3093\u306a\u30d1\u30b1\u30c3\u30c8\u3067\u3082\u9001\u4fe1\u3067\u304d\u3066\u3057\u307e\u3046\u306e\u3067\u3001\u8ab0\u306b\u3067\u3082\u8a31\u53ef\u3059\u308b\u308f\u3051\u306b\u306f\u3044\u304b\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u306a\u306e\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>\u306a\u304a\u3001IP \u30d8\u30c3\u30c0\u307e\u3067\u542b\u3081\u3066\u81ea\u524d\u3067\u7528\u610f\u3059\u308b\u304b\u3092\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u9078\u629e\u3067\u304d\u307e\u3059\u3002setsockopt() \u3067 IP_HDRINCL \u3092\u30aa\u30f3\u306b\u3059\u308b\u3068\u3001\u81ea\u524d\u3067\u7528\u610f\u3057\u305f\u3082\u306e\u3092\u9001\u4fe1\u3067\u304d\u307e\u3059\u3002\u4eca\u56de\u306f\u7279\u306b\u5fc5\u8981\u304c\u306a\u3044\u306e\u3067\u3001\u30aa\u30d5\u306e\u307e\u307e\u3067\u3059\u3002\u30aa\u30d5\u306e\u5834\u5408\u306f\u3001ICMP \u30d8\u30c3\u30c0\u4ee5\u964d\u306e\u30c7\u30fc\u30bf\u3092\u7528\u610f\u3059\u308c\u3070\u3088\u3044\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h4 id=\"hs_3fa6af8e08ab71c6d25661b9b0ab3d10_header_8\"> ICMP \u30d1\u30b1\u30c3\u30c8\u306e\u751f\u6210<\/h4>\n<p>ICMP \u30a8\u30b3\u30fc\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u751f\u6210\u3057\u307e\u3059\u3002\u3068\u308a\u3042\u3048\u305a\u3001RTT \u306e\u8a08\u7b97\u6a5f\u80fd\u306f\u8003\u3048\u306a\u3044\u3053\u3068\u306b\u3057\u3066\u3001Data \u90e8\u5206\u306f\u7a7a\u306b\u3057\u307e\u3059\u3002\u6240\u5b9a\u306e\u5f62\u5f0f\u3067\u30d8\u30c3\u30c0\u90e8\u306e\u307f\u4f5c\u308c\u3070\u3088\u3044\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"superpre c\">\n#define ICMP_ECHO_REQ   8\n#define ICMP_ECHO_REP   0\n\ntypedef struct {\n    uint8_t   icmpe_type;\n    uint8_t   icmpe_code;\n    uint16_t  icmpe_csum;\n    uint16_t  icmpe_id;\n    uint16_t  icmpe_seq;\n} icmp_echo_t;\n\nint\nset_icmp_echo_header(void *buf, int len, int echo_seq, int echo_id)\n{\n    icmp_echo_t *icmpe;\n\n    if (len < sizeof(*icmpe))\n        return -1;\n\n    memset(buf, 0, len);\n    icmpe = (icmp_echo_t *) buf;\n    icmpe->icmpe_type = ICMP_ECHO_REQ;\n    icmpe->icmpe_code = 0;\n    icmpe->icmpe_csum = 0;\n    icmpe->icmpe_id = htons(echo_id);\n    icmpe->icmpe_seq = htons(echo_seq);\n    icmpe->icmpe_csum = checksum(buf, sizeof(*icmpe));\n\n    return sizeof(*icmpe);\n}<\/pre>\n<p>\u3053\u306e\u3088\u3046\u306a\u611f\u3058\u3067\u666e\u901a\u306b\u4f5c\u308c\u3070 ok \u3067\u3059\u3002<\/p>\n<p>\u8907\u6570\u306e\u30a8\u30b3\u30fc\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u9001\u4fe1\u3057\u305f\u3068\u304d\u3001\u30ea\u30d7\u30e9\u30a4\u304c\u3069\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u306b\u5bfe\u5fdc\u3057\u305f\u3082\u306e\u304b\u5224\u65ad\u3059\u308b\u305f\u3081\u3001sequence \u306e\u5024\u306f\u9001\u4fe1\u3059\u308b\u305f\u3073\u306b\u30a4\u30f3\u30af\u30ea\u30e1\u30f3\u30c8\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u81ea\u5206\u304c\u9001\u4fe1\u3057\u305f\u30ea\u30af\u30a8\u30b9\u30c8\u306b\u5bfe\u3059\u308b\u30ea\u30d7\u30e9\u30a4\u304b\u3069\u3046\u304b\u5224\u5b9a\u3059\u308b\u305f\u3081\u3001\u4ed6\u306b\u4f7f\u308f\u308c\u3066\u3044\u306a\u305d\u3046\u306a\u5024\u3092 id  \u306b\u30bb\u30c3\u30c8\u3057\u307e\u3059\u3002\u540c\u3058\u30db\u30b9\u30c8\u4e0a\u3067\u3001\u540c\u6642\u306b\u4ed6\u306e ping \u304c\u5b9f\u884c\u3055\u308c\u3066\u3044\u305f\u5834\u5408\u306b\u56f0\u3089\u306a\u3044\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002\u3053\u3053\u3067\u306f\u3001\u4e71\u6570\u3092\u751f\u6210\u3057\u3066\u4f7f\u3046\u306e\u304c\u304a\u3059\u3059\u3081\u3067\u3059\u3002<\/p>\n<p>\u306a\u304a\u3001\u30ea\u30d7\u30e9\u30a4\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u9001\u4fe1\u5143\u306f\u3001\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u9001\u4fe1\u5148\u3068\u7570\u306a\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u306b\u5bfe\u3059\u308b\u30ea\u30d7\u30e9\u30a4\u304b\u306e\u5224\u5b9a\u306b\u3001id \u306e\u5024\u3092\u7528\u3044\u308b\u65b9\u6cd5\u3082\u8003\u3048\u3089\u308c\u307e\u3059\u3002<\/p>\n<p>\u30c1\u30a7\u30c3\u30af\u30b5\u30e0\u306f\u30011\u306e\u88dc\u6570\u306e\u548c\u306e\u3055\u3089\u306b1\u306e\u88dc\u6570\u3092\u6c42\u3081\u308b\u72ec\u7279\u306e\u65b9\u6cd5\u3067\u8a08\u7b97\u3057\u307e\u3059\u3002<\/p>\n<h4 id=\"hs_3fa6af8e08ab71c6d25661b9b0ab3d10_header_9\"> ICMP \u30a8\u30b3\u30fc\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u9001\u53d7\u4fe1<\/h4>\n<p>\u666e\u901a\u306b sendto() \u3084 recvfrom() \u3092\u4f7f\u3063\u3066\u30c7\u30fc\u30bf\u3092\u9001\u53d7\u4fe1\u3057\u307e\u3059\u3002<\/p>\n<h4 id=\"hs_3fa6af8e08ab71c6d25661b9b0ab3d10_header_10\"> \u53d7\u4fe1\u3057\u305f\u30d1\u30b1\u30c3\u30c8\u306e\u89e3\u6790<\/h4>\n<p>\u30d1\u30b1\u30c3\u30c8\u3092\u53d7\u4fe1\u3057\u305f\u3089\u3001\u53d7\u4fe1\u3057\u305f\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u3001\u81ea\u5206\u304c\u9001\u4fe1\u3057\u305f\u30a8\u30b3\u30fc\u30ea\u30af\u30a8\u30b9\u30c8\u306b\u5bfe\u3059\u308b\u30ea\u30d7\u30e9\u30a4\u304b\u78ba\u304b\u3081\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>raw socket \u304b\u3089\u306e\u53d7\u4fe1\u30c7\u30fc\u30bf\u306f\u3001\u9001\u4fe1\u6642\u3068\u7570\u306a\u308a\u3001\u5e38\u306b IP \u30d8\u30c3\u30c0\u304c\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u3002\u53d7\u4fe1\u3057\u305f ICMP \u30d8\u30c3\u30c0\u306f\u3001\u5148\u982d\u306e IP \u30d8\u30c3\u30c0\u306e\u7d9a\u304d\u306b\u5b58\u5728\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u307e\u305a\u306f IP \u30d8\u30c3\u30c0\u306e\u30b5\u30a4\u30ba\u3092\u8abf\u3079\u307e\u3059\u3002<\/p>\n<p>RFC791 \u306b\u3088\u308c\u3070\u3001IP \u30d8\u30c3\u30c0\u306f\u6b21\u306e\u3088\u3046\u306a\u5f62\u5f0f\u3067\u3059\u3002<\/p>\n<pre class=\"superpre \">\n    0                   1                   2                   3   \n    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 \n   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n   |Version|  IHL  |Type of Service|          Total Length         |\n   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n   |         Identification        |Flags|      Fragment Offset    |\n   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n   |  Time to Live |    Protocol   |         Header Checksum       |\n   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n   |                       Source Address                          |\n   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n   |                    Destination Address                        |\n   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n   |                    Options                    |    Padding    |\n   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<\/pre>\n<p>IP \u30d8\u30c3\u30c0\u306f\u3001\u30aa\u30d7\u30b7\u30e7\u30f3\u30d8\u30c3\u30c0\u306e\u6709\u7121\u306b\u3088\u308a\u9577\u3055\u304c\u53ef\u5909\u3059\u308b\u306e\u3067\u3001IHL \u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u5024\u304b\u3089\u30d8\u30c3\u30c0\u9577\u3092\u8a08\u7b97\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002IP \u30d8\u30c3\u30c0\u9577\u304c\u308f\u304b\u308c\u3070 ICMP \u30d8\u30c3\u30c0\u306e\u4f4d\u7f6e\u304c\u308f\u304b\u308a\u307e\u3059\u3002ICMP \u30d8\u30c3\u30c0\u306e type, code, sequence, id \u7b49\u306e\u5024\u3092\u53c2\u7167\u3057\u3066\u3001\u5168\u3066\u9069\u5207\u306a\u5024\u3067\u3042\u308c\u3070\u3001\u9593\u9055\u3044\u306a\u304f\u81ea\u5206\u304c\u9001\u4fe1\u3057\u305f\u30ea\u30af\u30a8\u30b9\u30c8\u306b\u5bfe\u3059\u308b\u30ea\u30d7\u30e9\u30a4\u3060\u3068\u5224\u65ad\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u5177\u4f53\u7684\u306b\u306f\u6b21\u306e\u3088\u3046\u306a\u611f\u3058\u306b\u3059\u308b\u3068\u3088\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"superpre c\">\nint\nread_icmp_echo_header(int *echo_seq, int *echo_id, void *buf, int len)\n{\n    int ihl;\n    icmp_echo_t *icmpe;\n\n    \/* IP header length *\/\n    ihl = (*((uint8_t *) buf) & 0x0f) * 4;\n    icmpe = (icmp_echo_t *) (buf + ihl);\n\n    if (len < ihl + sizeof(icmp_echo_t))\n        return -1;\n    if (icmpe->icmpe_type != ICMP_ECHO_REP || icmpe->icmpe_code != 0)\n        return -1;\n\n    *echo_id = ntohs(icmpe->icmpe_id);\n    *echo_seq = ntohs(icmpe->icmpe_seq);\n\n    return 0;\n}<\/pre>\n<h3 id=\"hs_3fa6af8e08ab71c6d25661b9b0ab3d10_header_11\"> \u4f5c\u3063\u3066\u307f\u305f<\/h3>\n<p>\u3068\u3044\u3046\u308f\u3051\u3067\u3001\u4e00\u9023\u306e\u6d41\u308c\u3055\u3048\u7406\u89e3\u3057\u3066\u3057\u307e\u3048\u3070\u3001ping \u76f8\u5f53\u306e\u30c4\u30fc\u30eb\u3092\u4f5c\u308b\u306e\u306f\u7c21\u5358\u3060\u3068\u3044\u3046\u3053\u3068\u304c\u7406\u89e3\u3044\u305f\u3060\u3051\u305f\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u3088\u304f\u4f7f\u3046\u30c4\u30fc\u30eb\u3060\u3051\u306b\u3001\u5229\u7528\u72b6\u6cc1\u306b\u3042\u308f\u305b\u3066\u4f5c\u3089\u308c\u305f\u3082\u306e\u304c\u3042\u308b\u3068\u5927\u5909\u4fbf\u5229\u3067\u4ed5\u4e8b\u3082\u306f\u304b\u3069\u308a\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u3001\u5b9f\u88c5\u306e\u30b5\u30f3\u30d7\u30eb\u3092\u517c\u306d\u3066\u3061\u3087\u3063\u3068\u3057\u305f\u3082\u306e\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u5834\u6240\u3067\u516c\u958b\u3044\u305f\u3057\u307e\u3059\u3002\u4f55\u304b\u306e\u53c2\u8003\u306b\u3057\u3066\u3044\u305f\u3060\u3051\u308b\u3068\u5e78\u3044\u3067\u3059\u3002<\/p>\n<p><a href=\"http:\/\/github.com\/ebisawa\/ruby-bulkping\">http:\/\/github.com\/ebisawa\/ruby-bulkping<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3002\u30d7\u30e9\u30c3\u30c8\u30d5\u30a9\u30fc\u30e0\u958b\u767a\u90e8\u306e ebisawa \u3067\u3059\u3002\u3088\u308d\u3057\u304f\u304a\u9858\u3044\u3057\u307e\u3059\u3002 \u4eca\u56de\u306f\u304a\u306a\u3058\u307f ping \u306e\u304a\u8a71\u3067\u3059\u3002 \u305f\u304b\u304c ping \u3055\u308c\u3069 ping \u3053\u306e\u30d6\u30ed\u30b0\u3092\u3054\u89a7\u306e\u65b9\u306a\u3089\u307e\u305a\u9593\u9055\u3044\u306a\u304f\u3054\u5b58\u77e5\u306e ping \u30b3 [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9],"tags":[13],"class_list":["post-336","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-info","tag-sockets-api"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/336","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/comments?post=336"}],"version-history":[{"count":3,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/336\/revisions"}],"predecessor-version":[{"id":21128,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/336\/revisions\/21128"}],"wp:attachment":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/media?parent=336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/categories?post=336"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/tags?post=336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}