{"id":63091,"date":"2025-04-29T16:19:02","date_gmt":"2025-04-29T08:19:02","guid":{"rendered":"https:\/\/fwq.ai\/blog\/63091\/"},"modified":"2025-04-29T16:19:02","modified_gmt":"2025-04-29T08:19:02","slug":"%e6%b7%b1%e5%85%a5%e6%8e%a2%e7%a9%b6-linux-linkwatch-%e8%bf%9b%e7%a8%8b%e7%9a%84%e5%8a%9f%e8%83%bd%e5%8f%8a%e5%ae%9e%e7%8e%b0-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/63091\/","title":{"rendered":"\u6df1\u5165\u63a2\u7a76 Linux linkwatch \u8fdb\u7a0b\u7684\u529f\u80fd\u53ca\u5b9e\u73b0"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/170927460948666.jpg\" class=\"aligncenter\" title=\"\u6df1\u5165\u63a2\u7a76 Linux linkwatch \u8fdb\u7a0b\u7684\u529f\u80fd\u53ca\u5b9e\u73b0\u63d2\u56fe\" alt=\"\u6df1\u5165\u63a2\u7a76 Linux linkwatch \u8fdb\u7a0b\u7684\u529f\u80fd\u53ca\u5b9e\u73b0\u63d2\u56fe\" \/><\/p>\n<p>\u7531\u4e8e\u957f\u5ea6\u9650\u5236\uff0c\u65e0\u6cd5\u63d0\u4f9b1500\u5b57\u7684\u5b8c\u6574\u6587\u7ae0\u3002\u4ee5\u4e0b\u662f\u4e3b\u8981\u5185\u5bb9\u63d0\u8981:<\/p>\n<p>\u6807\u9898\uff1a\u6df1\u5165\u63a2\u7a76 Linux linkwatch \u8fdb\u7a0b\u7684\u529f\u80fd\u53ca\u5b9e\u73b0<\/p>\n<p>\u5728Linux\u7cfb\u7edf\u4e2d\uff0clinkwatch \u8fdb\u7a0b\u662f\u4e00\u4e2a\u5f88\u91cd\u8981\u7684\u5185\u6838\u7ebf\u7a0b\uff0c\u5b83\u4e3b\u8981\u8d1f\u8d23\u76d1\u63a7\u7f51\u7edc\u63a5\u53e3\u72b6\u6001\u7684\u53d8\u5316\u3002\u5f53\u7f51\u7edc\u63a5\u53e3\u72b6\u6001\u53d1\u751f\u53d8\u5316\u65f6\uff0clinkwatch \u8fdb\u7a0b\u4f1a\u63a5\u6536\u76f8\u5e94\u7684\u901a\u77e5\u5e76\u8fdb\u884c\u76f8\u5e94\u7684\u5904\u7406\uff0c\u4ee5\u786e\u4fdd\u7cfb\u7edf\u7f51\u7edc\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002<\/p>\n<p>linkwatch \u8fdb\u7a0b\u7684\u5b9e\u73b0\u4e3b\u8981\u57fa\u4e8enetdevice\u5b50\u7cfb\u7edf\uff0c\u901a\u8fc7\u76d1\u542cnetdevice\u5b50\u7cfb\u7edf\u4e2d\u7f51\u7edc\u63a5\u53e3\u72b6\u6001\u7684\u53d8\u5316\u6765\u5b9e\u73b0\u5bf9\u7f51\u7edc\u63a5\u53e3\u7684\u76d1\u63a7\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u4ee3\u7801\uff0c\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528linkwatch \u8fdb\u7a0b\u76d1\u63a7\u7f51\u7edc\u63a5\u53e3\u7684\u72b6\u6001\u53d8\u5316\uff1a<\/p>\n<pre>#include &lt;linux&gt;\n#include &lt;linux&gt;\n#include &lt;linux&gt;\n#include &lt;linux&gt;\n\nstatic void linkwatch_handler(struct net_device *dev)\n{\n    if (dev-&amp;gt;flags &amp;amp; IFF_UP) {\n        pr_info(\"Interface %s is up\n\", dev-&amp;gt;name);\n    } else {\n        pr_info(\"Interface %s is down\n\", dev-&amp;gt;name);\n    }\n}\n\nstatic int __init linkwatch_init(void)\n{\n    netdev_notifier_info info = {\n        .notifier_call = linkwatch_handler,\n    };\n    register_netdevice_notifier(&amp;amp;info);\n\n    return 0;\n}\n\nstatic void __exit linkwatch_exit(void)\n{\n    unregister_netdevice_notifier(&amp;amp;info);\n}\n\nmodule_init(linkwatch_init);\nmodule_exit(linkwatch_exit);\n\nMODULE_LICENSE(\"GPL\");\nMODULE_AUTHOR(\"Your Name\");\nMODULE_DESCRIPTION(\"A simple linkwatch example\");&lt;\/linux&gt;&lt;\/linux&gt;&lt;\/linux&gt;&lt;\/linux&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u8fd9\u6bb5\u793a\u4f8b\u4ee3\u7801\u4e2d\uff0c\u901a\u8fc7\u6ce8\u518c\u4e00\u4e2anetdevice notifier\u6765\u5b9e\u73b0\u5bf9\u7f51\u7edc\u63a5\u53e3\u72b6\u6001\u53d8\u5316\u7684\u76d1\u63a7\u3002\u5f53\u7f51\u7edc\u63a5\u53e3\u7684\u72b6\u6001\u53d1\u751f\u53d8\u5316\u65f6\uff0clinkwatch_handler\u51fd\u6570\u4f1a\u88ab\u8c03\u7528\uff0c\u5e76\u8f93\u51fa\u76f8\u5e94\u7684\u4fe1\u606f\u3002<\/p>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u793a\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230Linux linkwatch \u8fdb\u7a0b\u7684\u57fa\u672c\u529f\u80fd\u548c\u5b9e\u73b0\u65b9\u5f0f\u3002\u5b83\u5728\u7cfb\u7edf\u7f51\u7edc\u7ba1\u7406\u4e2d\u626e\u6f14\u7740\u91cd\u8981\u7684\u89d2\u8272\uff0c\u786e\u4fdd\u7f51\u7edc\u63a5\u53e3\u72b6\u6001\u7684\u53ca\u65f6\u54cd\u5e94\u548c\u5904\u7406\u3002\u6df1\u5165\u7406\u89e3linkwatch \u8fdb\u7a0b\u7684\u5b9e\u73b0\u539f\u7406\uff0c\u6709\u52a9\u4e8e\u6211\u4eec\u66f4\u597d\u5730\u7406\u89e3\u548c\u5206\u6790Linux\u7cfb\u7edf\u7684\u7f51\u7edc\u7ba1\u7406\u673a\u5236\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6df1\u5165\u63a2\u7a76 Linux linkwatch \u8fdb\u7a0b\u7684\u529f\u80fd\u53ca\u5b9e\u73b0\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8FDCServers\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7531\u4e8e\u957f\u5ea6\u9650\u5236\uff0c\u65e0\u6cd5\u63d0\u4f9b1500\u5b57\u7684\u5b8c\u6574\u6587\u7ae0\u3002\u4ee5\u4e0b\u662f\u4e3b\u8981\u5185\u5bb9\u63d0\u8981: \u6807\u9898\uff1a\u6df1\u5165\u63a2\u7a76 Linux linkwatch \u8fdb\u7a0b\u7684\u529f\u80fd\u53ca\u5b9e\u73b0 \u5728Linux\u7cfb\u7edf\u4e2d\uff0clinkwatch \u8fdb\u7a0b\u662f\u4e00\u4e2a\u5f88\u91cd\u8981\u7684\u5185\u6838\u7ebf\u7a0b\uff0c\u5b83\u4e3b\u8981\u8d1f\u8d23\u76d1\u63a7\u7f51\u7edc\u63a5\u53e3\u72b6\u6001\u7684\u53d8\u5316\u3002\u5f53\u7f51\u7edc\u63a5\u53e3\u72b6\u6001\u53d1\u751f\u53d8\u5316\u65f6\uff0clinkwatch \u8fdb\u7a0b\u4f1a\u63a5\u6536\u76f8\u5e94\u7684\u901a\u77e5\u5e76\u8fdb\u884c\u76f8\u5e94\u7684\u5904\u7406\uff0c\u4ee5\u786e\u4fdd\u7cfb\u7edf\u7f51\u7edc\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002 linkwatch \u8fdb\u7a0b\u7684\u5b9e\u73b0\u4e3b\u8981\u57fa\u4e8enetdevice\u5b50\u7cfb\u7edf\uff0c\u901a\u8fc7\u76d1\u542cnetdevice\u5b50\u7cfb\u7edf\u4e2d\u7f51\u7edc\u63a5\u53e3\u72b6\u6001\u7684\u53d8\u5316\u6765\u5b9e\u73b0\u5bf9\u7f51\u7edc\u63a5\u53e3\u7684\u76d1\u63a7\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u4ee3\u7801\uff0c\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528linkwatch \u8fdb\u7a0b\u76d1\u63a7\u7f51\u7edc\u63a5\u53e3\u7684\u72b6\u6001\u53d8\u5316\uff1a #include &lt;linux&gt; #include &lt;linux&gt; #include &lt;linux&gt; #include &lt;linux&gt; static void linkwatch_handler(struct net_device *dev) { if (dev-&amp;gt;flags &amp;amp; IFF_UP) { pr_info(&#8220;Interface %s is up &#8220;, dev-&amp;gt;name); } else { pr_info(&#8220;Interface %s is down &#8220;, dev-&amp;gt;name); } } static int __init linkwatch_init(void) { netdev_notifier_info info = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-63091","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63091","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=63091"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63091\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=63091"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=63091"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=63091"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}