aaaaaaaaaa 女爷i 2022-05-25 03:40 143阅读 0赞 json_object *parse_dhcp_list_2json(char* src_str,int index,json_object *rsp_dhcp_list_json){ char *delim=" "; char mac[64] = {0} ; char *p; char *q; int type; char *one ="1"; char *three ="3"; int online; char pingcomd[32]="ping -c 1 -W 1 "; //char pingcomdd[32] = ">/dev/null"; char src_str_cp[1024]={0}; json_object *rsp_json = NULL ; /*rsp_json = json_object_new_object(); if (rsp_json == NULL){ my_printf(LOG_MODE_LEVEL_1, "%s(%d) json_object_new_object return NULL.\n",__FUNCTION__,__LINE__); return FALSE; }*/ char output_ary[6][64]; int i=0; char client_mac[64]={0}; char client_ip[64]={0}; char client_host_name[64]={0}; char client_online[64]={0}; char client_connect_type[64]={0}; char client_online_tmp[64]={0}; char net_arp_file[64] = "/tmp/net_arp_flag_mac.tmp"; char cmd[256]; memset( &cmd, 0x00, sizeof(cmd)); if(separate_string_to_array( src_str, " ", 5, 64, (char *)&output_ary) != 5) { return -1; } strcpy(client_mac, output_ary[1]); //mac strcpy(client_ip, output_ary[2]); //ip strcpy(client_host_name, output_ary[3]);//name type=IsWifi(client_mac); // client_connect_type if(type) { strcpy(client_connect_type, three); strcpy(client_online, "online"); } else { strcpy(client_connect_type, one); strcpy(client_online, "offline"); } my_printf(LOG_MODE_LEVEL_1,"[Debug]clinet_mac:%s\n", client_mac); //has been upper in IsWifi function my_printf(LOG_MODE_LEVEL_1,"[Debug]clinet_ip:%s\n", client_ip); my_printf(LOG_MODE_LEVEL_1,"[Debug]clinet_host_name:%s\n", client_host_name); snprintf(cmd, sizeof(cmd), "awk '{print $3,$4=toupper($4),$1}' /proc/net/arp > %s", net_arp_file); my_printf(LOG_MODE_LEVEL_1, "[##lin##]%s(%d) cmd:%s\n",__FUNCTION__,__LINE__, cmd); //system("awk '{print $3,$4}' /proc/net/arp > /tmp/net_arp_flag_mac.tmp"); system(cmd); if(access(net_arp_file, F_OK) == -1) { my_printf(LOG_MODE_LEVEL_1, "%s(%d) File %s is NULL%s \n",__FUNCTION__,__LINE__,net_arp_file); } //grep "28:ed:6a:e9:ab:fb" /tmp/net_arp_flag_mac.tmp | cut -d '' -f 1 memset( &cmd, 0x00, sizeof(cmd)); snprintf(cmd, sizeof(cmd), "grep \"%s\" %s | cut -d ' ' -f 1", client_mac, net_arp_file); my_printf(LOG_MODE_LEVEL_1, "[##lin##]%s(%d) cmd:%s\n",__FUNCTION__,__LINE__, cmd); get_system_output(cmd, client_online_tmp, 64); my_printf(LOG_MODE_LEVEL_1, "[##lin##]%s(%d) client_online_tmp:%s\n",__FUNCTION__,__LINE__, client_online_tmp); //if(strcmp(client_online_tmp, "0x2") == 0) // 0x2 online 0x1 offline if(strcmp(client_online, "online") == 0) { //strcpy(client_online, 0); rsp_json = json_object_new_object(); if (rsp_json == NULL) { my_printf(LOG_MODE_LEVEL_1, "%s(%d) json_object_new_object return NULL.\n",__FUNCTION__,__LINE__); return FALSE; } my_printf(LOG_MODE_LEVEL_1, "[##lin##]%s(%d) **************atoi(client_online_tmp):%s\n",__FUNCTION__,__LINE__, client_online_tmp); json_object_object_add(rsp_json, "MAC", json_object_new_string(client_mac)); json_object_object_add(rsp_json, "IP", json_object_new_string(client_ip)); json_object_object_add(rsp_json, "Name", json_object_new_string(client_host_name)); json_object_object_add(rsp_json, "UserType", json_object_new_string(client_connect_type)); return rsp_json; } #if 0 strcpy(src_str_cp,src_str); my_printf(LOG_MODE_LEVEL_1, "[##lin##]%s(%d) src_str_cp:[%s]\n",__FUNCTION__,__LINE__,src_str_cp); //my_printf(LOG_MODE_LEVEL_1, "[##lin##]%s(%d) src_str:[%s]\n",__FUNCTION__,__LINE__,src_str); q = strtok(src_str_cp,delim); q = strtok(NULL,delim); q = strtok(NULL,delim); strcat(pingcomd,q); //strcat(pingcomd,pingcomdd); my_printf(LOG_MODE_LEVEL_1, "%s(%d) pingcomd is %s \n",__FUNCTION__,__LINE__,pingcomd); online = system(pingcomd); my_printf(LOG_MODE_LEVEL_1, "%s(%d) online is %d \n",__FUNCTION__,__LINE__,online); //online=0; if(online == 0) { rsp_json = json_object_new_object(); if (rsp_json == NULL){ my_printf(LOG_MODE_LEVEL_1, "%s(%d) json_object_new_object return NULL.\n",__FUNCTION__,__LINE__); return FALSE; } p = strtok(src_str,delim); my_printf(LOG_MODE_LEVEL_1, "[##lin@@##]%s(%d) p:[%s]\n",__FUNCTION__,__LINE__,p); p=strtok(NULL,delim); type=IsWifi(p); my_printf(LOG_MODE_LEVEL_1, "[##lin@@##]%s(%d) type:[%d]\n",__FUNCTION__,__LINE__,type); json_object_object_add(rsp_json, "MAC", json_object_new_string(p)); p=strtok(NULL,delim); my_printf(LOG_MODE_LEVEL_1, "[##lin##]%s(%d) p:[%s]\n",__FUNCTION__,__LINE__,p); if(p == NULL){ my_printf(LOG_MODE_LEVEL_1, "%s(%d) strtok return NULL, delim:[%s]\n",__FUNCTION__,__LINE__,delim); return FALSE; } json_object_object_add(rsp_json, "IP", json_object_new_string(p)); my_printf(LOG_MODE_LEVEL_1, "[##lin##]%s(%d) p:[%s]\n",__FUNCTION__,__LINE__,p); p=strtok(NULL,delim); if(p == NULL){ my_printf(LOG_MODE_LEVEL_1, "%s(%d) strtok return NULL, delim:[%s]\n",__FUNCTION__,__LINE__,delim); return FALSE; } json_object_object_add(rsp_json, "Name", json_object_new_string(p)); my_printf(LOG_MODE_LEVEL_1, "[##lin##]%s(%d) p:[%s]\n",__FUNCTION__,__LINE__,p); if(type){ json_object_object_add(rsp_json, "UserType", json_object_new_string(three)); } else{ json_object_object_add(rsp_json, "UserType", json_object_new_string(one)); } return rsp_json; } #endif // json_object_object_del(rsp_json," "); // return rsp_json; return FALSE; }
相关 aaaaaaaaaa json_object parse_dhcp_list_2json(char src_str,int index,json_object rsp_dhcp_list_j 女爷i/ 2022年05月25日 03:40/ 0 赞/ 144 阅读
还没有评论,来说两句吧...