C代码获取Linux中IP地址的接口名称 [英] C code to get the interface name for the IP address in Linux

查看:60
本文介绍了C代码获取Linux中IP地址的接口名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从C代码获取Linux中IP地址的接口名称?

How can I get the interface name for the IP address in linux from C code ?

例如我想获取分配给IP地址192.168.0.1的接口名称(例如etho,eth1,l0)

e.g. I'd like to get the interface name ( like etho , eth1 , l0 ) assigned for the IP address 192.168.0.1

推荐答案

您可以使用 getifaddrs .有关使用信息,请参见人3 getifaddrs .这仅适用于类 Unix 系统.

You can use getifaddrs. See man 3 getifaddrs for usage information. This will only work on a Unix-like systems.

这篇关于C代码获取Linux中IP地址的接口名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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