I have retrieved IP, subnet and broadcast using ioctl() system call. can anyone help me to find out whether client is static or dhcp?? I am asking about in general and using system call. it is all about client instead of interface.
Asked
Active
Viewed 1,145 times
-1
-
possible duplicate of [How to find out if the eth0 mode is static or dhcp?](http://stackoverflow.com/questions/16085222/how-to-find-out-if-the-eth0-mode-is-static-or-dhcp) – Yasir Majeed Apr 01 '15 at 11:41
-
The interface doesn't have a mode, there's no dhcp built into the kernel. – teppic Apr 01 '15 at 11:48
-
1I suppose, if you have the right permissions, you could trawl through `/var/log/messages`...? – Galik Apr 01 '15 at 11:55
-
Hello @all. i just wanted to know about client whether it has static IP or it is dhcp client?? – Ravi Bhushan Apr 01 '15 at 12:15
-
@YasirMajeed: it is different question. – Ravi Bhushan Apr 01 '15 at 12:22
-
@teppic: i am asking about client. whether it has static IP or it is DHCP client? – Ravi Bhushan Apr 01 '15 at 12:23
2 Answers
2
The interface itself has nothing to do with dhcp. It can be configured to have a particular IP address, gateway, etc. but that's all. This configuration, however, can be done with a smart little program called dhcp client :) So what you need is to find out who (i mean, which program) has configured your interface.
UPDATE:
For example, under the majority of linux distributions you may do a
ps aux | grep 'dhcpcd .* eth0'
If it gives a result like
/sbin/dhcpcd --netconfig -L -E -HHH -c /etc/sysconfig/network/scripts/dhcpcd-hook -t 0 -h somehostname eth0
you can say that eth0 is configured with dhcp

Géza Török
- 1,397
- 7
- 15
-
i just want to retrieve whether client has assigned static IP or it is dhcp client?? – Ravi Bhushan Apr 01 '15 at 11:49
-
3I know, but from the interface aspect, there is no difference. You need to dive into the network manager's configuration, or obtain a status from it, or something like this. It is hard to give an answer to this question in a general context. It's not just operating system, but even distribution dependent. – Géza Török Apr 01 '15 at 11:50
-1
use system command in c
cat /etc/network/interfaces
this will get you network information txt on screen
but first you need to set permission and for permission you user or group on linux system
-
1
-
1Usually you don't need any special permission for reading */etc/network/interfaces*. Additionally this will only tell you the configuration used during system start when not using NetworkManager. Also, a DHCP client could have been started afterwards. – scai Apr 01 '15 at 12:00
-
12) Why to use the `system()` command and `cat`?? Files can be perfectly read from C, tools are provided in the standard library to do so :) – Géza Török Apr 01 '15 at 12:01
-