问题
I am seeking for a simple way to test if the kernel supports IPv6 on Linux in C/C++. Is it enough to check if the socket() call fails and that errno is set to EINVAL ?
回答1:
Indeed, read ipv6(7): the call to socket(7)-s routines, notably socket(2) and others, e.g. bind(2) etc..., could fail (and you should always handle such failures anyway).
You could also use proc(5) e.g. read /proc/net/if_inet6
or /proc/net/sockstat6
(I believe it won't exist if ipv6
is unsupported).
来源:https://stackoverflow.com/questions/28097823/how-to-test-from-userspace-if-the-kernel-supports-ipv6