void GetNetworkInfo() { CAEndpoint_t *tempInfo = NULL; uint32_t tempSize = 0; CAResult_t res = CAGetNetworkInformation(&tempInfo, &tempSize); if (CA_STATUS_OK != res || NULL == tempInfo || 0 >= tempSize) { Serial.println("Network not connected"); free(tempInfo); return; } Serial.println("========="); Serial.print("Network info total size is "); Serial.println(tempSize); int index; for (index = 0; index < tempSize; index++) { Serial.print("Type: "); Serial.println(tempInfo[index].adapter); if (CA_ADAPTER_IP == tempInfo[index].adapter) { Serial.print("Address: "); Serial.println(tempInfo[index].addr); Serial.print("Port: "); Serial.println(tempInfo[index].port); } } free(tempInfo); Serial.println("======="); }
std::string SceneUtils::getNetAddress() { CAEndpoint_t ** netInfo = (CAEndpoint_t **)OICMalloc(sizeof(CAEndpoint_t*)*5); if(netInfo == nullptr) { throw RCSException("memory allocation fail"); } uint32_t size = 0; CAGetNetworkInformation(netInfo, &size); if (size == 0) { OICFree(netInfo); throw RCSException("Disabled Network"); } for (uint32_t i = 0; i < size; ++i) { if (netInfo[i]->adapter == CATransportAdapter_t::CA_ADAPTER_IP) { std::string retAddress = std::string(netInfo[i]->addr) + ":" + std::to_string(netInfo[i]->port); OICFree(netInfo); return retAddress; } } OICFree(netInfo); throw RCSException("Not supported Network"); }
// CAGetNetworkInformation TC TEST_F (CATests, GetNetworkInformationTest) { uint32_t tempSize = 0; CAEndpoint_t *tempInfo = NULL; EXPECT_EQ(CA_STATUS_OK, CASelectNetwork(CA_ADAPTER_IP)); EXPECT_EQ(CA_STATUS_OK, CAGetNetworkInformation(&tempInfo, &tempSize)); free(tempInfo); }
CAResult_t checkGetNetworkInfo() { CAEndpoint_t *tempInfo = NULL; uint32_t tempSize = 0; CAResult_t res = CAGetNetworkInformation(&tempInfo, &tempSize); free(tempInfo); if (CA_STATUS_OK == res || CA_ADAPTER_NOT_ENABLED == res || CA_NOT_SUPPORTED == res) { return CA_STATUS_OK; } else { return CA_STATUS_FAILED; } }
void get_network_info() { CAEndpoint_t *tempInfo = NULL; uint32_t tempSize = 0; CAResult_t res = CAGetNetworkInformation(&tempInfo, &tempSize); if (CA_STATUS_OK != res || NULL == tempInfo || 0 >= tempSize) { printf("Network not connected\n"); free(tempInfo); return; } printf("################## Network Information #######################\n"); printf("Network info total size is %d\n\n", tempSize); int index; for (index = 0; index < tempSize; index++) { printf("Type: %d\n", tempInfo[index].adapter); if (CA_ADAPTER_IP == tempInfo[index].adapter) { printf("Address: %s\n", tempInfo[index].addr); printf("Port: %d\n", tempInfo[index].port); } else { printf("Address: %s\n", tempInfo[index].addr); } printf("Secured: %s\n\n", (tempInfo[index].flags & CA_SECURE) ? "true" : "false"); if (tempInfo[index].flags & CA_SECURE) { g_local_secure_port = tempInfo[index].port; printf("Secured: in global %d\n\n", g_local_secure_port); } } free(tempInfo); printf("##############################################################"); }
JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMGetNetworkInfomation(JNIEnv *env, jobject obj) { LOGI("RMGetNetworkInfomation"); if (!env || !obj) { LOGI("Invalid input parameter"); return; } CAEndpoint_t *tempInfo = NULL; uint32_t tempSize = 0; CAResult_t res = CAGetNetworkInformation(&tempInfo, &tempSize); if (CA_STATUS_OK != res) { LOGE("Could not start get network information"); free(tempInfo); return; } LOGI("################## Network Information #######################"); callback("######## Network Information", "#######"); LOGI("Network info total size is %d", tempSize); uint32_t index; for (index = 0; index < tempSize; index++) { res = get_remote_address(tempInfo[index].addr); if (CA_STATUS_OK != res) { free(tempInfo); return; } if (NULL != g_responseListenerObject) { char networkInfo[NETWORK_INFO_LENGTH]; LOGI("Type: %d", tempInfo[index].adapter); sprintf(networkInfo, "%d",tempInfo[index].adapter); callback("Type :", networkInfo); if (CA_ADAPTER_IP == tempInfo[index].adapter) { LOGI("Port: %d", tempInfo[index].port); sprintf(networkInfo, "%d",tempInfo[index].port); callback("Port: ", networkInfo); } LOGI("Secured: %d", (tempInfo[index].flags & CA_SECURE)); LOGI("Address: %s", g_remoteAddress); callback("Address: ", g_remoteAddress); free(g_remoteAddress); } if (tempInfo[index].flags & CA_SECURE) { g_localSecurePort = tempInfo[index].port; } } // free free(tempInfo); LOGI("##############################################################"); }