Skip to content

Commit d421d20

Browse files
Replace ipify.com with an ipv6-compliant ifconfig.io
1 parent 38d2d91 commit d421d20

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

main.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ int main() {
3939
printf("Netmask: %s\n", netmask ? netmask : "None");
4040
printf("Gateway: %s\n", gateway ? gateway : "None");
4141

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
4343
TCPSocket socket;
4444
// Send a simple http request
45-
char sbuffer[] = "GET / HTTP/1.1\r\nHost: api.ipify.org\r\nConnection: close\r\n\r\n";
45+
char sbuffer[] = "GET / HTTP/1.1\r\nHost: ifconfig.io\r\nConnection: close\r\n\r\n";
4646
nsapi_size_t size = strlen(sbuffer);
4747

4848
result = socket.open(net);
4949
if (result != 0) {
5050
printf("Error! socket.open() returned: %d\n", result);
5151
}
5252

53-
result = socket.connect("api.ipify.org", 80);
53+
result = socket.connect("ifconfig.io", 80);
5454
if (result != 0) {
5555
printf("Error! socket.connect() returned: %d\n", result);
5656
goto DISCONNECT;
@@ -71,7 +71,7 @@ int main() {
7171
remaining = 256;
7272
rcount = 0;
7373
p = buffer;
74-
while (0 < (result = socket.recv(p, remaining))) {
74+
while (remaining > 0 && 0 < (result = socket.recv(p, remaining))) {
7575
p += result;
7676
rcount += result;
7777
remaining -= result;
@@ -83,9 +83,6 @@ int main() {
8383
// the HTTP response code
8484
printf("recv %d [%.*s]\n", rcount, strstr(buffer, "\r\n")-buffer, buffer);
8585

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);
8986
delete[] buffer;
9087

9188
DISCONNECT:

0 commit comments

Comments
 (0)