@@ -100,12 +100,13 @@ int main()
100
100
}
101
101
102
102
// Show the network address
103
- const char *ip = net->get_ip_address ();
104
- const char *netmask = net->get_netmask ();
105
- const char *gateway = net->get_gateway ();
106
- printf (" IP address: %s\n " , ip ? ip : " None" );
107
- printf (" Netmask: %s\n " , netmask ? netmask : " None" );
108
- printf (" Gateway: %s\n " , gateway ? gateway : " None" );
103
+ SocketAddress a;
104
+ net->get_ip_address (&a);
105
+ printf (" IP address: %s\n " , a.get_ip_address () ? a.get_ip_address () : " None" );
106
+ net->get_netmask (&a);
107
+ printf (" Netmask: %s\n " , a.get_ip_address () ? a.get_ip_address () : " None" );
108
+ net->get_gateway (&a);
109
+ printf (" Gateway: %s\n " , a.get_ip_address () ? a.get_ip_address () : " None" );
109
110
110
111
Thread *thread = new Thread (osPriorityNormal1, 2048 );
111
112
thread->start (print_stats);
@@ -128,7 +129,13 @@ int main()
128
129
char *buffer = new char [256 ];
129
130
char *p = buffer;
130
131
131
- result = socket.connect (" api.ipify.org" , 80 );
132
+ result = NetworkInterface::get_default_instance ()->gethostbyname (" api.ipify.org" , &a);
133
+ if (result != NSAPI_ERROR_OK) {
134
+ printf (" Error! DNS resolution failed with %d\n " , result);
135
+ goto DISCONNECT;
136
+ }
137
+ a.set_port (80 );
138
+ result = socket.connect (a);
132
139
if (result != 0 ) {
133
140
stdio_mutex.lock ();
134
141
printf (" Error! socket.connect() returned: %d\n " , result);
0 commit comments