How to test from userspace if the kernel supports IPv6?

你。 提交于 2019-12-25 01:14:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!