Reputation: 225
How to read the system proxy setting values in linux using c or c++
Upvotes: 0
Views: 3578
Reputation: 62379
Most Linux distributions that I've seen do not have the notion of a "system proxy". The desktop environments that run on top of Linux (KDE, Gnome, etc....) generally have configuration options to set up a proxy, which most applications written for that desktop will then have access to, but how to look that up in code will be different depending on which environment you're running. Also, running e.g. KDE apps under Gnome or vice versa may not get the same results, unless both have been configured properly. Because of this and a number of other things, many individual applications have their own way to set proxies. One of those possible ways, that works for some applications is the environment variables mentioned in other answers (other possibilities being various configuration files, or connecting to one of the configuration services like gconf). If you're writing a new app and just want to be able to set and use a proxy in that app, this approach is probably one of the simplest.
Upvotes: 0
Reputation: 358
System proxy settings are generally stored in environment variables like HTTP_PROXY, HTTPS_PROXY etc.
'C' allows us to read enrolment variables via adding an extra argument envp
to the main() function as shown.
int main (int argc, char *argv[], char *envp[])
{
char *http_proxy, *https_proxy;
http_proxy = getenv("HTTP_PROXY");
https_proxy = getenv("HTTPS_PROXY");
printf ("Proxy settings :: %s on %s.\n", http_proxy, https_proxy);
return 0;
}
This should do the trick depending on what variables you would want to process.
Upvotes: 1