Преглед изворни кода

Z991239-4875 #comment feat: 修改uos网卡信息接口

陈纪林80310970 пре 2 година
родитељ
комит
12d67a0d5e
1 измењених фајлова са 57 додато и 4 уклоњено
  1. 57 4
      Module/mod_accessauth/AccessAuthFSM.cpp

+ 57 - 4
Module/mod_accessauth/AccessAuthFSM.cpp

@@ -1731,15 +1731,68 @@ void CAccessAuthFSM::GetNetMsg(SpReqAnsContext<AccessAuthService_GetNetMsg_Req,
         ctx->Ans.netStatus = 0; //失败
     }
 #else
-    if (DetectNetworkLegality(tmp))
+    ErrorCodeEnum ec = Error_Succeed;
+    int netType = 0; //默认未知
+
+    CSimpleStringA tmpVendor(""), tmpDevSN(""), tmpDLLVersion("");
+    GetEntityBase()->GetFunction()->GetSysVar("FWBVendor", tmpVendor);
+    GetEntityBase()->GetFunction()->GetSysVar("FWBDevSN", tmpDevSN);
+    GetEntityBase()->GetFunction()->GetSysVar("FWBVersion", tmpDLLVersion);
+
+
+    if (tmpDLLVersion.GetLength() < 2)
+        tmpDLLVersion = "8.1";
+    if (tmpDevSN.GetLength() > 12 && tmpDevSN.IndexOf("FWB") > 2)
     {
-        ctx->Ans.netStatus = 1; //成功
+        Dbg("This is fwb device.");
     }
     else
     {
-        ctx->Ans.netStatus = 0; //失败
+        int i = 0;
+        int sockfd;
+        struct ifconf ifconf;
+        struct ifreq* ifreq;
+        char buf[1024];
+
+        //初始化ifconf
+        ifconf.ifc_len = 1024;
+        ifconf.ifc_buf = buf;
+
+        if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
+        {
+            perror("socket error");
+            exit(1);
+        }
+
+        //获取所有接口信息
+        ioctl(sockfd, SIOCGIFCONF, &ifconf);
+
+        //逐个获取Ip地址
+        int size = ifconf.ifc_len / sizeof(struct ifreq);
+        ifreq = (struct ifreq*)buf;
+        string netName(ifreq->ifr_name);
+
+        if (size == 1 && netName == "lo") //只有逻辑地址 -- 网线被拔出
+        {
+            netType = 0;
+            tmp = "无网络";
+        }
+        else
+        {
+            for (i = size; i > 0; i--)
+            {
+                string netName(ifreq->ifr_name); //有其他网卡 -- 有线
+                if (netName != "lo")
+                {
+                    netType = 1;
+                    tmp = "网络已连接";
+                }
+                ifreq++;
+            }
+        }
+
+        ctx->Ans.netStatus = netType;
     }
-    Dbg("网络信息:%s.", tmp.GetData());
     ctx->Ans.netMsg = tmp;
 #endif // RVC_OS_WIN
     ctx->Answer(Error_Succeed);