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

Commit b9bd18c

Browse files
Replace string-based APIs with SocketAddress-based ones
1 parent 4b6d7c4 commit b9bd18c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

main.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,27 +53,34 @@ int main(void)
5353

5454
printf("Connecting to network\n");
5555
result = net->connect();
56-
if (result != 0) {
56+
if (result != NSAPI_ERROR_OK) {
5757
printf("Error! net->connect() returned: %d\n", result);
5858
return result;
5959
}
6060

6161
TLSSocket *socket = new TLSSocket;
6262
result = socket->set_root_ca_cert(cert);
63-
if (result != 0) {
63+
if (result != NSAPI_ERROR_OK) {
6464
printf("Error: socket->set_root_ca_cert() returned %d\n", result);
6565
return result;
6666
}
6767

6868
result = socket->open(net);
69-
if (result != 0) {
69+
if (result != NSAPI_ERROR_OK) {
7070
printf("Error! socket->open() returned: %d\n", result);
7171
return result;
7272
}
7373

7474
printf("Connecting to ifconfig.io\n");
75-
result = socket->connect("ifconfig.io", 443);
76-
if (result != 0) {
75+
SocketAddress addr;
76+
result = net->gethostbyname("ifconfig.io", &addr);
77+
if (result != NSAPI_ERROR_OK) {
78+
printf("Error! DNS resolution for ifconfig.io failed with %d\n", result);
79+
}
80+
addr.set_port(443);
81+
82+
result = socket->connect(addr);
83+
if (result != NSAPI_ERROR_OK) {
7784
printf("Error! socket->connect() returned: %d\n", result);
7885
goto DISCONNECT;
7986
}

0 commit comments

Comments
 (0)