如何从用户空间测试,如果内核支持IPv6? [英] How to test from userspace if the kernel supports IPv6?

查看:225
本文介绍了如何从用户空间测试,如果内核支持IPv6?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我寻求一个简单的方法来测试内核支持上的Linux ++在C / C的IPv6。
它是足够的检查,如果socket()调用失败,并且errno设置为EINVAL?

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 ?

推荐答案

事实上,阅读的的IPv6(7):调用插座( 7) -s程序,特别是插槽(2)和其他人,如绑定(2)等等,可能会失败(和你应该的总是的处理这种故障反正)。

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).

您也可以使用 PROC(5)如的/ proc /净/ if_inet6 的/ proc /净/ sockstat6 (我相信这将不存在,如果的IPv6 不支持)。

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).

这篇关于如何从用户空间测试,如果内核支持IPv6?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆