问题描述
有没有在Linux下的方式,用C code,以获得相同的信息ifconfig eth0命令将返回?我感兴趣的东西,如IP地址,连接状态和MAC地址。
下面是在ifconfig输出示例:
eth0的链接ENCAP:以太网的HWaddr 00:0F:20:CF:8B:42
INET地址:217.149.127.10 BCAST:217.149.127.63子网掩码:255.255.255.192
UP BROADCAST RUNNING MULTICAST MTU:1500跃点数:1
RX数据包:2472694671错误:1下降:0超支:0帧:0
TX数据包:44641779错误:0删除:0超支:0载波:0
碰撞:0 txqueuelen:1000
RX字节:1761467179(1679.8兆)TX字节:2870928587(2737.9兆)
中断:28
是使用ifconfig
本身是用C写的:)请参见:<一href=\"http://cvsweb.netbsd.org/bsdweb.cgi/src/sbin/ifconfig/ifconfig.c?rev=1.169&content-type=text/x-cvsweb-markup\">http://cvsweb.netbsd.org/bsdweb.cgi/src/sbin/ifconfig/ifconfig.c?rev=1.169&content-type=text/x-cvsweb-markup
不要男人netdevice
查看详情(在Linux上)。您可以使用的ioctl()
系统调用。
Is there a way in Linux, using C code, to get the same information that "ifconfig eth0" would return? I'm interested in things like IP address, link status, and MAC address.
Here's sample output from ifconfig:
eth0 Link encap:Ethernet HWaddr 00:0F:20:CF:8B:42
inet addr:217.149.127.10 Bcast:217.149.127.63 Mask:255.255.255.192
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2472694671 errors:1 dropped:0 overruns:0 frame:0
TX packets:44641779 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1761467179 (1679.8 Mb) TX bytes:2870928587 (2737.9 Mb)
Interrupt:28
Yes, ifconfig
itself is written in C. :) See: http://cvsweb.netbsd.org/bsdweb.cgi/src/sbin/ifconfig/ifconfig.c?rev=1.169&content-type=text/x-cvsweb-markup
Do man netdevice
to see the details (on Linux). You use the ioctl()
system call.
这篇关于使用C code来获得相同的信息为使用ifconfig的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!