Skip to content

Commit dd21246

Browse files
author
Antti Kauppila
authored
Merge pull request #39 from michalpasztamobica/remove_deprecated_api
Replace string-based API with SocketAddress-based ones
2 parents 67136b8 + 1935ed4 commit dd21246

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

main.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,13 @@ int main()
9999
}
100100

101101
// Show the network address
102-
const char *ip = net->get_ip_address();
103-
const char *netmask = net->get_netmask();
104-
const char *gateway = net->get_gateway();
105-
printf("IP address: %s\n", ip ? ip : "None");
106-
printf("Netmask: %s\n", netmask ? netmask : "None");
107-
printf("Gateway: %s\n", gateway ? gateway : "None");
102+
SocketAddress a;
103+
net->get_ip_address(&a);
104+
printf("IP address: %s\n", a.get_ip_address() ? a.get_ip_address() : "None");
105+
net->get_netmask(&a);
106+
printf("Netmask: %s\n", a.get_ip_address() ? a.get_ip_address() : "None");
107+
net->get_gateway(&a);
108+
printf("Gateway: %s\n", a.get_ip_address() ? a.get_ip_address() : "None");
108109

109110
Thread *thread = new Thread(osPriorityNormal1, 2048);
110111
thread->start(print_stats);
@@ -127,7 +128,13 @@ int main()
127128
char *buffer = new char[256];
128129
char *p = buffer;
129130

130-
result = socket.connect("api.ipify.org", 80);
131+
result = NetworkInterface::get_default_instance()->gethostbyname("api.ipify.org", &a);
132+
if (result != NSAPI_ERROR_OK) {
133+
printf("Error! DNS resolution failed with %d\n", result);
134+
goto DISCONNECT;
135+
}
136+
a.set_port(80);
137+
result = socket.connect(a);
131138
if (result != 0) {
132139
stdio_mutex.lock();
133140
printf("Error! socket.connect() returned: %d\n", result);

mbed-os.lib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://github.com/ARMmbed/mbed-os/#cf4f12a123c05fcae83fc56d76442015cb8a39e9
1+
https://github.com/ARMmbed/mbed-os/#64853b354fa188bfe8dbd51e78771213c7ed37f7

0 commit comments

Comments
 (0)