-1

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.

Ravi Bhushan
  • 253
  • 3
  • 17

2 Answers2

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
  • 3
    I 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
    1) On which distributions does this file exist? – Géza Török Apr 01 '15 at 12:00
  • 1
    Usually 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
  • 1
    2) 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
  • 3) @scai is right :) – Géza Török Apr 01 '15 at 12:03