0

In a Linux C program, I call

FILE *fd = popen("curl ipecho.net/plain", "r");
fgets(buffer, BUFFER_CONTENTS_MAX, fd);
pclose(fd);

to store my machine's IP address into a buffer, and it returns just the IP address (plus some other stuff which I strip off). It works fine, but during the call, CURL echoes a header to stdout despite the "/plain" switch. How can I suppress the stdout output? The unwanted output winds up looking like:

% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 11 100 11 0 0 86 0 --:--:-- --:--:-- --:--:-- 85

R. Lambert
  • 11
  • 3
  • Consider the second answer at https://stackoverflow.com/questions/7373752/how-do-i-get-curl-to-not-show-the-progress-bar and maybe use `curl --no-progress-meter ipecho.net/plain` or `curl -sS ipecho.net/plain`. – EdmCoff Jun 17 '22 at 20:31
  • To be clear, the extra text you're seeing is output from `curl`, not http headers from ipecho.net – EdmCoff Jun 17 '22 at 20:32
  • I would recommend using libcurl. – Cheatah Jun 17 '22 at 21:35
  • EdmCoff's two curl suggestions both worked beautifully. Thanks! ...makes sense that it's curl output and not an http header. – R. Lambert Jun 18 '22 at 20:51

0 Answers0