Commit 7212b204 authored by Kishen Maloor's avatar Kishen Maloor

Merge branch 'origin/gaborone' into gaborone+

Signed-off-by: Kishen Maloor's avatarKishen Maloor <kishen.maloor@intel.com>
parents 886392f8 4cf5b083
Pipeline #692 failed with stage
in 7 minutes and 34 seconds
......@@ -2,6 +2,8 @@
image: gcc
Linux_Secured_Test:
variables:
GIT_SUBMODULE_STRATEGY: normal
stage: build
before_script:
- apt update && apt -y install make autoconf
......@@ -13,6 +15,8 @@ Linux_Secured_Test:
- make DYNAMIC=1 IPV4=1 TCP=1 SECURE=1 test
Linux_Unsecured_Test:
variables:
GIT_SUBMODULE_STRATEGY: normal
stage: build
before_script:
- apt update && apt -y install make autoconf
......@@ -24,29 +28,33 @@ Linux_Unsecured_Test:
- make DYNAMIC=1 IPV4=1 TCP=1 SECURE=0 test
Android_build:
stage: build
image: openjdk:8-jdk
before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1 make autoconf swig patch
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
- unzip -d android-sdk-linux android-sdk.zip
- echo y | android-sdk-linux/tools/bin/sdkmanager "ndk-bundle" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "platforms;android-28" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "build-tools;28.0.2" >/dev/null
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
# temporarily disable checking for EPIPE error and use yes to accept all licenses
- set +o pipefail
- yes | android-sdk-linux/tools/bin/sdkmanager --licenses
- set -o pipefail
- ./android-sdk-linux/ndk-bundle/build/tools/make_standalone_toolchain.py --arch arm --api 23 --install-dir ~/android-arm-23
script:
- cd port/android
- make DYNAMIC=1 TCP=1 IPV4=1 SECURE=1 PKI=1 CLOUD=1 JAVA=1 DEBUG=0
variables:
GIT_SUBMODULE_STRATEGY: normal
stage: build
image: openjdk:8-jdk
before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1 make autoconf swig patch
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
- unzip -d android-sdk-linux android-sdk.zip
- echo y | android-sdk-linux/tools/bin/sdkmanager "ndk-bundle" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "platforms;android-28" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "build-tools;28.0.2" >/dev/null
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
# temporarily disable checking for EPIPE error and use yes to accept all licenses
- set +o pipefail
- yes | android-sdk-linux/tools/bin/sdkmanager --licenses
- set -o pipefail
- ./android-sdk-linux/ndk-bundle/build/tools/make_standalone_toolchain.py --arch arm --api 23 --install-dir ~/android-arm-23
script:
- cd port/android
- make DYNAMIC=1 TCP=1 IPV4=1 SECURE=1 PKI=1 CLOUD=1 JAVA=1 DEBUG=0
whitespace_and_doxygen:
variables:
GIT_SUBMODULE_STRATEGY: none
stage: build
before_script:
- apt update && apt -y install make autoconf doxygen clang-format
......
......@@ -70,12 +70,16 @@ free_api_param(cloud_api_param_t *p)
int
conv_cloud_endpoint(oc_cloud_context_t *ctx)
{
int ret = 0;
oc_endpoint_t ep;
memset(&ep, 0, sizeof(oc_endpoint_t));
if (memcmp(&ep, ctx->cloud_ep, sizeof(oc_endpoint_t)) == 0) {
return oc_string_to_endpoint(&ctx->store.ci_server, ctx->cloud_ep, NULL);
ret = oc_string_to_endpoint(&ctx->store.ci_server, ctx->cloud_ep, NULL);
#ifdef OC_DNS_CACHE
oc_dns_clear_cache();
#endif /* OC_DNS_CACHE */
}
return 0;
return ret;
}
int
......@@ -318,6 +322,25 @@ oc_cloud_refresh_token(oc_cloud_context_t *ctx, oc_cloud_cb_t cb, void *data)
return -1;
}
int
oc_cloud_discover_resources(oc_cloud_context_t *ctx,
oc_discovery_all_handler_t handler, void *user_data)
{
if (!ctx) {
return -1;
}
if (!(ctx->store.status & OC_CLOUD_LOGGED_IN)) {
return -1;
}
if (oc_do_ip_discovery_all_at_endpoint(handler, ctx->cloud_ep, user_data)) {
return 0;
}
return -1;
}
/* Internal APIs for accessing the OCF Cloud */
bool
cloud_access_register(oc_endpoint_t *endpoint, const char *auth_provider,
......
......@@ -777,33 +777,12 @@ oc_ri_process_discovery_payload(uint8_t *payload, int len,
rep = rep->next;
}
oc_rep_t *link = links->value.object;
while (link != NULL) {
switch (link->type) {
case OC_REP_STRING: {
if (oc_string_len(link->name) == 6 &&
memcmp(oc_string(link->name), "anchor", 6) == 0) {
anchor = &link->value.string;
}
} break;
default:
break;
}
if (anchor) {
break;
}
link = link->next;
}
oc_uuid_t di;
oc_str_to_uuid(oc_string(*anchor) + 6, &di);
while (links != NULL) {
/* Reset bm in every round as this can be omitted if 0. */
oc_uuid_t di;
oc_resource_properties_t bm = 0;
oc_endpoint_t *eps_list = NULL;
link = links->value.object;
oc_rep_t *link = links->value.object;
while (link != NULL) {
switch (link->type) {
......@@ -811,6 +790,7 @@ oc_ri_process_discovery_payload(uint8_t *payload, int len,
if (oc_string_len(link->name) == 6 &&
memcmp(oc_string(link->name), "anchor", 6) == 0) {
anchor = &link->value.string;
oc_str_to_uuid(oc_string(*anchor) + 6, &di);
} else if (oc_string_len(link->name) == 4 &&
memcmp(oc_string(link->name), "href", 4) == 0) {
uri = &link->value.string;
......@@ -844,8 +824,9 @@ oc_ri_process_discovery_payload(uint8_t *payload, int len,
memcmp(oc_string(ep->name), "ep", 2) == 0) {
if (oc_string_to_endpoint(&ep->value.string, &temp_ep, NULL) ==
0) {
if (((endpoint->flags & IPV4) && (temp_ep.flags & IPV6)) ||
((endpoint->flags & IPV6) && (temp_ep.flags & IPV4))) {
if (!(temp_ep.flags & TCP) &&
(((endpoint->flags & IPV4) && (temp_ep.flags & IPV6)) ||
((endpoint->flags & IPV6) && (temp_ep.flags & IPV4)))) {
goto next_ep;
}
if (eps_cur) {
......@@ -912,6 +893,9 @@ oc_ri_process_discovery_payload(uint8_t *payload, int len,
done:
oc_free_rep(p);
#ifdef OC_DNS_CACHE
oc_dns_clear_cache();
#endif /* OC_DNS_CACHE */
return ret;
}
#endif /* OC_CLIENT */
......@@ -15,6 +15,7 @@
*/
#include "oc_api.h"
#include "oc_core_res.h"
#include "port/oc_clock.h"
#include "oc_pki.h"
#include "oc_introspection.h"
......@@ -425,7 +426,7 @@ read_pem(const char *file_path, char *buffer, size_t *buffer_len)
fclose(fp);
return -1;
}
if (pem_len > (long)*buffer_len) {
if (pem_len >= (long)*buffer_len) {
PRINT("ERROR: buffer provided too small\n");
fclose(fp);
return -1;
......@@ -441,6 +442,7 @@ read_pem(const char *file_path, char *buffer, size_t *buffer_len)
return -1;
}
fclose(fp);
buffer[pem_len] = '\0';
*buffer_len = (size_t)pem_len;
return 0;
}
......@@ -505,6 +507,15 @@ factory_presets_cb(size_t device, void *data)
#endif /* OC_SECURITY && OC_PKI */
}
void
display_device_uuid(void)
{
char buffer[OC_UUID_LEN];
oc_uuid_to_str(oc_core_get_device_id(0), buffer, sizeof(buffer));
PRINT("Started device with ID: %s\n", buffer);
}
int
main(void)
{
......@@ -527,7 +538,7 @@ main(void)
#ifdef OC_SECURITY
oc_set_random_pin_callback(random_pin_cb, NULL);
#endif
oc_set_max_app_data_size(32768);
init = oc_main_init(&handler);
if (init < 0)
return init;
......@@ -536,6 +547,8 @@ main(void)
return -1;
}
display_device_uuid();
int c;
while (quit != 1) {
display_menu();
......
This diff is collapsed.
......@@ -18,6 +18,7 @@
****************************************************************************/
#include "oc_api.h"
#include "oc_pki.h"
#include <signal.h>
#include <inttypes.h>
......@@ -142,6 +143,17 @@ static const char *device_name = "Cloud Device";
static const char *manufacturer = "ocfcloud.com";
#ifdef OC_SECURITY
static const char *cis;
static const char *auth_code;
static const char *sid;
static const char *apn;
#else /* OC_SECURITY */
static const char *cis = "coap+tcp://127.0.0.1:5683";
static const char *auth_code = "test";
static const char *sid = "00000000-0000-0000-0000-000000000001";
static const char *apn = "test";
#endif /* OC_SECURITY */
oc_resource_t *res1;
oc_resource_t *res2;
......@@ -284,9 +296,102 @@ register_resources(void)
oc_add_resource(res2);
}
#if defined(OC_SECURITY) && defined(OC_PKI)
static int
read_pem(const char *file_path, char *buffer, size_t *buffer_len)
{
FILE *fp = fopen(file_path, "r");
if (fp == NULL) {
PRINT("ERROR: unable to read PEM\n");
return -1;
}
if (fseek(fp, 0, SEEK_END) != 0) {
PRINT("ERROR: unable to read PEM\n");
fclose(fp);
return -1;
}
long pem_len = ftell(fp);
if (pem_len < 0) {
PRINT("ERROR: could not obtain length of file\n");
fclose(fp);
return -1;
}
if (pem_len > (long)*buffer_len) {
PRINT("ERROR: buffer provided too small\n");
fclose(fp);
return -1;
}
if (fseek(fp, 0, SEEK_SET) != 0) {
PRINT("ERROR: unable to read PEM\n");
fclose(fp);
return -1;
}
if (fread(buffer, 1, pem_len, fp) < (size_t)pem_len) {
PRINT("ERROR: unable to read PEM\n");
fclose(fp);
return -1;
}
fclose(fp);
buffer[pem_len] = '\0';
*buffer_len = (size_t)pem_len;
return 0;
}
#endif /* OC_SECURITY && OC_PKI */
void
factory_presets_cb(size_t device, void *data)
{
(void)device;
(void)data;
#if defined(OC_SECURITY) && defined(OC_PKI)
unsigned char cloud_ca[4096];
size_t cert_len = 4096;
if (read_pem("pki_certs/cloudca.pem", (char *)cloud_ca, &cert_len) < 0) {
PRINT("ERROR: unable to read certificates\n");
return;
}
int rootca_credid =
oc_pki_add_trust_anchor(0, (const unsigned char *)cloud_ca, cert_len);
if (rootca_credid < 0) {
PRINT("ERROR installing root cert\n");
return;
}
#endif /* OC_SECURITY && OC_PKI */
}
int
main(void)
main(int argc, char *argv[])
{
PRINT("Default parameters: device_name: %s, auth_code: %s, cis: %s, sid: %s, "
"apn: %s\n",
device_name, auth_code, cis, sid, apn);
if (argc == 1) {
PRINT("./cloud_client <device-name-without-spaces> <auth-code> <cis> <sid> "
"<apn>\n"
"Using the default values\n");
}
if (argc > 1) {
device_name = argv[1];
PRINT("device_name: %s\n", argv[1]);
}
if (argc > 2) {
auth_code = argv[2];
PRINT("auth_code: %s\n", argv[2]);
}
if (argc > 3) {
cis = argv[3];
PRINT("cis : %s\n", argv[3]);
}
if (argc > 4) {
sid = argv[4];
PRINT("sid: %s\n", argv[4]);
}
if (argc > 5) {
apn = argv[5];
PRINT("apn: %s\n", argv[5]);
}
int ret = init();
if (ret < 0) {
return ret;
......@@ -299,6 +404,7 @@ main(void)
#ifdef OC_STORAGE
oc_storage_config("./cloud_server_creds/");
#endif /* OC_STORAGE */
oc_set_factory_presets_cb(factory_presets_cb, NULL);
ret = oc_main_init(&handler);
if (ret < 0)
......@@ -307,6 +413,9 @@ main(void)
oc_cloud_context_t *ctx = oc_cloud_get_context(0);
if (ctx) {
oc_cloud_manager_start(ctx, cloud_status_handler, NULL);
if (cis) {
oc_cloud_provision_conf_resource(ctx, cis, auth_code, sid, apn);
}
}
run();
......
-----BEGIN CERTIFICATE-----
MIIBhDCCASmgAwIBAgIQdAMxveYP9Nb48xe9kRm3ajAKBggqhkjOPQQDAjAxMS8w
LQYDVQQDEyZPQ0YgQ2xvdWQgUHJpdmF0ZSBDZXJ0aWZpY2F0ZXMgUm9vdCBDQTAe
Fw0xOTExMDYxMjAzNTJaFw0yOTExMDMxMjAzNTJaMDExLzAtBgNVBAMTJk9DRiBD
bG91ZCBQcml2YXRlIENlcnRpZmljYXRlcyBSb290IENBMFkwEwYHKoZIzj0CAQYI
KoZIzj0DAQcDQgAEaNJi86t5QlZiLcJ7uRMNlcwIpmFiJf9MOqyz2GGnGVBypU6H
lwZHY2/l5juO/O4EH2s9h3HfcR+nUG2/tFzFEaMjMCEwDgYDVR0PAQH/BAQDAgEG
MA8GA1UdEwEB/wQFMAM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AC
AjBhBgorBgEEAYORVgEABFMwUTAJAgECAgEAAgEAMDYMGTEuMy42LjEuNC4xLjUx
NDE0LjAuMC4xLjAMGTEuMy42LjEuNC4xLjUxNDE0LjAuMC4yLjAMBUxpdGUxDAVM
aXRlMTAqBgorBgEEAYORVgEBBBwwGgYLKwYBBAGDkVYBAQAGCysGAQQBg5FWAQEB
MDAGCisGAQQBg5FWAQIEIjAgDA4xLjMuNi4xLjQuMS43MQwJRGlzY292ZXJ5DAMx
LjAwCgYIKoZIzj0EAwIDSAAwRQIgedG7zHeLh9YzM0bU3DQBnKDRIFnJHiDayyuE
8pVfJOQCIQCo/llZOZD87IHzsyxEfXm/QhkTNA5WJOa7sjF2ngQ1/g==
-----END CERTIFICATE-----
......@@ -2,7 +2,7 @@
BggqhkjOPQMBBw==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEII8kjV/guIOeu+1e6GKjDOeIzHAgmA4MCBXIMy10uAlqoAoGCCqGSM49
AwEHoUQDQgAEBYJtQKn3zZi/tkIwqTZXDnaGEBnOxjnpUi0ATT5Dc/HY7V243o7D
hM6p5MQl89ebUccBuA6JK3Fx1MNJitbrjw==
MHcCAQEEIBF8S8rq+h8EnykDcCpAyvMam+u3D9i/5oYF5owt/+SnoAoGCCqGSM49
AwEHoUQDQgAEWR9C5zBIOQUeNcXLcEDD6DcGtBEVQdSfVllL3ayquBlZF/x8D1Br
1YiEqZiEtBjPMystiIx5vqzK3OKEk38l9A==
-----END EC PRIVATE KEY-----
......@@ -632,7 +632,7 @@ read_pem(const char *file_path, char *buffer, size_t *buffer_len)
fclose(fp);
return -1;
}
if (pem_len > (long)*buffer_len) {
if (pem_len >= (long)*buffer_len) {
PRINT("ERROR: buffer provided too small\n");
fclose(fp);
return -1;
......@@ -648,6 +648,7 @@ read_pem(const char *file_path, char *buffer, size_t *buffer_len)
return -1;
}
fclose(fp);
buffer[pem_len] = '\0';
*buffer_len = (size_t)pem_len;
return 0;
}
......@@ -686,7 +687,6 @@ factory_presets_cb(size_t device, void *data)
PRINT("ERROR: unable to read certificates\n");
return;
}
int subca_credid = oc_pki_add_mfg_intermediate_cert(
0, ee_credid, (const unsigned char *)cert, cert_len);
......
......@@ -211,7 +211,7 @@ read_pem(const char *file_path, char *buffer, size_t *buffer_len)
fclose(fp);
return -1;
}
if (pem_len > (long)*buffer_len) {
if (pem_len >= (long)*buffer_len) {
PRINT("ERROR: buffer provided too small\n");
fclose(fp);
return -1;
......@@ -227,6 +227,7 @@ read_pem(const char *file_path, char *buffer, size_t *buffer_len)
return -1;
}
fclose(fp);
buffer[pem_len] = '\0';
*buffer_len = (size_t)pem_len;
return 0;
}
......
......@@ -24,6 +24,7 @@
#define OC_CLOUD_H
#include "oc_ri.h"
#include "oc_client_state.h"
#include "oc_session_events.h"
#ifdef __cplusplus
......@@ -128,6 +129,9 @@ int oc_cloud_get_token_expiry(oc_cloud_context_t *ctx);
int oc_cloud_add_resource(oc_resource_t *resource);
void oc_cloud_delete_resource(oc_resource_t *resource);
int oc_cloud_publish_resources(size_t device);
int oc_cloud_discover_resources(oc_cloud_context_t *ctx,
oc_discovery_all_handler_t handler,
void *user_data);
int oc_cloud_provision_conf_resource(oc_cloud_context_t *ctx,
const char *server,
......
......@@ -1543,6 +1543,7 @@ read_pem(const char *file_path, char *buffer, size_t *buffer_len)
return -1;
}
fclose(fp);
buffer[pem_len] = '\0';
*buffer_len = (size_t)pem_len;
return 0;
}
......
......@@ -26,7 +26,7 @@ typedef uint64_t oc_clock_time_t;
/* Add support for dns lookup to the endpoint */
#define OC_DNS_LOOKUP
#define OC_DNS_LOOKUP_IPV6
//#define OC_DNS_LOOKUP_IPV6
/* If we selected support for dynamic memory allocation */
#ifdef OC_DYNAMIC_ALLOCATION
......
......@@ -134,7 +134,7 @@ ifeq ($(CLOUD),1)
CFLAGS += -DOC_CLOUD
TCP=1
IPV4=1
SAMPLES += cloud_server cloud_tests
SAMPLES += cloud_client cloud_server cloud_tests
endif
OBT = onboarding_tool
......@@ -320,9 +320,9 @@ smart_lock: libiotivity-lite-client.a $(ROOT_DIR)/apps/smart_lock_linux.c
@mkdir -p $@_creds
${CC} -o $@ ../../apps/smart_lock_linux.c libiotivity-lite-client.a -DOC_CLIENT ${CFLAGS} ${LIBS}
client_certification_tests: libiotivity-lite-client.a $(ROOT_DIR)/apps/client_certification_tests.c copy_idd_files
client_certification_tests: libiotivity-lite-client-server.a $(ROOT_DIR)/apps/client_certification_tests.c copy_idd_files
@mkdir -p $@_creds
${CC} -o $@ ../../apps/client_certification_tests.c libiotivity-lite-client.a -DOC_CLIENT ${CFLAGS} ${LIBS}
${CC} -o $@ ../../apps/client_certification_tests.c libiotivity-lite-client-server.a -DOC_CLIENT -DOC_SERVER ${CFLAGS} ${LIBS}
temp_sensor: libiotivity-lite-client.a $(ROOT_DIR)/apps/temp_sensor_client_linux.c
@mkdir -p $@_creds
......@@ -374,10 +374,14 @@ multi_device_client: libiotivity-lite-client.a $(ROOT_DIR)/apps/multi_device_cli
@mkdir -p $@_creds
${CC} -o $@ ../../apps/multi_device_client_linux.c libiotivity-lite-client.a -DOC_CLIENT ${CFLAGS} ${LIBS}
cloud_server: libiotivity-lite-client-server.a $(ROOT_DIR)/apps/cloud_server.c
cloud_server: libiotivity-lite-client-server.a $(ROOT_DIR)/apps/cloud_server.c copy_pki_certs
@mkdir -p $@_creds
${CC} -o $@ ../../apps/cloud_server.c libiotivity-lite-client-server.a -DOC_CLIENT -DOC_SERVER ${CFLAGS} ${CFLAGS_CLOUD} ${LIBS}
cloud_client: libiotivity-lite-client-server.a $(ROOT_DIR)/apps/cloud_client.c copy_pki_certs
@mkdir -p $@_creds
${CC} -o $@ ../../apps/cloud_client.c libiotivity-lite-client-server.a -DOC_CLIENT -DOC_SERVER ${CFLAGS} ${CFLAGS_CLOUD} ${LIBS}
cloud_tests: libiotivity-lite-client-server.a $(ROOT_DIR)/apps/cloud_certification_tests.c
@mkdir -p $@_creds
${CC} -o $@ ../../apps/cloud_certification_tests.c libiotivity-lite-client-server.a -DOC_CLIENT -DOC_SERVER ${CFLAGS} ${CFLAGS_CLOUD} ${LIBS}
......
......@@ -1660,6 +1660,59 @@ oc_connectivity_end_session(oc_endpoint_t *endpoint)
#endif /* OC_TCP */
#ifdef OC_DNS_LOOKUP
#ifdef OC_DNS_CACHE
typedef struct oc_dns_cache_t
{
struct oc_dns_cache_t *next;
oc_string_t domain;
union dev_addr addr;
} oc_dns_cache_t;
OC_MEMB(dns_s, oc_dns_cache_t, 1);
OC_LIST(dns_cache);
static oc_dns_cache_t *
oc_dns_lookup_cache(const char *domain)
{
if (oc_list_length(dns_cache) == 0) {
return NULL;
}
oc_dns_cache_t *c = (oc_dns_cache_t *)oc_list_head(dns_cache);
while (c) {
if (strlen(domain) == oc_string_len(c->domain) &&
memcmp(domain, oc_string(c->domain), oc_string_len(c->domain)) == 0) {
return c;
}
c = c->next;
}
return NULL;
}
static int
oc_dns_cache_domain(const char *domain, union dev_addr *addr)
{
oc_dns_cache_t *c = (oc_dns_cache_t *)oc_memb_alloc(&dns_s);
if (c) {
oc_new_string(&c->domain, domain, strlen(domain));
memcpy(&c->addr, addr, sizeof(union dev_addr));
oc_list_add(dns_cache, c);
return 0;
}
return -1;
}
void
oc_dns_clear_cache(void)
{
oc_dns_cache_t *c = (oc_dns_cache_t *)oc_list_pop(dns_cache);
while (c) {
oc_free_string(&c->domain);
oc_memb_free(&dns_s, c);
c = (oc_dns_cache_t *)oc_list_pop(dns_cache);
}
}
#endif /* OC_DNS_CACHE */
int
oc_dns_lookup(const char *domain, oc_string_t *addr, enum transport_flags flags)
{
......@@ -1667,20 +1720,55 @@ oc_dns_lookup(const char *domain, oc_string_t *addr, enum transport_flags flags)
OC_ERR("Error of input parameters");
return -1;
}
struct addrinfo hints, *result = NULL;
memset(&hints, 0, sizeof(hints));
hints.ai_family = (flags & IPV6) ? AF_INET6 : AF_INET;
hints.ai_socktype = (flags & TCP) ? SOCK_STREAM : SOCK_DGRAM;
int ret = getaddrinfo(domain, NULL, &hints, &result);
int ret = -1;
union dev_addr a;
#ifdef OC_DNS_CACHE
oc_dns_cache_t *c = oc_dns_lookup_cache(domain);
if (!c) {
#endif /* OC_DNS_CACHE */
memset(&a, 0, sizeof(union dev_addr));
struct addrinfo hints, *result = NULL;
memset(&hints, 0, sizeof(hints));
hints.ai_family = (flags & IPV6) ? AF_INET6 : AF_INET;
hints.ai_socktype = (flags & TCP) ? SOCK_STREAM : SOCK_DGRAM;
ret = getaddrinfo(domain, NULL, &hints, &result);
if (ret == 0) {
if (flags & IPV6) {
struct sockaddr_in6 *r = (struct sockaddr_in6 *)result->ai_addr;
memcpy(a.ipv6.address, r->sin6_addr.s6_addr,
sizeof(r->sin6_addr.s6_addr));
a.ipv6.port = ntohs(r->sin6_port);
a.ipv6.scope = r->sin6_scope_id;
}
#ifdef OC_IPV4
else {
struct sockaddr_in *r = (struct sockaddr_in *)result->ai_addr;
memcpy(a.ipv4.address, &r->sin_addr.s_addr, sizeof(r->sin_addr.s_addr));
a.ipv4.port = ntohs(r->sin_port);
}
#endif /* OC_IPV4 */
#ifdef OC_DNS_CACHE
oc_dns_cache_domain(domain, &a);
#endif /* OC_DNS_CACHE */
}
freeaddrinfo(result);
#ifdef OC_DNS_CACHE
} else {
ret = 0;
memcpy(&a, &c->addr, sizeof(union dev_addr));
}
#endif /* OC_DNS_CACHE */
if (ret == 0) {
char address[INET6_ADDRSTRLEN + 2] = { 0 };
const char *dest = NULL;
if (flags & IPV6) {
struct sockaddr_in6 *s_addr = (struct sockaddr_in6 *)result->ai_addr;
address[0] = '[';
dest = inet_ntop(AF_INET6, (void *)&s_addr->sin6_addr, address + 1,
dest = inet_ntop(AF_INET6, (void *)