I need to get the file descriptor to use in ioctl() calls for an ethernet port in Linux. Not sure how to do this.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Just use the file descriptor of an open socket, using the name of the device in the
ifreqstructure passed toioctl(), assuming your program has adequate permissions to do so.From the docs:
The socket need not be bound to the target device, or be of any specific family. Any open socket fd will do (again, with appropriate privileges), just open one for your specific task, wait for
ioctl()to return and close it.See
man 7 netdevicefor more, or here if you don’t have the appropriate documentation packages installed (hint, the package is usually namedmanpages-devormanpages-devel, depending on your distro)You can also take a look at the source to the
net-toolspackage, which may be named differently depending on your distro. That’s the source toifconfig(Debian / Ubuntu here).Sorry for the original ambiguity, I thought you were trying to configure a special multi function device (not sure why now, perhaps lack of sleep).