{"id":382,"date":"2025-12-14T11:34:25","date_gmt":"2025-12-14T03:34:25","guid":{"rendered":"https:\/\/www.garfield-blog.top\/?p=382"},"modified":"2025-12-19T11:30:27","modified_gmt":"2025-12-19T03:30:27","slug":"%e3%80%90%e6%ba%90%e7%a0%81%e8%a7%a3%e6%9e%90%e3%80%91hostapd4ctrl_if%e5%ad%90%e6%a8%a1%e5%9d%97%e6%a2%b3%e7%90%86","status":"publish","type":"post","link":"https:\/\/www.garfield-blog.top\/?p=382","title":{"rendered":"\u3010\u6e90\u7801\u89e3\u6790\u3011hostapd(4)ctrl_if\u5b50\u6a21\u5757\u68b3\u7406"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u6982\u8ff0<\/h2>\n\n\n\n<p><code>hostapd<\/code>\u7684<code>ctrl i\/f<\/code>\uff08<code>control interface<\/code>\uff0c\u63a7\u5236\u63a5\u53e3\uff09\u6a21\u5757\u4e3b\u8981\u4f5c\u7528\u662f<strong>\u4e3a\u5916\u90e8\u7a0b\u5e8f\uff08\u5982\u547d\u4ee4\u884c\u5de5\u5177hostapd_cli\u3001GUI\u7b49\uff09\u63d0\u4f9b\u4e0ehostapd\u5b88\u62a4\u8fdb\u7a0b\u8fdb\u884c\u4ea4\u4e92\u7684\u673a\u5236<\/strong>\uff0c\u5b9e\u73b0\u8fd0\u884c\u65f6\u63a7\u5236\u548c\u72b6\u6001\u67e5\u8be2<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5bf9\u5e94\u6e90\u4ee3\u7801<\/h2>\n\n\n\n<p><code>ctrl if<\/code>\u6a21\u5757\u5bf9\u5e94\u6e90\u4ee3\u7801\u662f<code>.\/hostapd\/ctrl_iface.c<\/code>\u548c<code>.\/hostapd\/ctrl_iface.h<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">hostapd\u4e3b\u8fdb\u7a0b<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u914d\u7f6e\u53e5\u67c4<\/h3>\n\n\n\n<p><code>hostapd<\/code>\u901a\u4fe1\u65f6\u91c7\u7528\u7684\u65b9\u6cd5\u662f\u901a\u8fc7\u6587\u4ef6\u53e5\u67c4\u6765\u8fdb\u884c\u901a\u4fe1\uff0c\u53e5\u67c4\u4f1a\u5b58\u50a8\u5728<code>hostapd.conf<\/code>\u4e2d\u7684<code>ctrl_interface<\/code>\u914d\u7f6e\u9009\u9879\u4e2d\uff0c\u5728\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u65f6\u4f1a\u5c06\u8fd9\u4e2a\u5b57\u6bb5\u5b58\u5165<code>struct hostapd_bss_config<\/code>\u4e2d\u7684<code>ctrl_interface<\/code>\u5b57\u6bb5\u4e2d\u7528\u4e8e\u540e\u7eed\u7684\u4f7f\u7528<\/p>\n\n\n\n<p>\u5728<code>.\/hostapd\/hostapd.conf<\/code>\u4e2d\u53ef\u4ee5\u627e\u5230\u76f8\u5173\u7684\u6ce8\u91ca<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Interface for separate control program. If this is specified, hostapd\n# will create this directory and a UNIX domain socket for listening to requests\n# from external programs (CLI\/GUI, etc.) for status information and\n# configuration. The socket file will be named based on the interface name, so\n# multiple hostapd processes\/interfaces can be run at the same time if more\n# than one interface is used.\n# \/var\/run\/hostapd is the recommended directory for sockets and by default,\n# hostapd_cli will use it when trying to connect with hostapd.\nctrl_interface=\/var\/run\/hostapd<\/code><\/pre>\n\n\n\n<p>\u901a\u4fe1\u4f7f\u7528\u7684\u53e5\u67c4\u4f1a\u5728<code>hostapd_ctrl_iface_path<\/code>\u51fd\u6570\u4e2d\u62fc\u63a5\u800c\u6210<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>static char * hostapd_ctrl_iface_path(struct hostapd_data *hapd)\n{\n    char *buf;\n    size_t len;\n\n    if (hapd-&gt;conf-&gt;ctrl_interface == NULL)\n        return NULL;\n\n    len = os_strlen(hapd-&gt;conf-&gt;ctrl_interface) +\n        os_strlen(hapd-&gt;conf-&gt;iface) + 2;\n    buf = os_malloc(len);\n    if (buf == NULL)\n        return NULL;\n\n    os_snprintf(buf, len, \"%s\/%s\",\n            hapd-&gt;conf-&gt;ctrl_interface, hapd-&gt;conf-&gt;iface);\n    buf&#91;len - 1] = '\\0';\n    return buf;\n}<\/code><\/pre>\n\n\n\n<p>\u8fd9\u91cc\u7684<code>hapd-&gt;conf-&gt;ctrl_interface<\/code>\u662f\u5bf9\u5e94\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684<code>ctrl_interface<\/code>\uff0c<code>hapd-&gt;conf-&gt;iface<\/code>\u662f\u5bf9\u5e94\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684<code>interface<\/code>\u9009\u9879<\/p>\n\n\n\n<p>\u5728\u914d\u7f6e\u53e5\u67c4\u4e4b\u540e\u4f1a\u901a\u8fc7<code>eloop_register_read_sock<\/code>\u51fd\u6570\u6765\u5bf9\u5176\u8fdb\u884c\u76d1\u542c\uff0c\u540c\u65f6\u914d\u7f6e\u5bf9\u5e94\u56de\u8c03<code>hostapd_ctrl_iface_receive<\/code>\u7528\u6765\u5904\u7406<code>socket<\/code>\u4e2d\u7684\u6d88\u606f<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f7f\u7528\u547d\u4ee4<\/h3>\n\n\n\n<p>\u5728\u542f\u52a8<code>hostapd<\/code>\u4e3b\u8fdb\u7a0b\u4e4b\u540e\uff0c\u8f93\u5165<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo .\/hostapd_cli -i wlan0 help<\/code><\/pre>\n\n\n\n<p><code>-i<\/code>\u6307\u5b9a\u7aef\u53e3\uff0c<code>help<\/code>\u67e5\u770b\u4f7f\u7528\u5e2e\u52a9<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">hostapd_cli\u4fa7<\/h2>\n\n\n\n<p>\u5728<code>hostapd_cli<\/code>\u7684\u4e2d\u4f1a\u4f7f\u7528\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf<code>static struct wpa_ctrl *ctrl_conn<\/code>\u6765\u5b58\u50a8\u5f85\u4f7f\u7528\u7684<code>socket<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u521d\u59cb\u5316\u53e5\u67c4<\/h3>\n\n\n\n<p><code>hostapd_cli<\/code>\u5728\u4e0e<code>hostapd<\/code>\u7684\u4e3b\u8fdb\u7a0b\u8fdb\u884c\u901a\u4fe1\u65f6\u662f\u4f5c\u4e3a<code>client<\/code>\u7aef\uff0c\u5728\u521b\u5efa\u4e0e\u4e3b\u8fdb\u7a0b\u901a\u4fe1\u7684socket\u65f6\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f7f\u7528<code>bind<\/code>\u51fd\u6570\u5c06<code>socket<\/code>\u7ed1\u5b9a\u672c\u5730\u7684\u4e00\u4e2a\u968f\u673a\u6587\u4ef6<\/li>\n\n\n\n<li>\u4f7f\u7528<code>connet<\/code>\u5c06<code>socket<\/code>\u7684\u76ee\u6807\u53e5\u67c4\uff0c\u8fd9\u4e2a\u76ee\u6807\u662f\u5168\u5c40\u53d8\u91cf<code>CONFIG_CTRL_IFACE_DIR<\/code>\u4e2d\u5b58\u50a8\u4e0e\u4e3b\u8fdb\u7a0b\u901a\u4fe1\u4f7f\u7528\u7684\u53e5\u67c4\u7684\u8def\u5f84\uff0c\u4f20\u5165\u7aef\u53e3\u6bd4\u5982<code>wlan0<\/code>\uff0c\u7136\u540e\u5c06\u4e24\u8005\u8fdb\u884c\u62fc\u63a5<\/li>\n\n\n\n<li>\u76ee\u6807\u53e5\u67c4\u5728\u4e3b\u8fdb\u7a0b\u4e2d\u4e5f\u4f1a\u4f7f\u7528\uff0c\u533a\u522b\u662f\u4e3b\u8fdb\u7a0b\u662f\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u83b7\u53d6\u6587\u4ef6\u8def\u5f84<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.garfield-blog.top\/wp-content\/uploads\/2025\/12\/hostapd_cli_reconnect\u6d41\u7a0b-1024x1016.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1016\" data-original=\"https:\/\/www.garfield-blog.top\/wp-content\/uploads\/2025\/12\/hostapd_cli_reconnect\u6d41\u7a0b-1024x1016.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-383\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/div><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u5904\u7406\u7528\u6237\u547d\u4ee4<\/h3>\n\n\n\n<p><code>hostapd_cli<\/code>\u5185\u90e8\u7ef4\u62a4\u4e86\u4e00\u4e2a\u5168\u5c40\u7684\u7ed3\u6784\u4f53\u6570\u7ec4\uff0c\u5b58\u50a8\u652f\u6301\u7684\u547d\u4ee4\u548c\u5bf9\u5e94\u7684\u56de\u8c03\u51fd\u6570\u3002\u5728\u63a5\u6536\u5230\u547d\u4ee4\u540e\u4f1a\u9996\u5148\u5728\u6570\u7ec4\u4e2d\u627e\u5230\u5bf9\u5e94\u7684\u56de\u8c03\u7136\u540e\u8c03\u7528\uff0c\u6700\u540e\u4f7f\u7528<code>wpa_ctrl_command<\/code>\u63a5\u53e3\u6765\u53d1\u9001\u548c\u63a5\u6536\u6570\u636e<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.garfield-blog.top\/wp-content\/uploads\/2025\/12\/hostapd_cli\u547d\u4ee4\u5904\u7406-1024x342.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"342\" data-original=\"https:\/\/www.garfield-blog.top\/wp-content\/uploads\/2025\/12\/hostapd_cli\u547d\u4ee4\u5904\u7406-1024x342.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-384\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/div><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u53d1\u9001\u548c\u63a5\u6536\u6570\u636e<\/h3>\n\n\n\n<p>\u6570\u636e\u7684\u53d1\u9001\u548c\u63a5\u6536\u4f7f\u7528\u7684\u65f6\u4e4b\u524d\u521b\u5efa\u7684<code>socket<\/code>\u53e5\u67c4\uff0c\u53d1\u9001\u540e\u4f7f\u7528<code>select<\/code>\u76d1\u542c\u53e5\u67c4\uff0c\u5e76\u5bf9\u9700\u8981\u4e3b\u52a8\u5904\u7406\u7684\u4e8b\u4ef6\u8c03\u7528\u6ce8\u518c\u597d\u7684<code>hostapd_cli_msg_cb<\/code>\u8fdb\u884c\u5904\u7406<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.garfield-blog.top\/wp-content\/uploads\/2025\/12\/wpa_ctrl_command\u6d41\u7a0b-1024x796.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"796\" data-original=\"https:\/\/www.garfield-blog.top\/wp-content\/uploads\/2025\/12\/wpa_ctrl_command\u6d41\u7a0b-1024x796.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-385\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/div><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u6574\u4f53\u6d41\u7a0b<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.garfield-blog.top\/wp-content\/uploads\/2025\/12\/client\u7aef\u6574\u4f53\u6d41\u7a0b-4096x1863.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"4096\" height=\"1863\" data-original=\"https:\/\/www.garfield-blog.top\/wp-content\/uploads\/2025\/12\/client\u7aef\u6574\u4f53\u6d41\u7a0b-4096x1863.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-390\"  sizes=\"auto, (max-width: 4096px) 100vw, 4096px\" \/><\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8ff0 hostapd\u7684ctrl i\/f\uff08control interface\uff0c\u63a7\u5236\u63a5\u53e3\uff09\u6a21\u5757\u4e3b\u8981\u4f5c\u7528\u662f\u4e3a\u5916\u90e8\u7a0b\u5e8f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-382","post","type-post","status-publish","format-standard","hentry","category-source-code-analysis"],"_links":{"self":[{"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts\/382","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=382"}],"version-history":[{"count":3,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts\/382\/revisions"}],"predecessor-version":[{"id":441,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts\/382\/revisions\/441"}],"wp:attachment":[{"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=382"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=382"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=382"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}