遇到过这样一个问题,手机作为热点,用笔记本去连接 始终处于分配IP阶段,而其它大多数机器又是可以的。
最后调查发现是authoritative缺失,导致客户端长时间等待dhcp分配ip超时。
authoritative;
指定当一个客户端试图获得一个不是该DHCP服务器分配的IP信息,DHCP将发送一个拒绝消息,而不会等待请求超时。当请求被拒绝,客户端会重新向当前DHCP发送IP请求获得新地址。
当网络中有其他的DHCP服务器时,加上此参数可以忽略其他DHCP服务器。
可把此参数加在dhcp.conf配置文件的第一行。
android手机热点代码层修改:
diff --git a/TetherController.cpp b/TetherController.cpp
index 743742c..32a0b43 100644
--- a/ TetherController.cpp
+++ b/ TetherController.cpp
@@ -96,6 +96,8 @@ bool TetherController::getIpFwdEnabled() {
return (enabled == '1' ? true : false);
}
+#define TETHER_START_CONST_ARG 8
+
int TetherController::startTethering(int num_addrs, struct in_addr* addrs) {
if (mDaemonPid != 0) {
ALOGE("Tethering already started");
@@ -134,19 +136,20 @@ int TetherController::startTethering(int num_addrs, struct in_addr* addrs) {
close(pipefd[0]);
}
- int num_processed_args = 7 + (num_addrs/2) + 1; // 1 null for termination
+ int num_processed_args = TETHER_START_CONST_ARG + (num_addrs/2) + 1;
char **args = (char **)malloc(sizeof(char *) * num_processed_args);
args[num_processed_args - 1] = NULL;
args[0] = (char *)"/system/bin/dnsmasq";
args[1] = (char *)"--keep-in-foreground";
args[2] = (char *)"--no-resolv";
args[3] = (char *)"--no-poll";
+ args[4] = (char *)"--dhcp-authoritative";
// TODO: pipe through metered status from ConnService
- args[4] = (char *)"--dhcp-option-force=43,ANDROID_METERED";
- args[5] = (char *)"--pid-file";
- args[6] = (char *)"";
+ args[5] = (char *)"--dhcp-option-force=43,ANDROID_METERED";
+ args[6] = (char *)"--pid-file";
+ args[7] = (char *)"";
- int nextArg = 7;
+ int nextArg = TETHER_START_CONST_ARG;
for (int addrIndex=0; addrIndex < num_addrs;) {
char *start = strdup(inet_ntoa(addrs[addrIndex++]));
char *end = strdup(inet_ntoa(addrs[addrIndex++]));