@@ -39,18 +39,18 @@ int main() {
39
39
printf (" Netmask: %s\n " , netmask ? netmask : " None" );
40
40
printf (" Gateway: %s\n " , gateway ? gateway : " None" );
41
41
42
- // Open a socket on the network interface, and create a TCP connection to api.ipify.org
42
+ // Open a socket on the network interface, and create a TCP connection to ifconfig.io
43
43
TCPSocket socket;
44
44
// Send a simple http request
45
- char sbuffer[] = " GET / HTTP/1.1\r\n Host: api.ipify.org \r\n Connection: close\r\n\r\n " ;
45
+ char sbuffer[] = " GET / HTTP/1.1\r\n Host: ifconfig.io \r\n Connection: close\r\n\r\n " ;
46
46
nsapi_size_t size = strlen (sbuffer);
47
47
48
48
result = socket.open (net);
49
49
if (result != 0 ) {
50
50
printf (" Error! socket.open() returned: %d\n " , result);
51
51
}
52
52
53
- result = socket.connect (" api.ipify.org " , 80 );
53
+ result = socket.connect (" ifconfig.io " , 80 );
54
54
if (result != 0 ) {
55
55
printf (" Error! socket.connect() returned: %d\n " , result);
56
56
goto DISCONNECT;
@@ -71,7 +71,7 @@ int main() {
71
71
remaining = 256 ;
72
72
rcount = 0 ;
73
73
p = buffer;
74
- while (0 < (result = socket.recv (p, remaining))) {
74
+ while (remaining > 0 && 0 < (result = socket.recv (p, remaining))) {
75
75
p += result;
76
76
rcount += result;
77
77
remaining -= result;
@@ -83,9 +83,6 @@ int main() {
83
83
// the HTTP response code
84
84
printf (" recv %d [%.*s]\n " , rcount, strstr (buffer, " \r\n " )-buffer, buffer);
85
85
86
- // The api.ipify.org service also gives us the device's external IP address
87
- p = strstr (buffer, " \r\n\r\n " )+4 ;
88
- printf (" External IP address: %.*s\n " , rcount-(p-buffer), p);
89
86
delete[] buffer;
90
87
91
88
DISCONNECT:
0 commit comments