I want to enable/disable IPv4/IPv6 in Linux programmatically using C. Is this possible? If yes, kindly please let me know how to do this and any reference to sample program would also be very helpful.
1 Answer
See here: https://unix.stackexchange.com/questions/66574/how-can-i-disable-ipv6-in-custom-built-embedded-setup
Unfortunately, the _sysctl(2) system call API is deprecated, so you are left with writing to files in /proc/ directly (which is easy enough from C, just a little funny smelling):
The important bits seem to be writing a textual value of 1 (text, not int) to at least the first of these two files, and possibly both:
/proc/sys/net/ipv6/conf/all/disable_ipv6
/proc/sys/net/ipv6/conf/default/disable_ipv6
As for IPv4, it's less clear to me. Do you really need to disable IPv4 while leaving IPv6 running?
localhost?