Skip to content

Replace string-based API with SocketAddress-based ones #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
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
21 changes: 14 additions & 7 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,13 @@ int main()
}

// Show the network address
const char *ip = net->get_ip_address();
const char *netmask = net->get_netmask();
const char *gateway = net->get_gateway();
printf("IP address: %s\n", ip ? ip : "None");
printf("Netmask: %s\n", netmask ? netmask : "None");
printf("Gateway: %s\n", gateway ? gateway : "None");
SocketAddress a;
net->get_ip_address(&a);
printf("IP address: %s\n", a.get_ip_address() ? a.get_ip_address() : "None");
net->get_netmask(&a);
printf("Netmask: %s\n", a.get_ip_address() ? a.get_ip_address() : "None");
net->get_gateway(&a);
printf("Gateway: %s\n", a.get_ip_address() ? a.get_ip_address() : "None");

Thread *thread = new Thread(osPriorityNormal1, 2048);
thread->start(print_stats);
Expand All @@ -128,7 +129,13 @@ int main()
char *buffer = new char[256];
char *p = buffer;

result = socket.connect("api.ipify.org", 80);
result = NetworkInterface::get_default_instance()->gethostbyname("api.ipify.org", &a);
if (result != NSAPI_ERROR_OK) {
printf("Error! DNS resolution failed with %d\n", result);
goto DISCONNECT;
}
a.set_port(80);
result = socket.connect(a);
if (result != 0) {
stdio_mutex.lock();
printf("Error! socket.connect() returned: %d\n", result);
Expand Down
2 changes: 1 addition & 1 deletion mbed-os.lib
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/ARMmbed/mbed-os/#cf4f12a123c05fcae83fc56d76442015cb8a39e9
https://github.com/ARMmbed/mbed-os/#64853b354fa188bfe8dbd51e78771213c7ed37f7