@@ -99,12 +99,13 @@ int main()
99
99
}
100
100
101
101
// 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" );
108
109
109
110
Thread *thread = new Thread (osPriorityNormal1, 2048 );
110
111
thread->start (print_stats);
@@ -127,7 +128,13 @@ int main()
127
128
char *buffer = new char [256 ];
128
129
char *p = buffer;
129
130
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);
131
138
if (result != 0 ) {
132
139
stdio_mutex.lock ();
133
140
printf (" Error! socket.connect() returned: %d\n " , result);
0 commit comments