Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Rearrange tls-related function calls and add explicit set_hostname() #44

Merged
merged 2 commits into from
Jan 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,28 @@ int main(void)
return result;
}

TLSSocket *socket = new TLSSocket;
result = socket->set_root_ca_cert(cert);
printf("Connecting to ifconfig.io\n");
SocketAddress addr;
result = net->gethostbyname("ifconfig.io", &addr);
if (result != NSAPI_ERROR_OK) {
printf("Error: socket->set_root_ca_cert() returned %d\n", result);
return result;
printf("Error! DNS resolution for ifconfig.io failed with %d\n", result);
}
addr.set_port(443);

TLSSocket *socket = new TLSSocket;
result = socket->open(net);
if (result != NSAPI_ERROR_OK) {
printf("Error! socket->open() returned: %d\n", result);
return result;
}

printf("Connecting to ifconfig.io\n");
SocketAddress addr;
result = net->gethostbyname("ifconfig.io", &addr);
socket->set_hostname("ifconfig.io");

result = socket->set_root_ca_cert(cert);
if (result != NSAPI_ERROR_OK) {
printf("Error! DNS resolution for ifconfig.io failed with %d\n", result);
printf("Error: socket->set_root_ca_cert() returned %d\n", result);
return result;
}
addr.set_port(443);

result = socket->connect(addr);
if (result != NSAPI_ERROR_OK) {
Expand Down