Get ioctl file descriptor for Ethernet port

I need to get a file descriptor for use in ioctl () calls for an Ethernet port on Linux. Not sure how to do this.

+3
source share
2 answers

Just use the open socket file descriptor using the device name in the structure ifreqpassed in ioctl(), provided that your program has the appropriate permissions to do this.

From the docs:

Linux supports some standard ioctls for configuring network devices. They can be used in any descriptor socket file regardless of family or type. They pass the ifreq structure:

- . fd ( , ), , , ioctl() .

. man 7 netdevice , (, manpages-dev manpages-devel, )

net-tools, - . ifconfig (Debian/Ubuntu ).

, , ( , , , ).

+3

- fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP)

strace, , ifconfig.

+1

Source: https://habr.com/ru/post/1750163/


All Articles